@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.
@@ -53,6 +53,9 @@ class BeeDebug {
53
53
  if (options?.headers) {
54
54
  requestOptions.headers = options.headers;
55
55
  }
56
+ if (options?.onRequest) {
57
+ requestOptions.onRequest = options.onRequest;
58
+ }
56
59
  this.requestOptions = requestOptions;
57
60
  }
58
61
  async getNodeAddresses(options) {
package/dist/cjs/bee.js CHANGED
@@ -80,6 +80,9 @@ class Bee {
80
80
  if (options?.headers) {
81
81
  requestOptions.headers = options.headers;
82
82
  }
83
+ if (options?.onRequest) {
84
+ requestOptions.onRequest = options.onRequest;
85
+ }
83
86
  this.requestOptions = requestOptions;
84
87
  }
85
88
  /**
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.downloadReadable = exports.download = exports.upload = void 0;
4
4
  const bytes_1 = require("../utils/bytes");
5
- const data_1 = require("../utils/data");
6
5
  const headers_1 = require("../utils/headers");
7
6
  const http_1 = require("../utils/http");
8
7
  const type_1 = require("../utils/type");
@@ -20,7 +19,7 @@ async function upload(requestOptions, data, postageBatchId, options) {
20
19
  url: endpoint,
21
20
  method: 'post',
22
21
  responseType: 'json',
23
- data: await (0, data_1.prepareData)(data),
22
+ data,
24
23
  headers: {
25
24
  'content-type': 'application/octet-stream',
26
25
  ...(0, headers_1.extractUploadHeaders)(postageBatchId, options),
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.subscribe = exports.send = void 0;
7
7
  const isomorphic_ws_1 = __importDefault(require("isomorphic-ws"));
8
- const data_1 = require("../utils/data");
9
8
  const headers_1 = require("../utils/headers");
10
9
  const http_1 = require("../utils/http");
11
10
  const endpoint = 'pss';
@@ -24,7 +23,7 @@ async function send(requestOptions, topic, target, data, postageBatchId, recipie
24
23
  await (0, http_1.http)(requestOptions, {
25
24
  method: 'post',
26
25
  url: `${endpoint}/send/${topic}/${target}`,
27
- data: await (0, data_1.prepareData)(data),
26
+ data,
28
27
  responseType: 'json',
29
28
  params: { recipient },
30
29
  headers: (0, headers_1.extractUploadHeaders)(postageBatchId),
@@ -9,7 +9,6 @@ const cafe_utility_1 = require("cafe-utility");
9
9
  exports.DEFAULT_HTTP_CONFIG = {
10
10
  headers: {
11
11
  accept: 'application/json, text/plain, */*',
12
- 'user-agent': `bee-js`,
13
12
  },
14
13
  };
15
14
  /**
@@ -20,6 +19,7 @@ exports.DEFAULT_HTTP_CONFIG = {
20
19
  async function http(options, config) {
21
20
  try {
22
21
  const requestConfig = cafe_utility_1.Objects.deepMerge3(exports.DEFAULT_HTTP_CONFIG, config, options);
22
+ maybeRunOnRequestHook(options, requestConfig);
23
23
  const response = await (0, axios_1.default)(requestConfig);
24
24
  return response;
25
25
  }
@@ -28,3 +28,13 @@ async function http(options, config) {
28
28
  }
29
29
  }
30
30
  exports.http = http;
31
+ function maybeRunOnRequestHook(options, requestConfig) {
32
+ if (options.onRequest) {
33
+ options.onRequest({
34
+ method: requestConfig.method,
35
+ url: cafe_utility_1.Strings.joinUrl(requestConfig.baseURL, requestConfig.url),
36
+ headers: { ...requestConfig.headers },
37
+ params: requestConfig.params,
38
+ });
39
+ }
40
+ }