@biorate/axios 0.29.1 → 0.30.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/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [0.30.0](https://github.com/biorate/core/compare/v0.29.1...v0.30.0) (2022-06-20)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * *.ts into npmignore ([6a6be03](https://github.com/biorate/core/commit/6a6be030a1e8923df4b03d518f08618e759d06fa))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [0.29.1](https://github.com/biorate/core/compare/v0.29.0...v0.29.1) (2022-06-20)
7
18
 
8
19
  **Note:** Version bump only for package @biorate/axios
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
17
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
18
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
19
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
20
+ };
21
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
22
+ if (kind === "m") throw new TypeError("Private method is not writable");
23
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
24
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
25
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
26
+ };
27
+ var _Axios_client;
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.Axios = void 0;
30
+ const lodash_1 = require("lodash");
31
+ const axios_1 = require("axios");
32
+ const axios_retry_1 = require("axios-retry");
33
+ const pathToUrl = require("path-to-url");
34
+ __exportStar(require("./interfaces"), exports);
35
+ const axiosRetryConfigKeys = [
36
+ 'retries',
37
+ 'retryDelay',
38
+ 'shouldResetTimeout',
39
+ 'retryCondition',
40
+ ];
41
+ const axiosExcludeKeys = ['path', 'config'];
42
+ class Axios {
43
+ constructor() {
44
+ _Axios_client.set(this, void 0);
45
+ }
46
+ static fetch(...args) {
47
+ return this._fetch(...args);
48
+ }
49
+ static _fetch(options) {
50
+ if (!this.cache.has(this))
51
+ this.cache.set(this, new this());
52
+ return this.cache.get(this).fetch(options);
53
+ }
54
+ async fetch(options) {
55
+ if (!__classPrivateFieldGet(this, _Axios_client, "f")) {
56
+ __classPrivateFieldSet(this, _Axios_client, axios_1.default.create(), "f");
57
+ (0, axios_retry_1.default)(__classPrivateFieldGet(this, _Axios_client, "f"), (0, lodash_1.pick)(this, axiosRetryConfigKeys));
58
+ }
59
+ const settings = Object.assign(Object.assign({}, this), options);
60
+ if (settings.baseURL && settings.path)
61
+ settings.baseURL = pathToUrl(settings.baseURL, settings.path);
62
+ if (settings.url && settings.path)
63
+ settings.url = pathToUrl(settings.url, settings.path);
64
+ const params = Object.assign({}, (0, lodash_1.omit)(settings, axiosRetryConfigKeys.concat(axiosExcludeKeys)));
65
+ try {
66
+ await this.before(params);
67
+ return await __classPrivateFieldGet(this, _Axios_client, "f").call(this, params);
68
+ }
69
+ catch (e) {
70
+ await this.catch(e);
71
+ }
72
+ finally {
73
+ await this.finally();
74
+ }
75
+ }
76
+ async before(params) { }
77
+ async catch(e) {
78
+ throw e;
79
+ }
80
+ async finally() { }
81
+ }
82
+ exports.Axios = Axios;
83
+ _Axios_client = new WeakMap();
84
+ Axios.cache = new WeakMap();
85
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAoC;AACpC,iCAAgF;AAChF,6CAAuD;AACvD,yCAAyC;AAGzC,+CAA6B;AAE7B,MAAM,oBAAoB,GAAG;IAC3B,SAAS;IACT,YAAY;IACZ,oBAAoB;IACpB,gBAAgB;CACjB,CAAC;AAEF,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAyB5C,MAAa,KAAK;IAAlB;QAuBE,gCAAuB;IAyCzB,CAAC;IAxDQ,MAAM,CAAC,KAAK,CAAC,GAAG,IAAe;QACpC,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC;IAC9B,CAAC;IAIS,MAAM,CAAC,MAAM,CACrB,OAA4B;QAE5B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;QAC5D,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,KAAK,CAAI,OAAO,CAAC,CAAC;IAChD,CAAC;IAQS,KAAK,CAAC,KAAK,CAAI,OAA4B;QACnD,IAAI,CAAC,uBAAA,IAAI,qBAAQ,EAAE;YACjB,uBAAA,IAAI,iBAAW,eAAK,CAAC,MAAM,EAAE,MA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@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biorate/axios",
3
- "version": "0.29.1",
3
+ "version": "0.30.0",
4
4
  "description": "Axios OOP static interface",
5
5
  "main": "dist",
6
6
  "scripts": {
@@ -29,8 +29,8 @@
29
29
  "path-to-url": "^0.1.0"
30
30
  },
31
31
  "devDependencies": {
32
- "@biorate/config": "0.29.1",
33
- "@biorate/inversion": "0.29.1"
32
+ "@biorate/config": "0.30.0",
33
+ "@biorate/inversion": "0.30.0"
34
34
  },
35
- "gitHead": "5b2e555c3d82c8d276aa9385ebc0eff28c68db33"
35
+ "gitHead": "4e2b75f1a37d93bfb4854bd64ed9691781c2b800"
36
36
  }
@@ -0,0 +1,15 @@
1
+ import { Axios } from '../../src';
2
+ import { inject, container, Types } from '@biorate/inversion';
3
+ import { IConfig, Config } from '@biorate/config';
4
+
5
+ export class Yandex extends Axios {
6
+ @inject(Types.Config) public config: IConfig;
7
+ // @ts-ignore
8
+ public baseURL = this.config.get<string>('baseURL');
9
+ }
10
+
11
+ container.bind(Types.Config).to(Config).inSingletonScope();
12
+
13
+ container.get<IConfig>(Types.Config).merge({
14
+ baseURL: 'https://google.com',
15
+ });