@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
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.uploadCollection = exports.downloadFileReadable = exports.downloadFile = exports.uploadFile = void 0;
13
4
  const headers_1 = require("../utils/headers");
@@ -21,9 +12,9 @@ const type_1 = require("../utils/type");
21
12
  const bzzEndpoint = 'bzz';
22
13
  function extractFileUploadHeaders(postageBatchId, options) {
23
14
  const headers = (0, headers_1.extractUploadHeaders)(postageBatchId, options);
24
- if (options === null || options === void 0 ? void 0 : options.size)
15
+ if (options?.size)
25
16
  headers['content-length'] = String(options.size);
26
- if (options === null || options === void 0 ? void 0 : options.contentType)
17
+ if (options?.contentType)
27
18
  headers['content-type'] = options.contentType;
28
19
  return headers;
29
20
  }
@@ -36,96 +27,100 @@ function extractFileUploadHeaders(postageBatchId, options) {
36
27
  * @param name Name that will be attached to the uploaded file. Wraps the data into manifest with set index document.
37
28
  * @param options
38
29
  */
39
- function uploadFile(ky, data, postageBatchId, name, options) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- if ((0, stream_1.isReadable)(data) && !(options === null || options === void 0 ? void 0 : options.contentType)) {
42
- if (!options)
43
- options = {};
44
- options.contentType = 'application/octet-stream';
45
- }
46
- const response = yield (0, http_1.http)(ky, {
47
- method: 'post',
48
- path: bzzEndpoint,
49
- body: yield (0, data_1.prepareData)(data),
50
- headers: Object.assign({}, extractFileUploadHeaders(postageBatchId, options)),
51
- searchParams: { name },
52
- responseType: 'json',
53
- });
54
- return {
55
- reference: response.data.reference,
56
- tagUid: (0, type_1.makeTagUid)(response.headers.get('swarm-tag')),
57
- };
30
+ async function uploadFile(kyOptions, data, postageBatchId, name, options) {
31
+ if ((0, stream_1.isReadable)(data) && !options?.contentType) {
32
+ if (!options)
33
+ options = {};
34
+ options.contentType = 'application/octet-stream';
35
+ }
36
+ const response = await (0, http_1.http)(kyOptions, {
37
+ method: 'post',
38
+ path: bzzEndpoint,
39
+ body: await (0, data_1.prepareData)(data),
40
+ headers: {
41
+ ...extractFileUploadHeaders(postageBatchId, options),
42
+ },
43
+ searchParams: { name },
44
+ responseType: 'json',
58
45
  });
46
+ return {
47
+ reference: response.parsedData.reference,
48
+ tagUid: (0, type_1.makeTagUid)(response.headers.get('swarm-tag')),
49
+ };
59
50
  }
60
51
  exports.uploadFile = uploadFile;
61
52
  /**
62
53
  * Download single file as a buffer
63
54
  *
64
- * @param ky Ky instance for given Bee class instance
55
+ * @param kyOptions Ky Options for making requests
65
56
  * @param hash Bee file or collection hash
66
57
  * @param path If hash is collection then this defines path to a single file in the collection
67
58
  */
68
- function downloadFile(ky, hash, path = '') {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- const response = yield (0, http_1.http)(ky, {
71
- method: 'GET',
72
- responseType: 'arraybuffer',
73
- path: `${bzzEndpoint}/${hash}/${path}`,
74
- });
75
- const file = Object.assign(Object.assign({}, (0, headers_1.readFileHeaders)(response.headers)), { data: (0, bytes_1.wrapBytesWithHelpers)(new Uint8Array(response.data)) });
76
- return file;
59
+ async function downloadFile(kyOptions, hash, path = '') {
60
+ const response = await (0, http_1.http)(kyOptions, {
61
+ method: 'GET',
62
+ responseType: 'arraybuffer',
63
+ path: `${bzzEndpoint}/${hash}/${path}`,
77
64
  });
65
+ const file = {
66
+ ...(0, headers_1.readFileHeaders)(response.headers),
67
+ data: (0, bytes_1.wrapBytesWithHelpers)(new Uint8Array(response.parsedData)),
68
+ };
69
+ return file;
78
70
  }
79
71
  exports.downloadFile = downloadFile;
80
72
  /**
81
73
  * Download single file as a readable stream
82
74
  *
83
- * @param ky Ky instance for given Bee class instance
75
+ * @param kyOptions Ky Options for making requests
84
76
  * @param hash Bee file or collection hash
85
77
  * @param path If hash is collection then this defines path to a single file in the collection
86
78
  */
87
- function downloadFileReadable(ky, hash, path = '') {
88
- return __awaiter(this, void 0, void 0, function* () {
89
- const response = yield (0, http_1.http)(ky, {
90
- method: 'GET',
91
- responseType: 'stream',
92
- path: `${bzzEndpoint}/${hash}/${path}`,
93
- });
94
- const file = Object.assign(Object.assign({}, (0, headers_1.readFileHeaders)(response.headers)), { data: response.data });
95
- return file;
79
+ async function downloadFileReadable(kyOptions, hash, path = '') {
80
+ const response = await (0, http_1.http)(kyOptions, {
81
+ method: 'GET',
82
+ responseType: 'stream',
83
+ path: `${bzzEndpoint}/${hash}/${path}`,
96
84
  });
85
+ const file = {
86
+ ...(0, headers_1.readFileHeaders)(response.headers),
87
+ data: response.parsedData,
88
+ };
89
+ return file;
97
90
  }
98
91
  exports.downloadFileReadable = downloadFileReadable;
99
92
  function extractCollectionUploadHeaders(postageBatchId, options) {
100
93
  const headers = (0, headers_1.extractUploadHeaders)(postageBatchId, options);
101
- if (options === null || options === void 0 ? void 0 : options.indexDocument)
94
+ if (options?.indexDocument)
102
95
  headers['swarm-index-document'] = options.indexDocument;
103
- if (options === null || options === void 0 ? void 0 : options.errorDocument)
96
+ if (options?.errorDocument)
104
97
  headers['swarm-error-document'] = options.errorDocument;
105
98
  return headers;
106
99
  }
107
100
  /**
108
101
  * Upload collection
109
- * @param ky Ky instance for given Bee class instance
102
+ * @param kyOptions Ky Options for making requests
110
103
  * @param collection Collection of Uint8Array buffers to upload
111
104
  * @param postageBatchId Postage BatchId that will be assigned to uploaded data
112
105
  * @param options
113
106
  */
114
- function uploadCollection(ky, collection, postageBatchId, options) {
115
- return __awaiter(this, void 0, void 0, function* () {
116
- (0, collection_1.assertCollection)(collection);
117
- const tarData = (0, tar_1.makeTar)(collection);
118
- const response = yield (0, http_1.http)(ky, {
119
- method: 'post',
120
- path: bzzEndpoint,
121
- body: tarData,
122
- responseType: 'json',
123
- headers: Object.assign({ 'content-type': 'application/x-tar', 'swarm-collection': 'true' }, extractCollectionUploadHeaders(postageBatchId, options)),
124
- });
125
- return {
126
- reference: response.data.reference,
127
- tagUid: (0, type_1.makeTagUid)(response.headers.get('swarm-tag')),
128
- };
107
+ async function uploadCollection(kyOptions, collection, postageBatchId, options) {
108
+ (0, collection_1.assertCollection)(collection);
109
+ const tarData = (0, tar_1.makeTar)(collection);
110
+ const response = await (0, http_1.http)(kyOptions, {
111
+ method: 'post',
112
+ path: bzzEndpoint,
113
+ body: tarData,
114
+ responseType: 'json',
115
+ headers: {
116
+ 'content-type': 'application/x-tar',
117
+ 'swarm-collection': 'true',
118
+ ...extractCollectionUploadHeaders(postageBatchId, options),
119
+ },
129
120
  });
121
+ return {
122
+ reference: response.parsedData.reference,
123
+ tagUid: (0, type_1.makeTagUid)(response.headers.get('swarm-tag')),
124
+ };
130
125
  }
131
126
  exports.uploadCollection = uploadCollection;
@@ -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.download = exports.upload = void 0;
13
4
  const headers_1 = require("../utils/headers");
@@ -26,33 +17,32 @@ const endpoint = 'chunks';
26
17
  * @param postageBatchId Postage BatchId that will be assigned to uploaded data
27
18
  * @param options Additional options like tag, encryption, pinning
28
19
  */
29
- function upload(ky, data, postageBatchId, options) {
30
- return __awaiter(this, void 0, void 0, function* () {
31
- const response = yield (0, http_1.http)(ky, {
32
- method: 'post',
33
- path: `${endpoint}`,
34
- body: data,
35
- headers: Object.assign({ 'content-type': 'application/octet-stream' }, (0, headers_1.extractUploadHeaders)(postageBatchId, options)),
36
- responseType: 'json',
37
- });
38
- return response.data.reference;
20
+ async function upload(kyOptions, data, postageBatchId, options) {
21
+ const response = await (0, http_1.http)(kyOptions, {
22
+ method: 'post',
23
+ path: `${endpoint}`,
24
+ body: data,
25
+ headers: {
26
+ 'content-type': 'application/octet-stream',
27
+ ...(0, headers_1.extractUploadHeaders)(postageBatchId, options),
28
+ },
29
+ responseType: 'json',
39
30
  });
31
+ return response.parsedData.reference;
40
32
  }
41
33
  exports.upload = upload;
42
34
  /**
43
35
  * Download chunk data as a byte array
44
36
  *
45
- * @param ky Ky instance for given Bee class instance
37
+ * @param kyOptions Ky Options for making requests
46
38
  * @param hash Bee content reference
47
39
  *
48
40
  */
49
- function download(ky, hash) {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- const response = yield (0, http_1.http)(ky, {
52
- responseType: 'arraybuffer',
53
- path: `${endpoint}/${hash}`,
54
- });
55
- return (0, bytes_1.wrapBytesWithHelpers)(new Uint8Array(response.data));
41
+ async function download(kyOptions, hash) {
42
+ const response = await (0, http_1.http)(kyOptions, {
43
+ responseType: 'arraybuffer',
44
+ path: `${endpoint}/${hash}`,
56
45
  });
46
+ return (0, bytes_1.wrapBytesWithHelpers)(new Uint8Array(response.parsedData));
57
47
  }
58
48
  exports.download = download;
@@ -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.getPastDueConsumptionPeerBalance = exports.getPastDueConsumptionBalances = exports.getPeerBalance = exports.getAllBalances = void 0;
13
4
  const http_1 = require("../../utils/http");
@@ -16,62 +7,54 @@ const consumedEndpoint = 'consumed';
16
7
  /**
17
8
  * Get the balances with all known peers including prepaid services
18
9
  *
19
- * @param ky Ky debug instance
10
+ * @param kyOptions Ky Options for making requests
20
11
  */
21
- function getAllBalances(ky) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- const response = yield (0, http_1.http)(ky, {
24
- path: balancesEndpoint,
25
- responseType: 'json',
26
- });
27
- return response.data;
12
+ async function getAllBalances(kyOptions) {
13
+ const response = await (0, http_1.http)(kyOptions, {
14
+ path: balancesEndpoint,
15
+ responseType: 'json',
28
16
  });
17
+ return response.parsedData;
29
18
  }
30
19
  exports.getAllBalances = getAllBalances;
31
20
  /**
32
21
  * Get the balances with a specific peer including prepaid services
33
22
  *
34
- * @param ky Ky debug instance
23
+ * @param kyOptions Ky Options for making requests
35
24
  * @param address Swarm address of peer
36
25
  */
37
- function getPeerBalance(ky, address) {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- const response = yield (0, http_1.http)(ky, {
40
- path: `${balancesEndpoint}/${address}`,
41
- responseType: 'json',
42
- });
43
- return response.data;
26
+ async function getPeerBalance(kyOptions, address) {
27
+ const response = await (0, http_1.http)(kyOptions, {
28
+ path: `${balancesEndpoint}/${address}`,
29
+ responseType: 'json',
44
30
  });
31
+ return response.parsedData;
45
32
  }
46
33
  exports.getPeerBalance = getPeerBalance;
47
34
  /**
48
35
  * Get the past due consumption balances with all known peers
49
36
  *
50
- * @param ky Ky debug instance
37
+ * @param kyOptions Ky Options for making requests
51
38
  */
52
- function getPastDueConsumptionBalances(ky) {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- const response = yield (0, http_1.http)(ky, {
55
- path: consumedEndpoint,
56
- responseType: 'json',
57
- });
58
- return response.data;
39
+ async function getPastDueConsumptionBalances(kyOptions) {
40
+ const response = await (0, http_1.http)(kyOptions, {
41
+ path: consumedEndpoint,
42
+ responseType: 'json',
59
43
  });
44
+ return response.parsedData;
60
45
  }
61
46
  exports.getPastDueConsumptionBalances = getPastDueConsumptionBalances;
62
47
  /**
63
48
  * Get the past due consumption balance with a specific peer
64
49
  *
65
- * @param ky Ky debug instance
50
+ * @param kyOptions Ky Options for making requests
66
51
  * @param address Swarm address of peer
67
52
  */
68
- function getPastDueConsumptionPeerBalance(ky, address) {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- const response = yield (0, http_1.http)(ky, {
71
- path: `${consumedEndpoint}/${address}`,
72
- responseType: 'json',
73
- });
74
- return response.data;
53
+ async function getPastDueConsumptionPeerBalance(kyOptions, address) {
54
+ const response = await (0, http_1.http)(kyOptions, {
55
+ path: `${consumedEndpoint}/${address}`,
56
+ responseType: 'json',
75
57
  });
58
+ return response.parsedData;
76
59
  }
77
60
  exports.getPastDueConsumptionPeerBalance = getPastDueConsumptionPeerBalance;
@@ -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.withdrawTokens = exports.depositTokens = exports.getLastCheques = exports.getLastChequesForPeer = exports.cashoutLastCheque = exports.getLastCashoutAction = exports.getChequebookBalance = exports.getChequebookAddress = void 0;
13
4
  const http_1 = require("../../utils/http");
@@ -15,153 +6,137 @@ const chequebookEndpoint = 'chequebook';
15
6
  /**
16
7
  * Get the address of the chequebook contract used
17
8
  *
18
- * @param ky Ky debug instance
9
+ * @param kyOptions Ky Options for making requests
19
10
  */
20
- function getChequebookAddress(ky) {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- const response = yield (0, http_1.http)(ky, {
23
- path: chequebookEndpoint + '/address',
24
- responseType: 'json',
25
- });
26
- return response.data;
11
+ async function getChequebookAddress(kyOptions) {
12
+ const response = await (0, http_1.http)(kyOptions, {
13
+ path: chequebookEndpoint + '/address',
14
+ responseType: 'json',
27
15
  });
16
+ return response.parsedData;
28
17
  }
29
18
  exports.getChequebookAddress = getChequebookAddress;
30
19
  /**
31
20
  * Get the balance of the chequebook
32
21
  *
33
- * @param ky Ky debug instance
22
+ * @param kyOptions Ky Options for making requests
34
23
  */
35
- function getChequebookBalance(ky) {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- const response = yield (0, http_1.http)(ky, {
38
- path: chequebookEndpoint + '/balance',
39
- responseType: 'json',
40
- });
41
- return response.data;
24
+ async function getChequebookBalance(kyOptions) {
25
+ const response = await (0, http_1.http)(kyOptions, {
26
+ path: chequebookEndpoint + '/balance',
27
+ responseType: 'json',
42
28
  });
29
+ return response.parsedData;
43
30
  }
44
31
  exports.getChequebookBalance = getChequebookBalance;
45
32
  /**
46
33
  * Get last cashout action for the peer
47
34
  *
48
- * @param ky Ky debug instance
35
+ * @param kyOptions Ky Options for making requests
49
36
  * @param peer Swarm address of peer
50
37
  */
51
- function getLastCashoutAction(ky, peer) {
52
- return __awaiter(this, void 0, void 0, function* () {
53
- const response = yield (0, http_1.http)(ky, {
54
- path: chequebookEndpoint + `/cashout/${peer}`,
55
- responseType: 'json',
56
- });
57
- return response.data;
38
+ async function getLastCashoutAction(kyOptions, peer) {
39
+ const response = await (0, http_1.http)(kyOptions, {
40
+ path: chequebookEndpoint + `/cashout/${peer}`,
41
+ responseType: 'json',
58
42
  });
43
+ return response.parsedData;
59
44
  }
60
45
  exports.getLastCashoutAction = getLastCashoutAction;
61
46
  /**
62
47
  * Cashout the last cheque for the peer
63
48
  *
64
- * @param ky Ky debug instance
49
+ * @param kyOptions Ky Options for making requests
65
50
  * @param peer Swarm address of peer
66
51
  * @param options
67
52
  */
68
- function cashoutLastCheque(ky, peer, options) {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- const headers = {};
71
- if (options === null || options === void 0 ? void 0 : options.gasPrice) {
72
- headers['gas-price'] = options.gasPrice.toString();
73
- }
74
- if (options === null || options === void 0 ? void 0 : options.gasLimit) {
75
- headers['gas-limit'] = options.gasLimit.toString();
76
- }
77
- const response = yield (0, http_1.http)(ky, {
78
- method: 'post',
79
- path: chequebookEndpoint + `/cashout/${peer}`,
80
- responseType: 'json',
81
- headers,
82
- });
83
- return response.data.transactionHash;
53
+ async function cashoutLastCheque(kyOptions, peer, options) {
54
+ const headers = {};
55
+ if (options?.gasPrice) {
56
+ headers['gas-price'] = options.gasPrice.toString();
57
+ }
58
+ if (options?.gasLimit) {
59
+ headers['gas-limit'] = options.gasLimit.toString();
60
+ }
61
+ const response = await (0, http_1.http)(kyOptions, {
62
+ method: 'post',
63
+ path: chequebookEndpoint + `/cashout/${peer}`,
64
+ responseType: 'json',
65
+ headers,
84
66
  });
67
+ return response.parsedData.transactionHash;
85
68
  }
86
69
  exports.cashoutLastCheque = cashoutLastCheque;
87
70
  /**
88
71
  * Get last cheques for the peer
89
72
  *
90
- * @param ky Ky debug instance
73
+ * @param kyOptions Ky Options for making requests
91
74
  * @param peer Swarm address of peer
92
75
  */
93
- function getLastChequesForPeer(ky, peer) {
94
- return __awaiter(this, void 0, void 0, function* () {
95
- const response = yield (0, http_1.http)(ky, {
96
- path: chequebookEndpoint + `/cheque/${peer}`,
97
- responseType: 'json',
98
- });
99
- return response.data;
76
+ async function getLastChequesForPeer(kyOptions, peer) {
77
+ const response = await (0, http_1.http)(kyOptions, {
78
+ path: chequebookEndpoint + `/cheque/${peer}`,
79
+ responseType: 'json',
100
80
  });
81
+ return response.parsedData;
101
82
  }
102
83
  exports.getLastChequesForPeer = getLastChequesForPeer;
103
84
  /**
104
85
  * Get last cheques for all peers
105
86
  *
106
- * @param ky Ky debug instance
87
+ * @param kyOptions Ky Options for making requests
107
88
  */
108
- function getLastCheques(ky) {
109
- return __awaiter(this, void 0, void 0, function* () {
110
- const response = yield (0, http_1.http)(ky, {
111
- path: chequebookEndpoint + '/cheque',
112
- responseType: 'json',
113
- });
114
- return response.data;
89
+ async function getLastCheques(kyOptions) {
90
+ const response = await (0, http_1.http)(kyOptions, {
91
+ path: chequebookEndpoint + '/cheque',
92
+ responseType: 'json',
115
93
  });
94
+ return response.parsedData;
116
95
  }
117
96
  exports.getLastCheques = getLastCheques;
118
97
  /**
119
98
  * Deposit tokens from overlay address into chequebook
120
99
  *
121
- * @param ky Ky debug instance
100
+ * @param kyOptions Ky Options for making requests
122
101
  * @param amount Amount of tokens to deposit
123
102
  * @param gasPrice Gas Price in WEI for the transaction call
124
103
  * @return string Hash of the transaction
125
104
  */
126
- function depositTokens(ky, amount, gasPrice) {
127
- return __awaiter(this, void 0, void 0, function* () {
128
- const headers = {};
129
- if (gasPrice) {
130
- headers['gas-price'] = gasPrice.toString();
131
- }
132
- const response = yield (0, http_1.http)(ky, {
133
- method: 'post',
134
- path: chequebookEndpoint + '/deposit',
135
- responseType: 'json',
136
- searchParams: { amount: amount.toString(10) },
137
- headers,
138
- });
139
- return response.data.transactionHash;
105
+ async function depositTokens(kyOptions, amount, gasPrice) {
106
+ const headers = {};
107
+ if (gasPrice) {
108
+ headers['gas-price'] = gasPrice.toString();
109
+ }
110
+ const response = await (0, http_1.http)(kyOptions, {
111
+ method: 'post',
112
+ path: chequebookEndpoint + '/deposit',
113
+ responseType: 'json',
114
+ searchParams: { amount: amount.toString(10) },
115
+ headers,
140
116
  });
117
+ return response.parsedData.transactionHash;
141
118
  }
142
119
  exports.depositTokens = depositTokens;
143
120
  /**
144
121
  * Withdraw tokens from the chequebook to the overlay address
145
122
  *
146
- * @param ky Ky debug instance
123
+ * @param kyOptions Ky Options for making requests
147
124
  * @param amount Amount of tokens to withdraw
148
125
  * @param gasPrice Gas Price in WEI for the transaction call
149
126
  * @return string Hash of the transaction
150
127
  */
151
- function withdrawTokens(ky, amount, gasPrice) {
152
- return __awaiter(this, void 0, void 0, function* () {
153
- const headers = {};
154
- if (gasPrice) {
155
- headers['gas-price'] = gasPrice.toString();
156
- }
157
- const response = yield (0, http_1.http)(ky, {
158
- method: 'post',
159
- path: chequebookEndpoint + '/withdraw',
160
- responseType: 'json',
161
- searchParams: { amount: amount.toString(10) },
162
- headers,
163
- });
164
- return response.data.transactionHash;
128
+ async function withdrawTokens(kyOptions, amount, gasPrice) {
129
+ const headers = {};
130
+ if (gasPrice) {
131
+ headers['gas-price'] = gasPrice.toString();
132
+ }
133
+ const response = await (0, http_1.http)(kyOptions, {
134
+ method: 'post',
135
+ path: chequebookEndpoint + '/withdraw',
136
+ responseType: 'json',
137
+ searchParams: { amount: amount.toString(10) },
138
+ headers,
165
139
  });
140
+ return response.parsedData.transactionHash;
166
141
  }
167
142
  exports.withdrawTokens = withdrawTokens;