@foxford/services 1.0.0 → 1.1.0-beta-9bfd8f50-20231019
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/README.md +104 -41
- package/_virtual/_commonjsHelpers.js +9 -0
- package/_virtual/_commonjsHelpers.mjs +5 -0
- package/_virtual/axios.js +7 -0
- package/_virtual/axios.mjs +3 -0
- package/_virtual/index.js +7 -0
- package/_virtual/index.mjs +3 -0
- package/_virtual/index2.js +7 -0
- package/_virtual/index2.mjs +3 -0
- package/api/index.js +52 -1
- package/api/index.mjs +48 -1
- package/api/interceptors/request.js +49 -1
- package/api/interceptors/request.mjs +45 -1
- package/api/interceptors/response.js +40 -1
- package/api/interceptors/response.mjs +36 -1
- package/api/interceptors/responseFail.js +37 -1
- package/api/interceptors/responseFail.mjs +33 -1
- package/api/plugins/request/index.js +12 -0
- package/api/plugins/request/index.mjs +8 -0
- package/api/plugins/response-success/index.js +12 -0
- package/api/plugins/response-success/index.mjs +8 -0
- package/dependencies/@babel/runtime/helpers/esm/asyncToGenerator.js +34 -0
- package/dependencies/@babel/runtime/helpers/esm/asyncToGenerator.mjs +32 -0
- package/dependencies/@babel/runtime/helpers/esm/defineProperty.js +20 -0
- package/dependencies/@babel/runtime/helpers/esm/defineProperty.mjs +18 -0
- package/dependencies/@babel/runtime/helpers/esm/objectSpread2.js +27 -0
- package/dependencies/@babel/runtime/helpers/esm/objectSpread2.mjs +25 -0
- package/dependencies/@babel/runtime/helpers/esm/toPrimitive.js +16 -0
- package/dependencies/@babel/runtime/helpers/esm/toPrimitive.mjs +14 -0
- package/dependencies/@babel/runtime/helpers/esm/toPropertyKey.js +11 -0
- package/dependencies/@babel/runtime/helpers/esm/toPropertyKey.mjs +9 -0
- package/dependencies/@babel/runtime/helpers/esm/typeof.js +13 -0
- package/dependencies/@babel/runtime/helpers/esm/typeof.mjs +11 -0
- package/dependencies/axios/index.js +14 -0
- package/dependencies/axios/index.mjs +12 -0
- package/dependencies/axios/lib/adapters/xhr.js +189 -0
- package/dependencies/axios/lib/adapters/xhr.mjs +185 -0
- package/dependencies/axios/lib/axios.js +68 -0
- package/dependencies/axios/lib/axios.mjs +67 -0
- package/dependencies/axios/lib/cancel/Cancel.js +29 -0
- package/dependencies/axios/lib/cancel/Cancel.mjs +25 -0
- package/dependencies/axios/lib/cancel/CancelToken.js +68 -0
- package/dependencies/axios/lib/cancel/CancelToken.mjs +64 -0
- package/dependencies/axios/lib/cancel/isCancel.js +18 -0
- package/dependencies/axios/lib/cancel/isCancel.mjs +14 -0
- package/dependencies/axios/lib/core/Axios.js +95 -0
- package/dependencies/axios/lib/core/Axios.mjs +93 -0
- package/dependencies/axios/lib/core/InterceptorManager.js +54 -0
- package/dependencies/axios/lib/core/InterceptorManager.mjs +52 -0
- package/dependencies/axios/lib/core/buildFullPath.js +36 -0
- package/dependencies/axios/lib/core/buildFullPath.mjs +32 -0
- package/dependencies/axios/lib/core/createError.js +33 -0
- package/dependencies/axios/lib/core/createError.mjs +29 -0
- package/dependencies/axios/lib/core/dispatchRequest.js +62 -0
- package/dependencies/axios/lib/core/dispatchRequest.mjs +60 -0
- package/dependencies/axios/lib/core/enhanceError.js +53 -0
- package/dependencies/axios/lib/core/enhanceError.mjs +49 -0
- package/dependencies/axios/lib/core/mergeConfig.js +68 -0
- package/dependencies/axios/lib/core/mergeConfig.mjs +66 -0
- package/dependencies/axios/lib/core/settle.js +34 -0
- package/dependencies/axios/lib/core/settle.mjs +30 -0
- package/dependencies/axios/lib/core/transformData.js +23 -0
- package/dependencies/axios/lib/core/transformData.mjs +21 -0
- package/dependencies/axios/lib/defaults.js +84 -0
- package/dependencies/axios/lib/defaults.mjs +82 -0
- package/dependencies/axios/lib/helpers/bind.js +13 -0
- package/dependencies/axios/lib/helpers/bind.mjs +11 -0
- package/dependencies/axios/lib/helpers/buildURL.js +59 -0
- package/dependencies/axios/lib/helpers/buildURL.mjs +57 -0
- package/dependencies/axios/lib/helpers/combineURLs.js +25 -0
- package/dependencies/axios/lib/helpers/combineURLs.mjs +21 -0
- package/dependencies/axios/lib/helpers/cookies.js +58 -0
- package/dependencies/axios/lib/helpers/cookies.mjs +54 -0
- package/dependencies/axios/lib/helpers/isAbsoluteURL.js +27 -0
- package/dependencies/axios/lib/helpers/isAbsoluteURL.mjs +23 -0
- package/dependencies/axios/lib/helpers/isAxiosError.js +24 -0
- package/dependencies/axios/lib/helpers/isAxiosError.mjs +20 -0
- package/dependencies/axios/lib/helpers/isURLSameOrigin.js +72 -0
- package/dependencies/axios/lib/helpers/isURLSameOrigin.mjs +68 -0
- package/dependencies/axios/lib/helpers/normalizeHeaderName.js +15 -0
- package/dependencies/axios/lib/helpers/normalizeHeaderName.mjs +13 -0
- package/dependencies/axios/lib/helpers/parseHeaders.js +61 -0
- package/dependencies/axios/lib/helpers/parseHeaders.mjs +57 -0
- package/dependencies/axios/lib/helpers/spread.js +40 -0
- package/dependencies/axios/lib/helpers/spread.mjs +36 -0
- package/dependencies/axios/lib/utils.js +346 -0
- package/dependencies/axios/lib/utils.mjs +344 -0
- package/dependencies/axios-retry/index.js +8 -0
- package/dependencies/axios-retry/index.mjs +6 -0
- package/dependencies/axios-retry/lib/index.js +243 -0
- package/dependencies/axios-retry/lib/index.mjs +241 -0
- package/dependencies/is-retry-allowed/index.js +20 -0
- package/dependencies/is-retry-allowed/index.mjs +18 -0
- package/index.d.ts +248 -7
- package/index.js +15 -1
- package/index.mjs +4 -1
- package/package.json +87 -21
- package/recaptcha/index.js +247 -1
- package/recaptcha/index.mjs +243 -1
- package/utils/uuid.js +27 -1
- package/utils/uuid.mjs +23 -1
- package/api/index.d.ts +0 -78
- package/api/index.js.flow +0 -59
- package/api/index.mjs.flow +0 -59
- package/api/plugins/AbstractApiRequestPlugin.js +0 -1
- package/api/plugins/AbstractApiRequestPlugin.mjs +0 -1
- package/api/plugins/AbstractApiResponseFailPlugin.js +0 -1
- package/api/plugins/AbstractApiResponseFailPlugin.mjs +0 -1
- package/api/plugins/AbstractApiResponseSuccessPlugin.js +0 -1
- package/api/plugins/AbstractApiResponseSuccessPlugin.mjs +0 -1
- package/index.js.flow +0 -18
- package/index.mjs.flow +0 -18
- package/recaptcha/index.d.ts +0 -17
- package/recaptcha/index.js.flow +0 -19
- package/recaptcha/index.mjs.flow +0 -19
- package/recaptcha/typings/window.d.ts +0 -15
package/README.md
CHANGED
|
@@ -1,81 +1,144 @@
|
|
|
1
|
-
|
|
1
|
+
# Сервисы Foxford
|
|
2
2
|
|
|
3
3
|
Библиотека фронтовых сервисов, которые помогут реализовать тот или иной функционал на уровне приложения.
|
|
4
4
|
Здесь будут появляться сервисы фокса, которые будут "отвязаны" от других сервисов и функций, не принадлежащих им.
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
## Recaptcha Service
|
|
9
9
|
|
|
10
10
|
Сервис для работы с Google-капчей.
|
|
11
11
|
|
|
12
|
+
> Поставщиком сервиса рекапчи является `@foxford/foxford-js-sdk` (FoxfordService)
|
|
13
|
+
|
|
12
14
|
Пример использования:
|
|
13
15
|
|
|
14
16
|
```js static
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
import { Foxford } from '@foxford/foxford-js-sdk'
|
|
18
|
+
|
|
19
|
+
const FoxfordService = new Foxford({
|
|
20
|
+
recaptchaConfig: {
|
|
21
|
+
locale: 'ru',
|
|
22
|
+
sitekey: 'captchaSecretKey',
|
|
23
|
+
}
|
|
18
24
|
})
|
|
25
|
+
|
|
26
|
+
const RecaptchaService: RecaptchaServiceInterface = FoxfordService.recaptcha
|
|
19
27
|
```
|
|
20
28
|
|
|
21
29
|
А далее в необходимом месте:
|
|
22
30
|
|
|
23
31
|
```js static
|
|
24
32
|
async function submitHandler() {
|
|
25
|
-
const tokenPayload = await
|
|
33
|
+
const tokenPayload = await RecaptchaService.execute() // <TOKEN>
|
|
26
34
|
}
|
|
27
35
|
```
|
|
28
36
|
|
|
29
|
-
|
|
37
|
+
> В `stoege` сервис рекапчи доступен в `'services/recaptcha'`
|
|
30
38
|
|
|
31
|
-
|
|
39
|
+
Пример использования в `stoege`
|
|
32
40
|
|
|
33
|
-
|
|
41
|
+
```js static
|
|
42
|
+
import { RecaptchaService } from 'services/recaptcha'
|
|
34
43
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
config: AxiosRequestConfig
|
|
38
|
-
recaptchaConfig?: RecaptchaConfig
|
|
39
|
-
plugins?: Array<AbstractApiRequestPlugin | AbstractApiResponseSuccessPlugin | AbstractApiResponseFailPlugin>
|
|
44
|
+
async function submitHandler() {
|
|
45
|
+
const tokenPayload = await RecaptchaService.execute() // <TOKEN>
|
|
40
46
|
}
|
|
41
47
|
```
|
|
42
|
-
где:
|
|
43
|
-
- `config` - Конфиг для Axios
|
|
44
|
-
- `recaptchaConfig` - параметры для сервиса капчи, если передан, то при инициализации сервиса апи будет добавлен плагин-перехватчик капчи(только если таковой инстанс не был передан в plugins)
|
|
45
|
-
- `plugins` - массив плагинов для `Axios Interceptors`
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
```javascript
|
|
49
|
-
import { ApiService } from '@foxford/services'
|
|
49
|
+
---
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
## API Service
|
|
52
|
+
|
|
53
|
+
### Для чего?
|
|
54
|
+
Чтобы разные проекты использовали единый HTTP-клиент (Axios) сервис апи был вынесен в пакеты
|
|
55
|
+
и опубликован в [npm](https://www.npmjs.com/package/@foxford/services)
|
|
56
|
+
|
|
57
|
+
Апи из пакета сервисов представляет собой фабрику, которая принимает параметры и возвращает
|
|
58
|
+
инстанс клиента, подробнее описано [здесь](./api/README.md)
|
|
56
59
|
|
|
57
|
-
|
|
58
|
-
Предназначены для обработки и преобразования данных внутри перехватчиков запросов Axios
|
|
60
|
+
___
|
|
59
61
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
- `ApiResponseFailPlugin` для `ResponseInterceptorFail`
|
|
62
|
+
### Как обесепечивается единобразное использование HTTP-клиента?
|
|
63
|
+
> Точкой правды, поставщиком HTTP-клиента является `@foxford/foxford-js-sdk (FoxfordService)`
|
|
64
|
+
> Все "потребители" должны использовать HTTP-клиент из `FoxfordService`
|
|
64
65
|
|
|
65
|
-
|
|
66
|
+
`FoxfordService` использует пакет сервисов `@foxford/services` для получения инстанса Api
|
|
67
|
+
конфигурирует его и примешивает [Interceptors](https://axios-http.com/docs/interceptors)
|
|
68
|
+
и отдает наружу два клиента:
|
|
66
69
|
|
|
67
|
-
|
|
70
|
+
1. `FoxfordService.foxApi` - инстанс Api, ориентированный на использование внутренних сервисов Фоксфорда, в нем:
|
|
71
|
+
- Используются `Api Interceptors`
|
|
72
|
+
По умолчанию используются два обязательных перехватчика(`camelize` и `referrer`) и один опциональный(`captcha`) в `interceptors.request`, это:
|
|
73
|
+
- `camelize` - для преобразования кейса в ответе запроса
|
|
74
|
+
- `referrer` - для проброса реферрера в запросе
|
|
75
|
+
- `captcha` - опциональный, будет добавлен, если при инициализации `FoxfordService`,
|
|
76
|
+
в конфиге будет передан конфиг для капчи. Подробнее [здесь](./api/README.md)
|
|
77
|
+
- Используется `axiosRetry` - плагин Api, перехватывающий упавшие запрос и поторяющий его (3 раза)
|
|
78
|
+
- Указан `baseURL`
|
|
79
|
+
2. `FoxfordService.api` - "базовый" инстанс Api, который имеет минимальную конфигурацию и не использует Interceptors и в нем не указан baseUrl
|
|
80
|
+
Предназначен для хождения "наружу"
|
|
68
81
|
|
|
82
|
+
#### Базовый конфиг Api используемый для `FoxfordService.api`
|
|
69
83
|
```javascript
|
|
70
|
-
|
|
71
|
-
|
|
84
|
+
{
|
|
85
|
+
xsrfCookieName: CSRF_COOKIE_NAME,
|
|
86
|
+
xsrfHeaderName: 'X-CSRF-Token',
|
|
87
|
+
headers: { 'X-Requested-With': 'XMLHttpRequest' },
|
|
88
|
+
}
|
|
89
|
+
```
|
|
72
90
|
|
|
73
|
-
|
|
91
|
+
#### Конфиг Api используемый для `FoxfordService.foxApi`
|
|
92
|
+
```javascript
|
|
93
|
+
{
|
|
94
|
+
xsrfCookieName: CSRF_COOKIE_NAME,
|
|
95
|
+
xsrfHeaderName: 'X-CSRF-Token',
|
|
96
|
+
headers: { 'X-Requested-With': 'XMLHttpRequest' },
|
|
97
|
+
withCredentials: true,
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
При необходимости можно расширить или переопределить конфиг для `FoxfordService.foxApi`
|
|
101
|
+
|
|
102
|
+
___
|
|
74
103
|
|
|
75
|
-
const camelizeRequestPlugin: CamelizeRequestPlugin = new CamelizeRequestPlugin()
|
|
76
104
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
105
|
+
### Пример использования апи из `FoxfordService`
|
|
106
|
+
```javascript
|
|
107
|
+
import { Foxford } from '@foxford/foxford-js-sdk'
|
|
108
|
+
|
|
109
|
+
const myHost = 'exampleHost'
|
|
110
|
+
const FoxfordService = new Foxford({
|
|
111
|
+
api: {
|
|
112
|
+
config: {
|
|
113
|
+
baseURL: myHost,
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
host: myHost, // легаси, на работу апи не влияет, есть "на всякий случай",
|
|
117
|
+
recaptchaConfig: {
|
|
118
|
+
locale: 'ru',
|
|
119
|
+
sitekey: 'captchaSecretKey',
|
|
120
|
+
}
|
|
80
121
|
})
|
|
122
|
+
|
|
123
|
+
const getInternalData = () => {
|
|
124
|
+
FoxfordService.foxApi.get(`/some-internal-url-protected-with-captcha`).then(({ data }) => data)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const getExternalData = () => {
|
|
128
|
+
FoxfordService.api.get(`https://some.external.source`).then(({ data }) => data)
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Пример использования апи в `stoege`
|
|
133
|
+
|
|
134
|
+
```js static
|
|
135
|
+
import { Api, BaseApi } from 'services/api'
|
|
136
|
+
|
|
137
|
+
const getInternalData = () => {
|
|
138
|
+
Api.get(`/some-internal-url-protected-with-captcha`).then(({ data }) => data)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const getExternalData = () => {
|
|
142
|
+
BaseApi.get(`https://some.external.source`).then(({ data }) => data)
|
|
143
|
+
}
|
|
81
144
|
```
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
function getDefaultExportFromCjs (x) {
|
|
6
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
exports.getDefaultExportFromCjs = getDefaultExportFromCjs;
|
package/api/index.js
CHANGED
|
@@ -1 +1,52 @@
|
|
|
1
|
-
'use strict';
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var index$2 = require('./../dependencies/axios/index.js');
|
|
6
|
+
var index$3 = require('./../dependencies/axios-retry/index.js');
|
|
7
|
+
var request = require('./interceptors/request.js');
|
|
8
|
+
var response = require('./interceptors/response.js');
|
|
9
|
+
var responseFail = require('./interceptors/responseFail.js');
|
|
10
|
+
|
|
11
|
+
class ApiService {
|
|
12
|
+
createFoxApiInstance(_ref) {
|
|
13
|
+
var {
|
|
14
|
+
config,
|
|
15
|
+
plugins = []
|
|
16
|
+
} = _ref;
|
|
17
|
+
var apiInstance = index$2.create(config);
|
|
18
|
+
var requestPlugins = this.filterPlugins(plugins, 'request');
|
|
19
|
+
var responseSuccessPlugins = this.filterPlugins(plugins, 'responseSuccess');
|
|
20
|
+
apiInstance.interceptors.request.use(config => {
|
|
21
|
+
return request.RequestInterceptor(config, apiInstance, [...requestPlugins]);
|
|
22
|
+
});
|
|
23
|
+
apiInstance.interceptors.response.use(response$1 => {
|
|
24
|
+
return response.ResponseInterceptorSuccess(response$1, apiInstance, [...responseSuccessPlugins]);
|
|
25
|
+
}, responseFail.ResponseInterceptorFail);
|
|
26
|
+
index$3(apiInstance, {
|
|
27
|
+
retries: 3,
|
|
28
|
+
retryDelay: index$3.exponentialDelay
|
|
29
|
+
});
|
|
30
|
+
return apiInstance;
|
|
31
|
+
}
|
|
32
|
+
createApiInstance(_ref2) {
|
|
33
|
+
var {
|
|
34
|
+
config
|
|
35
|
+
} = _ref2;
|
|
36
|
+
return index$2.create(config);
|
|
37
|
+
}
|
|
38
|
+
createStaticApiInstance() {
|
|
39
|
+
var staticApiInstance = index$2;
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
|
+
staticApiInstance.isApiError = payload => {
|
|
42
|
+
return typeof payload === 'object' && payload.isAxiosError === true;
|
|
43
|
+
};
|
|
44
|
+
return staticApiInstance;
|
|
45
|
+
}
|
|
46
|
+
filterPlugins(plugins, pluginType) {
|
|
47
|
+
return plugins ? plugins.filter(plugin => plugin.pluginType === pluginType) : [];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
var apiServiceInstance = new ApiService();
|
|
51
|
+
|
|
52
|
+
exports.ApiService = apiServiceInstance;
|
package/api/index.mjs
CHANGED
|
@@ -1 +1,48 @@
|
|
|
1
|
-
import
|
|
1
|
+
import axios from './../dependencies/axios/index.mjs';
|
|
2
|
+
import axiosRetry from './../dependencies/axios-retry/index.mjs';
|
|
3
|
+
import { RequestInterceptor } from './interceptors/request.mjs';
|
|
4
|
+
import { ResponseInterceptorSuccess } from './interceptors/response.mjs';
|
|
5
|
+
import { ResponseInterceptorFail } from './interceptors/responseFail.mjs';
|
|
6
|
+
|
|
7
|
+
class ApiService {
|
|
8
|
+
createFoxApiInstance(_ref) {
|
|
9
|
+
var {
|
|
10
|
+
config,
|
|
11
|
+
plugins = []
|
|
12
|
+
} = _ref;
|
|
13
|
+
var apiInstance = axios.create(config);
|
|
14
|
+
var requestPlugins = this.filterPlugins(plugins, 'request');
|
|
15
|
+
var responseSuccessPlugins = this.filterPlugins(plugins, 'responseSuccess');
|
|
16
|
+
apiInstance.interceptors.request.use(config => {
|
|
17
|
+
return RequestInterceptor(config, apiInstance, [...requestPlugins]);
|
|
18
|
+
});
|
|
19
|
+
apiInstance.interceptors.response.use(response => {
|
|
20
|
+
return ResponseInterceptorSuccess(response, apiInstance, [...responseSuccessPlugins]);
|
|
21
|
+
}, ResponseInterceptorFail);
|
|
22
|
+
axiosRetry(apiInstance, {
|
|
23
|
+
retries: 3,
|
|
24
|
+
retryDelay: axiosRetry.exponentialDelay
|
|
25
|
+
});
|
|
26
|
+
return apiInstance;
|
|
27
|
+
}
|
|
28
|
+
createApiInstance(_ref2) {
|
|
29
|
+
var {
|
|
30
|
+
config
|
|
31
|
+
} = _ref2;
|
|
32
|
+
return axios.create(config);
|
|
33
|
+
}
|
|
34
|
+
createStaticApiInstance() {
|
|
35
|
+
var staticApiInstance = axios;
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
+
staticApiInstance.isApiError = payload => {
|
|
38
|
+
return typeof payload === 'object' && payload.isAxiosError === true;
|
|
39
|
+
};
|
|
40
|
+
return staticApiInstance;
|
|
41
|
+
}
|
|
42
|
+
filterPlugins(plugins, pluginType) {
|
|
43
|
+
return plugins ? plugins.filter(plugin => plugin.pluginType === pluginType) : [];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
var apiServiceInstance = new ApiService();
|
|
47
|
+
|
|
48
|
+
export { apiServiceInstance as ApiService };
|
|
@@ -1 +1,49 @@
|
|
|
1
|
-
'use strict';
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var objectSpread2 = require('./../../dependencies/@babel/runtime/helpers/esm/objectSpread2.js');
|
|
6
|
+
var asyncToGenerator = require('./../../dependencies/@babel/runtime/helpers/esm/asyncToGenerator.js');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Функция для последовательного вызова асихронных плагинов
|
|
10
|
+
* @param {ApiRequestConfigExtended} config
|
|
11
|
+
* @param {ApiInstance} instance
|
|
12
|
+
* @param {AbstractApiRequestPluginInterface[]} plugins
|
|
13
|
+
* @return {Promise<ApiRequestConfigExtended>>}
|
|
14
|
+
*/
|
|
15
|
+
function applyPlugins(_x, _x2, _x3) {
|
|
16
|
+
return _applyPlugins.apply(this, arguments);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Перехватчик на выполнение запроса
|
|
20
|
+
* @param {ApiRequestConfigExtended} config
|
|
21
|
+
* @param {ApiInstance} instance
|
|
22
|
+
* @param {AbstractApiRequestPluginInterface[]} plugins
|
|
23
|
+
*/
|
|
24
|
+
function _applyPlugins() {
|
|
25
|
+
_applyPlugins = asyncToGenerator(function* (config, instance, plugins) {
|
|
26
|
+
for (var plugin of plugins) {
|
|
27
|
+
if (!plugin.isApplicable(config)) continue;
|
|
28
|
+
config = yield plugin.execute(config, instance);
|
|
29
|
+
}
|
|
30
|
+
return config;
|
|
31
|
+
});
|
|
32
|
+
return _applyPlugins.apply(this, arguments);
|
|
33
|
+
}
|
|
34
|
+
function RequestInterceptor(config, instance, plugins) {
|
|
35
|
+
config.headers = objectSpread2({
|
|
36
|
+
'Content-Type': 'application/json'
|
|
37
|
+
}, config.headers);
|
|
38
|
+
if (window && window.location && window.location.pathname && window.location.origin) {
|
|
39
|
+
config.headers = objectSpread2(objectSpread2({}, config.headers), {}, {
|
|
40
|
+
'X-Referer': window.location.origin + window.location.pathname
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
if (plugins.length > 0) {
|
|
44
|
+
return applyPlugins(config, instance, plugins);
|
|
45
|
+
}
|
|
46
|
+
return config;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
exports.RequestInterceptor = RequestInterceptor;
|
|
@@ -1 +1,45 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _objectSpread2 from './../../dependencies/@babel/runtime/helpers/esm/objectSpread2.mjs';
|
|
2
|
+
import _asyncToGenerator from './../../dependencies/@babel/runtime/helpers/esm/asyncToGenerator.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Функция для последовательного вызова асихронных плагинов
|
|
6
|
+
* @param {ApiRequestConfigExtended} config
|
|
7
|
+
* @param {ApiInstance} instance
|
|
8
|
+
* @param {AbstractApiRequestPluginInterface[]} plugins
|
|
9
|
+
* @return {Promise<ApiRequestConfigExtended>>}
|
|
10
|
+
*/
|
|
11
|
+
function applyPlugins(_x, _x2, _x3) {
|
|
12
|
+
return _applyPlugins.apply(this, arguments);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Перехватчик на выполнение запроса
|
|
16
|
+
* @param {ApiRequestConfigExtended} config
|
|
17
|
+
* @param {ApiInstance} instance
|
|
18
|
+
* @param {AbstractApiRequestPluginInterface[]} plugins
|
|
19
|
+
*/
|
|
20
|
+
function _applyPlugins() {
|
|
21
|
+
_applyPlugins = _asyncToGenerator(function* (config, instance, plugins) {
|
|
22
|
+
for (var plugin of plugins) {
|
|
23
|
+
if (!plugin.isApplicable(config)) continue;
|
|
24
|
+
config = yield plugin.execute(config, instance);
|
|
25
|
+
}
|
|
26
|
+
return config;
|
|
27
|
+
});
|
|
28
|
+
return _applyPlugins.apply(this, arguments);
|
|
29
|
+
}
|
|
30
|
+
function RequestInterceptor(config, instance, plugins) {
|
|
31
|
+
config.headers = _objectSpread2({
|
|
32
|
+
'Content-Type': 'application/json'
|
|
33
|
+
}, config.headers);
|
|
34
|
+
if (window && window.location && window.location.pathname && window.location.origin) {
|
|
35
|
+
config.headers = _objectSpread2(_objectSpread2({}, config.headers), {}, {
|
|
36
|
+
'X-Referer': window.location.origin + window.location.pathname
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
if (plugins.length > 0) {
|
|
40
|
+
return applyPlugins(config, instance, plugins);
|
|
41
|
+
}
|
|
42
|
+
return config;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { RequestInterceptor };
|
|
@@ -1 +1,40 @@
|
|
|
1
|
-
'use strict';
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var asyncToGenerator = require('./../../dependencies/@babel/runtime/helpers/esm/asyncToGenerator.js');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Функция для последовательного вызова асихронных плагинов
|
|
9
|
+
* @param {ApiResponse} response
|
|
10
|
+
* @param {ApiInstance} instance
|
|
11
|
+
* @param {ResponseSuccessPluginInterface[]} plugins
|
|
12
|
+
* @return {Promise<ApiResponse>>}
|
|
13
|
+
*/
|
|
14
|
+
function applyPlugins(_x, _x2, _x3) {
|
|
15
|
+
return _applyPlugins.apply(this, arguments);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Перехватчик успешного выполнения запроса
|
|
19
|
+
* @param {ApiResponse} response
|
|
20
|
+
* @param {ApiInstance} instance
|
|
21
|
+
* @param {ResponseSuccessPluginInterface[]} plugins
|
|
22
|
+
*/
|
|
23
|
+
function _applyPlugins() {
|
|
24
|
+
_applyPlugins = asyncToGenerator(function* (response, instance, plugins) {
|
|
25
|
+
for (var plugin of plugins) {
|
|
26
|
+
if (!plugin.isApplicable(response)) continue;
|
|
27
|
+
response = yield plugin.execute(response, instance);
|
|
28
|
+
}
|
|
29
|
+
return response;
|
|
30
|
+
});
|
|
31
|
+
return _applyPlugins.apply(this, arguments);
|
|
32
|
+
}
|
|
33
|
+
function ResponseInterceptorSuccess(response, instance, plugins) {
|
|
34
|
+
if (plugins.length > 0) {
|
|
35
|
+
return applyPlugins(response, instance, plugins);
|
|
36
|
+
}
|
|
37
|
+
return response;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
exports.ResponseInterceptorSuccess = ResponseInterceptorSuccess;
|
|
@@ -1 +1,36 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _asyncToGenerator from './../../dependencies/@babel/runtime/helpers/esm/asyncToGenerator.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Функция для последовательного вызова асихронных плагинов
|
|
5
|
+
* @param {ApiResponse} response
|
|
6
|
+
* @param {ApiInstance} instance
|
|
7
|
+
* @param {ResponseSuccessPluginInterface[]} plugins
|
|
8
|
+
* @return {Promise<ApiResponse>>}
|
|
9
|
+
*/
|
|
10
|
+
function applyPlugins(_x, _x2, _x3) {
|
|
11
|
+
return _applyPlugins.apply(this, arguments);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Перехватчик успешного выполнения запроса
|
|
15
|
+
* @param {ApiResponse} response
|
|
16
|
+
* @param {ApiInstance} instance
|
|
17
|
+
* @param {ResponseSuccessPluginInterface[]} plugins
|
|
18
|
+
*/
|
|
19
|
+
function _applyPlugins() {
|
|
20
|
+
_applyPlugins = _asyncToGenerator(function* (response, instance, plugins) {
|
|
21
|
+
for (var plugin of plugins) {
|
|
22
|
+
if (!plugin.isApplicable(response)) continue;
|
|
23
|
+
response = yield plugin.execute(response, instance);
|
|
24
|
+
}
|
|
25
|
+
return response;
|
|
26
|
+
});
|
|
27
|
+
return _applyPlugins.apply(this, arguments);
|
|
28
|
+
}
|
|
29
|
+
function ResponseInterceptorSuccess(response, instance, plugins) {
|
|
30
|
+
if (plugins.length > 0) {
|
|
31
|
+
return applyPlugins(response, instance, plugins);
|
|
32
|
+
}
|
|
33
|
+
return response;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { ResponseInterceptorSuccess };
|
|
@@ -1 +1,37 @@
|
|
|
1
|
-
'use strict';
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var objectSpread2 = require('./../../dependencies/@babel/runtime/helpers/esm/objectSpread2.js');
|
|
6
|
+
|
|
7
|
+
var IGNORE_RETRY_STATUSES = [422, 401];
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Перехватчик отвалившегося запроса
|
|
11
|
+
* @param {ApiErrorExtended} error
|
|
12
|
+
*/
|
|
13
|
+
function ResponseInterceptorFail(error) {
|
|
14
|
+
var {
|
|
15
|
+
config = null,
|
|
16
|
+
response = null
|
|
17
|
+
} = error;
|
|
18
|
+
if (config === null || response === null) {
|
|
19
|
+
// Необходимо для любых внутренних ошибок axios (к примеру Cancel)
|
|
20
|
+
return Promise.reject(error);
|
|
21
|
+
}
|
|
22
|
+
var originalRequest = config;
|
|
23
|
+
if (IGNORE_RETRY_STATUSES.includes(response.status)) {
|
|
24
|
+
originalRequest._retry = true;
|
|
25
|
+
}
|
|
26
|
+
var rejectData = objectSpread2({
|
|
27
|
+
errorText: error.toString(),
|
|
28
|
+
headers: response.headers,
|
|
29
|
+
status: response.status,
|
|
30
|
+
statusText: response.statusText
|
|
31
|
+
}, typeof response.data === 'object' ? response.data : {
|
|
32
|
+
data: response.data
|
|
33
|
+
});
|
|
34
|
+
return Promise.reject(rejectData);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
exports.ResponseInterceptorFail = ResponseInterceptorFail;
|
|
@@ -1 +1,33 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _objectSpread2 from './../../dependencies/@babel/runtime/helpers/esm/objectSpread2.mjs';
|
|
2
|
+
|
|
3
|
+
var IGNORE_RETRY_STATUSES = [422, 401];
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Перехватчик отвалившегося запроса
|
|
7
|
+
* @param {ApiErrorExtended} error
|
|
8
|
+
*/
|
|
9
|
+
function ResponseInterceptorFail(error) {
|
|
10
|
+
var {
|
|
11
|
+
config = null,
|
|
12
|
+
response = null
|
|
13
|
+
} = error;
|
|
14
|
+
if (config === null || response === null) {
|
|
15
|
+
// Необходимо для любых внутренних ошибок axios (к примеру Cancel)
|
|
16
|
+
return Promise.reject(error);
|
|
17
|
+
}
|
|
18
|
+
var originalRequest = config;
|
|
19
|
+
if (IGNORE_RETRY_STATUSES.includes(response.status)) {
|
|
20
|
+
originalRequest._retry = true;
|
|
21
|
+
}
|
|
22
|
+
var rejectData = _objectSpread2({
|
|
23
|
+
errorText: error.toString(),
|
|
24
|
+
headers: response.headers,
|
|
25
|
+
status: response.status,
|
|
26
|
+
statusText: response.statusText
|
|
27
|
+
}, typeof response.data === 'object' ? response.data : {
|
|
28
|
+
data: response.data
|
|
29
|
+
});
|
|
30
|
+
return Promise.reject(rejectData);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { ResponseInterceptorFail };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
class ResponseSuccessPlugin {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.pluginType = 'responseSuccess';
|
|
8
|
+
this.pluginName = void 0;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
exports.ResponseSuccessPlugin = ResponseSuccessPlugin;
|