@ethersphere/bee-js 6.0.0-pre.1 → 6.0.0-pre.3
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.
- package/dist/cjs/bee-debug.js +3 -0
- package/dist/cjs/bee.js +3 -0
- package/dist/cjs/modules/bytes.js +1 -2
- package/dist/cjs/modules/pss.js +1 -2
- package/dist/cjs/utils/http.js +11 -1
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee-debug.js +3 -0
- package/dist/mjs/bee.js +3 -0
- package/dist/mjs/modules/bytes.js +1 -2
- package/dist/mjs/modules/pss.js +1 -2
- package/dist/mjs/utils/http.js +15 -3
- package/dist/types/types/index.d.ts +3 -1
- package/dist/types/utils/http.d.ts +0 -1
- package/package.json +1 -1
package/dist/mjs/bee-debug.js
CHANGED
|
@@ -27,6 +27,9 @@ export class BeeDebug {
|
|
|
27
27
|
if (options?.headers) {
|
|
28
28
|
requestOptions.headers = options.headers;
|
|
29
29
|
}
|
|
30
|
+
if (options?.onRequest) {
|
|
31
|
+
requestOptions.onRequest = options.onRequest;
|
|
32
|
+
}
|
|
30
33
|
this.requestOptions = requestOptions;
|
|
31
34
|
}
|
|
32
35
|
async getNodeAddresses(options) {
|
package/dist/mjs/bee.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { wrapBytesWithHelpers } from "../utils/bytes.js";
|
|
2
|
-
import { prepareData } from "../utils/data.js";
|
|
3
2
|
import { extractUploadHeaders } from "../utils/headers.js";
|
|
4
3
|
import { http } from "../utils/http.js";
|
|
5
4
|
import { makeTagUid } from "../utils/type.js";
|
|
@@ -17,7 +16,7 @@ export async function upload(requestOptions, data, postageBatchId, options) {
|
|
|
17
16
|
url: endpoint,
|
|
18
17
|
method: 'post',
|
|
19
18
|
responseType: 'json',
|
|
20
|
-
data
|
|
19
|
+
data,
|
|
21
20
|
headers: {
|
|
22
21
|
'content-type': 'application/octet-stream',
|
|
23
22
|
...extractUploadHeaders(postageBatchId, options)
|
package/dist/mjs/modules/pss.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import WebSocket from 'isomorphic-ws';
|
|
2
|
-
import { prepareData } from "../utils/data.js";
|
|
3
2
|
import { extractUploadHeaders } from "../utils/headers.js";
|
|
4
3
|
import { http } from "../utils/http.js";
|
|
5
4
|
const endpoint = 'pss';
|
|
@@ -18,7 +17,7 @@ export async function send(requestOptions, topic, target, data, postageBatchId,
|
|
|
18
17
|
await http(requestOptions, {
|
|
19
18
|
method: 'post',
|
|
20
19
|
url: `${endpoint}/send/${topic}/${target}`,
|
|
21
|
-
data
|
|
20
|
+
data,
|
|
22
21
|
responseType: 'json',
|
|
23
22
|
params: {
|
|
24
23
|
recipient
|
package/dist/mjs/utils/http.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
-
import { Objects } from 'cafe-utility';
|
|
2
|
+
import { Objects, Strings } from 'cafe-utility';
|
|
3
3
|
export const DEFAULT_HTTP_CONFIG = {
|
|
4
4
|
headers: {
|
|
5
|
-
accept: 'application/json, text/plain, */*'
|
|
6
|
-
'user-agent': `bee-js`
|
|
5
|
+
accept: 'application/json, text/plain, */*'
|
|
7
6
|
}
|
|
8
7
|
};
|
|
9
8
|
/**
|
|
@@ -14,9 +13,22 @@ export const DEFAULT_HTTP_CONFIG = {
|
|
|
14
13
|
export async function http(options, config) {
|
|
15
14
|
try {
|
|
16
15
|
const requestConfig = Objects.deepMerge3(DEFAULT_HTTP_CONFIG, config, options);
|
|
16
|
+
maybeRunOnRequestHook(options, requestConfig);
|
|
17
17
|
const response = await axios(requestConfig);
|
|
18
18
|
return response;
|
|
19
19
|
} catch (e) {
|
|
20
20
|
throw e;
|
|
21
21
|
}
|
|
22
|
+
}
|
|
23
|
+
function maybeRunOnRequestHook(options, requestConfig) {
|
|
24
|
+
if (options.onRequest) {
|
|
25
|
+
options.onRequest({
|
|
26
|
+
method: requestConfig.method,
|
|
27
|
+
url: Strings.joinUrl(requestConfig.baseURL, requestConfig.url),
|
|
28
|
+
headers: {
|
|
29
|
+
...requestConfig.headers
|
|
30
|
+
},
|
|
31
|
+
params: requestConfig.params
|
|
32
|
+
});
|
|
33
|
+
}
|
|
22
34
|
}
|
|
@@ -78,12 +78,14 @@ export type BeeRequestOptions = {
|
|
|
78
78
|
timeout?: number | false;
|
|
79
79
|
retry?: number | false;
|
|
80
80
|
headers?: Record<string, string>;
|
|
81
|
+
onRequest?: (request: BeeRequest) => void;
|
|
81
82
|
};
|
|
82
83
|
export interface BeeOptions extends BeeRequestOptions {
|
|
83
84
|
/**
|
|
84
85
|
* Signer object or private key of the Signer in form of either hex string or Uint8Array that will be default signer for the instance.
|
|
85
86
|
*/
|
|
86
87
|
signer?: Signer | Uint8Array | string;
|
|
88
|
+
onRequest?: (request: BeeRequest) => void;
|
|
87
89
|
}
|
|
88
90
|
export interface UploadResultWithCid extends UploadResult {
|
|
89
91
|
/**
|
|
@@ -277,7 +279,7 @@ export type HttpMethod = 'GET' | 'DELETE' | 'POST' | 'PATCH' | 'PUT';
|
|
|
277
279
|
export type HookCallback<V> = (value: V) => void | Promise<void>;
|
|
278
280
|
export interface BeeRequest {
|
|
279
281
|
url: string;
|
|
280
|
-
method:
|
|
282
|
+
method: string;
|
|
281
283
|
headers?: Record<string, string>;
|
|
282
284
|
params?: Record<string, unknown>;
|
|
283
285
|
}
|