@ethersphere/bee-js 5.1.1 → 5.1.2

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 (151) hide show
  1. package/README.md +14 -6
  2. package/dist/223.index.browser.min.js +3 -0
  3. package/dist/223.index.browser.min.js.LICENSE.txt +1 -0
  4. package/dist/223.index.browser.min.js.map +1 -0
  5. package/dist/cjs/bee-debug.js +208 -312
  6. package/dist/cjs/bee.js +258 -353
  7. package/dist/cjs/chunk/signer.js +11 -22
  8. package/dist/cjs/chunk/soc.js +33 -50
  9. package/dist/cjs/chunk/span.js +1 -1
  10. package/dist/cjs/feed/index.js +50 -65
  11. package/dist/cjs/feed/json.js +8 -21
  12. package/dist/cjs/feed/retrievable.js +14 -27
  13. package/dist/cjs/modules/bytes.js +25 -37
  14. package/dist/cjs/modules/bzz.js +63 -68
  15. package/dist/cjs/modules/chunk.js +17 -27
  16. package/dist/cjs/modules/debug/balance.js +24 -41
  17. package/dist/cjs/modules/debug/chequebook.js +71 -96
  18. package/dist/cjs/modules/debug/chunk.js +13 -26
  19. package/dist/cjs/modules/debug/connectivity.js +32 -53
  20. package/dist/cjs/modules/debug/settlements.js +12 -25
  21. package/dist/cjs/modules/debug/stake.js +20 -33
  22. package/dist/cjs/modules/debug/stamps.js +45 -66
  23. package/dist/cjs/modules/debug/states.js +27 -40
  24. package/dist/cjs/modules/debug/status.js +53 -80
  25. package/dist/cjs/modules/debug/tag.js +6 -17
  26. package/dist/cjs/modules/debug/transactions.js +23 -40
  27. package/dist/cjs/modules/feed.js +17 -27
  28. package/dist/cjs/modules/pinning.js +24 -41
  29. package/dist/cjs/modules/pss.js +9 -20
  30. package/dist/cjs/modules/soc.js +12 -20
  31. package/dist/cjs/modules/status.js +4 -15
  32. package/dist/cjs/modules/stewardship.js +10 -23
  33. package/dist/cjs/modules/tag.js +28 -47
  34. package/dist/cjs/utils/collection.browser.js +4 -17
  35. package/dist/cjs/utils/collection.js +11 -22
  36. package/dist/cjs/utils/collection.node.js +42 -86
  37. package/dist/cjs/utils/data.browser.js +46 -59
  38. package/dist/cjs/utils/data.js +22 -35
  39. package/dist/cjs/utils/eth.js +31 -43
  40. package/dist/cjs/utils/file.js +9 -20
  41. package/dist/cjs/utils/headers.js +4 -4
  42. package/dist/cjs/utils/http.js +78 -93
  43. package/dist/cjs/utils/merge.js +1 -1
  44. package/dist/cjs/utils/sleep.js +2 -13
  45. package/dist/cjs/utils/type.js +14 -12
  46. package/dist/index.browser.min.js +1 -1
  47. package/dist/index.browser.min.js.LICENSE.txt +1 -3
  48. package/dist/index.browser.min.js.map +1 -1
  49. package/dist/mjs/bee-debug.js +209 -450
  50. package/dist/mjs/bee.js +256 -491
  51. package/dist/mjs/chunk/bmt.js +4 -10
  52. package/dist/mjs/chunk/cac.js +0 -3
  53. package/dist/mjs/chunk/signer.js +12 -63
  54. package/dist/mjs/chunk/soc.js +33 -85
  55. package/dist/mjs/chunk/span.js +3 -6
  56. package/dist/mjs/feed/identifier.js +0 -6
  57. package/dist/mjs/feed/index.js +53 -97
  58. package/dist/mjs/feed/json.js +10 -49
  59. package/dist/mjs/feed/retrievable.js +13 -64
  60. package/dist/mjs/feed/topic.js +0 -2
  61. package/dist/mjs/index.js +1 -2
  62. package/dist/mjs/modules/bytes.js +25 -65
  63. package/dist/mjs/modules/bzz.js +64 -108
  64. package/dist/mjs/modules/chunk.js +17 -54
  65. package/dist/mjs/modules/debug/balance.js +24 -68
  66. package/dist/mjs/modules/debug/chequebook.js +75 -138
  67. package/dist/mjs/modules/debug/chunk.js +13 -51
  68. package/dist/mjs/modules/debug/connectivity.js +32 -76
  69. package/dist/mjs/modules/debug/settlements.js +12 -50
  70. package/dist/mjs/modules/debug/stake.js +20 -61
  71. package/dist/mjs/modules/debug/stamps.js +47 -94
  72. package/dist/mjs/modules/debug/states.js +25 -66
  73. package/dist/mjs/modules/debug/status.js +66 -125
  74. package/dist/mjs/modules/debug/tag.js +6 -41
  75. package/dist/mjs/modules/debug/transactions.js +25 -69
  76. package/dist/mjs/modules/feed.js +17 -57
  77. package/dist/mjs/modules/pinning.js +24 -68
  78. package/dist/mjs/modules/pss.js +11 -47
  79. package/dist/mjs/modules/soc.js +14 -48
  80. package/dist/mjs/modules/status.js +4 -39
  81. package/dist/mjs/modules/stewardship.js +10 -47
  82. package/dist/mjs/modules/tag.js +31 -78
  83. package/dist/mjs/types/debug.js +0 -1
  84. package/dist/mjs/types/index.js +0 -4
  85. package/dist/mjs/utils/bytes.js +6 -14
  86. package/dist/mjs/utils/collection.browser.js +4 -42
  87. package/dist/mjs/utils/collection.js +11 -57
  88. package/dist/mjs/utils/collection.node.js +42 -150
  89. package/dist/mjs/utils/data.browser.js +49 -94
  90. package/dist/mjs/utils/data.js +19 -62
  91. package/dist/mjs/utils/error.js +0 -5
  92. package/dist/mjs/utils/eth.js +37 -95
  93. package/dist/mjs/utils/file.js +11 -50
  94. package/dist/mjs/utils/hash.js +0 -1
  95. package/dist/mjs/utils/headers.js +6 -14
  96. package/dist/mjs/utils/hex.js +6 -25
  97. package/dist/mjs/utils/http.js +80 -138
  98. package/dist/mjs/utils/merge.js +3 -7
  99. package/dist/mjs/utils/pss.js +0 -2
  100. package/dist/mjs/utils/reference.js +2 -5
  101. package/dist/mjs/utils/sleep.js +2 -37
  102. package/dist/mjs/utils/stream.js +0 -23
  103. package/dist/mjs/utils/tar.js +2 -5
  104. package/dist/mjs/utils/type.js +18 -82
  105. package/dist/mjs/utils/uint64.js +0 -1
  106. package/dist/mjs/utils/url.js +2 -10
  107. package/dist/types/bee-debug.d.ts +2 -2
  108. package/dist/types/bee.d.ts +2 -26
  109. package/dist/types/chunk/cac.d.ts +1 -1
  110. package/dist/types/chunk/soc.d.ts +8 -7
  111. package/dist/types/feed/index.d.ts +9 -8
  112. package/dist/types/feed/type.d.ts +1 -1
  113. package/dist/types/modules/bytes.d.ts +6 -5
  114. package/dist/types/modules/bzz.d.ts +9 -8
  115. package/dist/types/modules/chunk.d.ts +5 -4
  116. package/dist/types/modules/debug/balance.d.ts +10 -9
  117. package/dist/types/modules/debug/chequebook.d.ts +18 -17
  118. package/dist/types/modules/debug/chunk.d.ts +6 -5
  119. package/dist/types/modules/debug/connectivity.d.ts +8 -7
  120. package/dist/types/modules/debug/settlements.d.ts +6 -5
  121. package/dist/types/modules/debug/stake.d.ts +5 -4
  122. package/dist/types/modules/debug/stamps.d.ts +8 -7
  123. package/dist/types/modules/debug/states.d.ts +8 -7
  124. package/dist/types/modules/debug/status.d.ts +15 -15
  125. package/dist/types/modules/debug/tag.d.ts +4 -3
  126. package/dist/types/modules/debug/transactions.d.ts +6 -5
  127. package/dist/types/modules/feed.d.ts +4 -3
  128. package/dist/types/modules/pinning.d.ts +8 -7
  129. package/dist/types/modules/pss.d.ts +4 -3
  130. package/dist/types/modules/soc.d.ts +3 -2
  131. package/dist/types/modules/status.d.ts +3 -3
  132. package/dist/types/modules/stewardship.d.ts +4 -3
  133. package/dist/types/modules/tag.d.ts +7 -6
  134. package/dist/types/types/debug.d.ts +1 -1
  135. package/dist/types/types/index.d.ts +30 -34
  136. package/dist/types/utils/eth.d.ts +3 -3
  137. package/dist/types/utils/hex.d.ts +2 -2
  138. package/dist/types/utils/http.d.ts +6 -6
  139. package/package.json +34 -39
  140. package/dist/cjs/types/ky-options.js +0 -8
  141. package/dist/cjs/types/ky-universal/common.js +0 -8
  142. package/dist/cjs/types/ky-universal/hooks.js +0 -8
  143. package/dist/cjs/types/ky-universal/retry.js +0 -8
  144. package/dist/mjs/types/ky-options.js +0 -7
  145. package/dist/mjs/types/ky-universal/common.js +0 -7
  146. package/dist/mjs/types/ky-universal/hooks.js +0 -7
  147. package/dist/mjs/types/ky-universal/retry.js +0 -7
  148. package/dist/types/types/ky-options.d.ts +0 -221
  149. package/dist/types/types/ky-universal/common.d.ts +0 -13
  150. package/dist/types/types/ky-universal/hooks.d.ts +0 -92
  151. package/dist/types/types/ky-universal/retry.d.ts +0 -38
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -106,7 +97,6 @@ exports.isHexEthAddress = isHexEthAddress;
106
97
  * @return little-endian encoded hexstring
107
98
  */
108
99
  function toLittleEndian(bigEndian, pad = 2) {
109
- var _a;
110
100
  if (!(Number.isInteger(pad) && pad >= 2 && pad % 2 === 0)) {
111
101
  throw new TypeError('minimal padding for conversion needs to be positive even integer');
112
102
  }
@@ -122,7 +112,7 @@ function toLittleEndian(bigEndian, pad = 2) {
122
112
  if (hexRep.length % 2 !== 0)
123
113
  hexRep = hexRep.padStart(hexRep.length + 1, '0');
124
114
  // Match all two pairs in the hexstring, reverse the pairs and join it again
125
- const littleEndian = (_a = hexRep.match(/../g)) === null || _a === void 0 ? void 0 : _a.reverse().join('');
115
+ const littleEndian = hexRep.match(/../g)?.reverse().join('');
126
116
  if (littleEndian)
127
117
  return littleEndian;
128
118
  throw new Error('failed to convert');
@@ -175,37 +165,35 @@ exports.ethToSwarmAddress = ethToSwarmAddress;
175
165
  * @param provider Injected web3 provider like window.ethereum or other compatible with EIP-1193
176
166
  * @param ethAddress Optional address of the account which the data should be signed with. If not specified `eth_requestAccounts` request is used to get the account address.
177
167
  */
178
- function makeEthereumWalletSigner(provider, ethAddress) {
179
- return __awaiter(this, void 0, void 0, function* () {
180
- let executorFnc;
181
- if (typeof provider !== 'object' || provider === null) {
182
- throw new TypeError('We need JsonRPC provider object!');
183
- }
184
- if (provider.request) {
185
- executorFnc = provider.request;
186
- }
187
- else if (provider.sendAsync) {
188
- executorFnc = provider.sendAsync;
189
- }
190
- else {
191
- throw new Error('Incompatible interface of given provider!');
192
- }
193
- if (!ethAddress) {
194
- ethAddress = (yield executorFnc({ method: 'eth_requestAccounts' }))[0];
195
- }
196
- const bytesEthAddress = makeEthAddress(ethAddress);
197
- const hexEthAddress = makeHexEthAddress(ethAddress);
198
- return {
199
- address: bytesEthAddress,
200
- sign: (data) => __awaiter(this, void 0, void 0, function* () {
201
- const result = yield executorFnc({
202
- jsonrpc: '2.0',
203
- method: 'personal_sign',
204
- params: ['0x' + data.hex(), '0x' + hexEthAddress],
205
- });
206
- return result;
207
- }),
208
- };
209
- });
168
+ async function makeEthereumWalletSigner(provider, ethAddress) {
169
+ let executorFnc;
170
+ if (typeof provider !== 'object' || provider === null) {
171
+ throw new TypeError('We need JsonRPC provider object!');
172
+ }
173
+ if (provider.request) {
174
+ executorFnc = provider.request;
175
+ }
176
+ else if (provider.sendAsync) {
177
+ executorFnc = provider.sendAsync;
178
+ }
179
+ else {
180
+ throw new Error('Incompatible interface of given provider!');
181
+ }
182
+ if (!ethAddress) {
183
+ ethAddress = (await executorFnc({ method: 'eth_requestAccounts' }))[0];
184
+ }
185
+ const bytesEthAddress = makeEthAddress(ethAddress);
186
+ const hexEthAddress = makeHexEthAddress(ethAddress);
187
+ return {
188
+ address: bytesEthAddress,
189
+ sign: async (data) => {
190
+ const result = await executorFnc({
191
+ jsonrpc: '2.0',
192
+ method: 'personal_sign',
193
+ params: ['0x' + data.hex(), '0x' + hexEthAddress],
194
+ });
195
+ return result;
196
+ },
197
+ };
210
198
  }
211
199
  exports.makeEthereumWalletSigner = makeEthereumWalletSigner;
@@ -4,15 +4,6 @@
4
4
  *
5
5
  * https://developer.mozilla.org/en-US/docs/Web/API/File
6
6
  */
7
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
- return new (P || (P = Promise))(function (resolve, reject) {
10
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
- step((generator = generator.apply(thisArg, _arguments || [])).next());
14
- });
15
- };
16
7
  Object.defineProperty(exports, "__esModule", { value: true });
17
8
  exports.fileArrayBuffer = exports.isFile = void 0;
18
9
  function isFile(file) {
@@ -33,17 +24,15 @@ exports.isFile = isFile;
33
24
  *
34
25
  * @param file A File object
35
26
  */
36
- function fileArrayBuffer(file) {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- if (file.arrayBuffer) {
39
- return file.arrayBuffer();
40
- }
41
- // workaround for Safari where arrayBuffer is not supported on Files
42
- return new Promise(resolve => {
43
- const fr = new FileReader();
44
- fr.onload = () => resolve(fr.result);
45
- fr.readAsArrayBuffer(file);
46
- });
27
+ async function fileArrayBuffer(file) {
28
+ if (file.arrayBuffer) {
29
+ return file.arrayBuffer();
30
+ }
31
+ // workaround for Safari where arrayBuffer is not supported on Files
32
+ return new Promise(resolve => {
33
+ const fr = new FileReader();
34
+ fr.onload = () => resolve(fr.result);
35
+ fr.readAsArrayBuffer(file);
47
36
  });
48
37
  }
49
38
  exports.fileArrayBuffer = fileArrayBuffer;
@@ -46,13 +46,13 @@ function extractUploadHeaders(postageBatchId, options) {
46
46
  const headers = {
47
47
  'swarm-postage-batch-id': postageBatchId,
48
48
  };
49
- if (options === null || options === void 0 ? void 0 : options.pin)
49
+ if (options?.pin)
50
50
  headers['swarm-pin'] = String(options.pin);
51
- if (options === null || options === void 0 ? void 0 : options.encrypt)
51
+ if (options?.encrypt)
52
52
  headers['swarm-encrypt'] = String(options.encrypt);
53
- if (options === null || options === void 0 ? void 0 : options.tag)
53
+ if (options?.tag)
54
54
  headers['swarm-tag'] = String(options.tag);
55
- if (typeof (options === null || options === void 0 ? void 0 : options.deferred) === 'boolean')
55
+ if (typeof options?.deferred === 'boolean')
56
56
  headers['swarm-deferred-upload'] = options.deferred.toString();
57
57
  return headers;
58
58
  }
@@ -1,35 +1,11 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
- var __importDefault = (this && this.__importDefault) || function (mod) {
23
- return (mod && mod.__esModule) ? mod : { "default": mod };
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.makeDefaultKy = exports.http = exports.filterHeaders = exports.wrapResponseClosure = exports.wrapRequestClosure = void 0;
3
+ exports.http = exports.filterHeaders = exports.wrapResponseClosure = exports.wrapRequestClosure = exports.DEFAULT_KY_CONFIG = void 0;
27
4
  const error_1 = require("./error");
28
- const ky_universal_1 = __importDefault(require("ky-universal"));
29
5
  const stream_1 = require("./stream");
30
- const merge_1 = require("./merge");
31
6
  const type_1 = require("./type");
32
- const DEFAULT_KY_CONFIG = {
7
+ const merge_1 = require("./merge");
8
+ exports.DEFAULT_KY_CONFIG = {
33
9
  headers: {
34
10
  accept: 'application/json, text/plain, */*',
35
11
  'user-agent': `bee-js`,
@@ -55,20 +31,20 @@ function wrapRequest(request) {
55
31
  };
56
32
  }
57
33
  function wrapRequestClosure(cb) {
58
- return (request) => __awaiter(this, void 0, void 0, function* () {
59
- yield cb(wrapRequest(request));
60
- });
34
+ return async (request) => {
35
+ await cb(wrapRequest(request));
36
+ };
61
37
  }
62
38
  exports.wrapRequestClosure = wrapRequestClosure;
63
39
  function wrapResponseClosure(cb) {
64
- return (request, options, response) => __awaiter(this, void 0, void 0, function* () {
65
- yield cb({
40
+ return async (request, options, response) => {
41
+ await cb({
66
42
  headers: headersToObject(response.headers),
67
43
  status: response.status,
68
44
  statusText: response.statusText,
69
45
  request: wrapRequest(request),
70
46
  });
71
- });
47
+ };
72
48
  }
73
49
  exports.wrapResponseClosure = wrapResponseClosure;
74
50
  /**
@@ -97,76 +73,85 @@ function filterHeaders(obj) {
97
73
  exports.filterHeaders = filterHeaders;
98
74
  /**
99
75
  * Main utility function to make HTTP requests.
100
- * @param ky
76
+ * @param kyOptions
101
77
  * @param config
102
78
  */
103
- function http(ky, config) {
104
- return __awaiter(this, void 0, void 0, function* () {
105
- try {
106
- const { path, responseType } = config, kyConfig = __rest(config, ["path", "responseType"]);
107
- const response = (yield ky(path, Object.assign(Object.assign({}, kyConfig), { searchParams: filterHeaders(kyConfig.searchParams) })));
108
- switch (responseType) {
109
- case 'stream':
110
- if (!response.body) {
111
- throw new error_1.BeeError('Response was expected to get data but did not get any!');
112
- }
113
- response.data = (0, stream_1.normalizeToReadableStream)(response.body);
114
- break;
115
- case 'arraybuffer':
116
- response.data = (yield response.arrayBuffer());
117
- break;
118
- case 'json':
119
- try {
120
- response.data = (yield response.json());
121
- }
122
- catch (e) {
123
- throw new error_1.BeeNotAJsonError();
124
- }
125
- break;
126
- default:
127
- break; // If responseType is not set, then no data are expected
128
- }
129
- return response;
130
- }
131
- catch (e) {
132
- // Passthrough thrown errors
133
- if (e instanceof error_1.BeeNotAJsonError) {
134
- throw e;
135
- }
136
- if (isHttpError(e)) {
137
- let message;
138
- // We store the response body here as it can be read only once in Response's lifecycle so to make it exposed
139
- // to the user in the BeeResponseError, for further analysis.
140
- const body = yield e.response.text();
141
- try {
142
- // The response can be Bee's JSON with structure `{code, message}` lets try to parse it
143
- message = JSON.parse(body).message;
79
+ async function http(kyOptions, config) {
80
+ try {
81
+ const ky = await getKy();
82
+ const { path, responseType, ...kyConfig } = (0, merge_1.deepMerge)(kyOptions, config);
83
+ const response = (await ky(path, {
84
+ ...kyConfig,
85
+ searchParams: filterHeaders(kyConfig.searchParams),
86
+ }));
87
+ switch (responseType) {
88
+ case 'stream':
89
+ if (!response.body) {
90
+ throw new error_1.BeeError('Response was expected to get data but did not get any!');
144
91
  }
145
- catch (e) { }
146
- if (message) {
147
- throw new error_1.BeeResponseError(e.response.status, e.response, body, config, `${e.response.statusText}: ${message}`);
92
+ response.parsedData = (0, stream_1.normalizeToReadableStream)(response.body);
93
+ break;
94
+ case 'arraybuffer':
95
+ response.parsedData = (await response.arrayBuffer());
96
+ break;
97
+ case 'json':
98
+ try {
99
+ response.parsedData = (await response.json());
148
100
  }
149
- else {
150
- throw new error_1.BeeResponseError(e.response.status, e.response, body, config, e.response.statusText);
101
+ catch (e) {
102
+ throw new error_1.BeeNotAJsonError();
151
103
  }
104
+ break;
105
+ default:
106
+ break; // If responseType is not set, then no data are expected
107
+ }
108
+ return response;
109
+ }
110
+ catch (e) {
111
+ // Passthrough thrown errors
112
+ if (e instanceof error_1.BeeNotAJsonError) {
113
+ throw e;
114
+ }
115
+ if (isHttpError(e)) {
116
+ let message;
117
+ // We store the response body here as it can be read only once in Response's lifecycle so to make it exposed
118
+ // to the user in the BeeResponseError, for further analysis.
119
+ const body = await e.response.text();
120
+ try {
121
+ // The response can be Bee's JSON with structure `{code, message}` lets try to parse it
122
+ message = JSON.parse(body).message;
152
123
  }
153
- else if (isHttpRequestError(e)) {
154
- throw new error_1.BeeRequestError(e.message, config);
124
+ catch (e) { }
125
+ if (message) {
126
+ throw new error_1.BeeResponseError(e.response.status, e.response, body, config, `${e.response.statusText}: ${message}`);
155
127
  }
156
128
  else {
157
- // Node 18 has native `fetch` implementation called Undici. Errors from this implementation have top level generic
158
- // message "fetch failed" with the more specific error placed into `cause` property. Instead of "fetch failed" we
159
- // expose the underlying problem.
160
- if (e.cause) {
161
- throw new error_1.BeeError(e.cause.message);
162
- }
163
- throw new error_1.BeeError(e.message);
129
+ throw new error_1.BeeResponseError(e.response.status, e.response, body, config, e.response.statusText);
164
130
  }
165
131
  }
166
- });
132
+ else if (isHttpRequestError(e)) {
133
+ throw new error_1.BeeRequestError(e.message, config);
134
+ }
135
+ else {
136
+ // Node 18 has native `fetch` implementation called Undici. Errors from this implementation have top level generic
137
+ // message "fetch failed" with the more specific error placed into `cause` property. Instead of "fetch failed" we
138
+ // expose the underlying problem.
139
+ if (e.cause) {
140
+ throw new error_1.BeeError(e.cause.message);
141
+ }
142
+ throw new error_1.BeeError(e.message);
143
+ }
144
+ }
167
145
  }
168
146
  exports.http = http;
169
- function makeDefaultKy(kyConfig) {
170
- return ky_universal_1.default.create((0, merge_1.deepMerge)(DEFAULT_KY_CONFIG, kyConfig));
147
+ let ky;
148
+ async function getKy() {
149
+ if (ky) {
150
+ return ky;
151
+ }
152
+ ky = (await import('ky-universal')).default;
153
+ if (!ky) {
154
+ throw new Error('Ky was not found while it should have been!');
155
+ }
156
+ return ky;
171
157
  }
172
- exports.makeDefaultKy = makeDefaultKy;
@@ -25,7 +25,7 @@ function deepMerge(...sources) {
25
25
  if ((0, type_1.isObject)(value) && key in returnValue) {
26
26
  value = deepMerge(returnValue[key], value);
27
27
  }
28
- returnValue = Object.assign(Object.assign({}, returnValue), { [key]: value });
28
+ returnValue = { ...returnValue, [key]: value };
29
29
  }
30
30
  }
31
31
  }
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.sleep = void 0;
13
4
  /**
@@ -15,9 +6,7 @@ exports.sleep = void 0;
15
6
  *
16
7
  * @param ms Number of miliseconds to sleep
17
8
  */
18
- function sleep(ms) {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- return new Promise(resolve => setTimeout(() => resolve(), ms));
21
- });
9
+ async function sleep(ms) {
10
+ return new Promise(resolve => setTimeout(() => resolve(), ms));
22
11
  }
23
12
  exports.sleep = sleep;
@@ -140,14 +140,13 @@ exports.assertReferenceOrEns = assertReferenceOrEns;
140
140
  * @param expectedCidType
141
141
  */
142
142
  function makeReferenceOrEns(value, expectedCidType) {
143
- var _a;
144
143
  if (typeof value !== 'string') {
145
144
  throw new TypeError('ReferenceCidOrEns has to be a string!');
146
145
  }
147
146
  try {
148
147
  const result = (0, swarm_cid_1.decodeCid)(value);
149
148
  if (result.type !== expectedCidType) {
150
- throw new error_1.BeeError(`CID was expected to be of type ${expectedCidType}, but got instead ${(_a = result.type) !== null && _a !== void 0 ? _a : 'non-Swarm CID'}`);
149
+ throw new error_1.BeeError(`CID was expected to be of type ${expectedCidType}, but got instead ${result.type ?? 'non-Swarm CID'}`);
151
150
  }
152
151
  return result.reference;
153
152
  }
@@ -165,9 +164,12 @@ exports.makeReferenceOrEns = makeReferenceOrEns;
165
164
  * @param cidType Type as described in the @ethersphere/swarm-cids-js -> ReferenceType
166
165
  */
167
166
  function addCidConversionFunction(result, cidType) {
168
- return Object.assign(Object.assign({}, result), { cid() {
167
+ return {
168
+ ...result,
169
+ cid() {
169
170
  return (0, swarm_cid_1.encodeReference)(result.reference, cidType).toString();
170
- } });
171
+ },
172
+ };
171
173
  }
172
174
  exports.addCidConversionFunction = addCidConversionFunction;
173
175
  function assertAddress(value) {
@@ -308,16 +310,16 @@ function assertPostageBatchOptions(value) {
308
310
  assertStrictlyObject(value);
309
311
  const options = value;
310
312
  assertRequestOptions(options, 'PostageBatchOptions');
311
- if (options === null || options === void 0 ? void 0 : options.gasPrice) {
313
+ if (options?.gasPrice) {
312
314
  assertNonNegativeInteger(options.gasPrice);
313
315
  }
314
- if ((options === null || options === void 0 ? void 0 : options.immutableFlag) !== undefined) {
316
+ if (options?.immutableFlag !== undefined) {
315
317
  assertBoolean(options.immutableFlag);
316
318
  }
317
- if ((options === null || options === void 0 ? void 0 : options.waitForUsable) !== undefined) {
319
+ if (options?.waitForUsable !== undefined) {
318
320
  assertBoolean(options.waitForUsable);
319
321
  }
320
- if ((options === null || options === void 0 ? void 0 : options.waitForUsableTimeout) !== undefined) {
322
+ if (options?.waitForUsableTimeout !== undefined) {
321
323
  assertNonNegativeInteger(options.waitForUsableTimeout, 'options.waitForUsableTimeout');
322
324
  }
323
325
  }
@@ -328,10 +330,10 @@ function assertTransactionOptions(value, name = 'TransactionOptions') {
328
330
  }
329
331
  assertStrictlyObject(value, name);
330
332
  const options = value;
331
- if (options === null || options === void 0 ? void 0 : options.gasLimit) {
333
+ if (options?.gasLimit) {
332
334
  assertNonNegativeInteger(options.gasLimit, name);
333
335
  }
334
- if (options === null || options === void 0 ? void 0 : options.gasPrice) {
336
+ if (options?.gasPrice) {
335
337
  assertNonNegativeInteger(options.gasPrice, name);
336
338
  }
337
339
  }
@@ -378,7 +380,7 @@ function assertAllTagsOptions(entry) {
378
380
  }
379
381
  assertRequestOptions(entry, 'AllTagsOptions');
380
382
  const options = entry;
381
- if ((options === null || options === void 0 ? void 0 : options.limit) !== undefined) {
383
+ if (options?.limit !== undefined) {
382
384
  if (typeof options.limit !== 'number') {
383
385
  throw new TypeError('AllTagsOptions.limit has to be a number or undefined!');
384
386
  }
@@ -389,7 +391,7 @@ function assertAllTagsOptions(entry) {
389
391
  throw new error_1.BeeArgumentError(`AllTagsOptions.limit has to be at most ${types_1.TAGS_LIMIT_MAX}`, options.limit);
390
392
  }
391
393
  }
392
- if ((options === null || options === void 0 ? void 0 : options.offset) !== undefined) {
394
+ if (options?.offset !== undefined) {
393
395
  assertNonNegativeInteger(options.offset, 'AllTagsOptions.offset');
394
396
  }
395
397
  }