@hyper-fetch/core 5.1.1 → 5.2.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyper-fetch/core",
3
- "version": "5.1.1",
3
+ "version": "5.2.0",
4
4
  "private": false,
5
5
  "description": "Cache, Queue and Persist your requests no matter if you are online or offline!",
6
6
  "author": "Maciej Pyrc <m.pyrc@interia.pl>",
@@ -57,6 +57,7 @@ export const getAdapterBindings = async <T extends AdapterInstance = AdapterType
57
57
  const { client, abortKey, queueKey, endpoint, data } = request;
58
58
 
59
59
  const fullUrl = url + endpoint;
60
+
60
61
  const effects = client.effects.filter((effect) => request.effectKey === effect.getEffectKey());
61
62
  const headers = headerMapper(request);
62
63
  let payload = data;
@@ -337,7 +338,8 @@ export const getAdapterBindings = async <T extends AdapterInstance = AdapterType
337
338
  if (processingError) {
338
339
  return onError(processingError, systemErrorStatus, systemErrorExtra, () => null);
339
340
  }
340
- if (req.mock && req.isMockEnabled) {
341
+
342
+ if (req.mock && req.isMockEnabled && req.client.isMockEnabled) {
341
343
  return mocker(request, {
342
344
  onError,
343
345
  onResponseEnd,
@@ -26,7 +26,6 @@ export const adapter: AdapterType = async (request, requestId) => {
26
26
  const { method = HttpMethodsEnum.get, client } = request;
27
27
  const httpClient = client.url.includes("https://") ? https : http;
28
28
  const options = {
29
- path: fullUrl,
30
29
  method,
31
30
  headers: headers as OutgoingHttpHeaders,
32
31
  timeout: defaultTimeout,
@@ -43,8 +42,10 @@ export const adapter: AdapterType = async (request, requestId) => {
43
42
  options.headers["Content-Length"] = Buffer.byteLength(JSON.stringify(payload));
44
43
  }
45
44
 
45
+ const requestUrl = !fullUrl.startsWith("http") ? `http://${fullUrl}` : fullUrl;
46
+
46
47
  return makeRequest((resolve) => {
47
- const httpRequest = httpClient.request(options, (response) => {
48
+ const httpRequest = httpClient.request(requestUrl, options, (response) => {
48
49
  response.setEncoding("utf8");
49
50
  unmountListener = createAbortListener(0, xhrExtra, response.destroy, resolve);
50
51
 
@@ -69,6 +69,8 @@ export class Client<
69
69
  defaultMethod: ExtractAdapterMethodType<Adapter> = HttpMethodsEnum.get as ExtractAdapterMethodType<Adapter>;
70
70
  defaultExtra: ExtractAdapterExtraType<Adapter> = xhrExtra as ExtractAdapterExtraType<Adapter>;
71
71
 
72
+ isMockEnabled = true;
73
+
72
74
  // Registered requests effect
73
75
  effects: RequestEffectInstance[] = [];
74
76
 
@@ -199,6 +201,15 @@ export class Client<
199
201
  return this;
200
202
  };
201
203
 
204
+ /**
205
+ * Set globally if mocking should be enabled or disabled for all client requests.
206
+ * @param isMockEnabled
207
+ */
208
+ setEnableGlobalMocking = (isMockEnabled: boolean) => {
209
+ this.isMockEnabled = isMockEnabled;
210
+ return this;
211
+ };
212
+
202
213
  /**
203
214
  * Set the request payload mapping function which get triggered before request get send
204
215
  */