@tramvai/module-common 2.70.0 → 2.72.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/lib/CommonModule.browser.js +100 -0
- package/lib/CommonModule.es.js +100 -0
- package/lib/CommonModule.js +106 -0
- package/lib/actions/ActionModule.browser.js +79 -0
- package/lib/actions/ActionModule.es.js +79 -0
- package/lib/actions/ActionModule.js +82 -0
- package/lib/actions/actionChecker.browser.js +52 -0
- package/lib/actions/actionChecker.es.js +52 -0
- package/lib/actions/actionChecker.js +56 -0
- package/lib/actions/actionExecution.browser.js +107 -0
- package/lib/actions/actionExecution.es.js +107 -0
- package/lib/actions/actionExecution.js +118 -0
- package/lib/actions/actionPageRunner.browser.browser.js +33 -0
- package/lib/actions/actionPageRunner.es.js +61 -0
- package/lib/actions/actionPageRunner.js +65 -0
- package/lib/actions/actionRegistry.browser.js +33 -0
- package/lib/actions/actionRegistry.es.js +33 -0
- package/lib/actions/actionRegistry.js +45 -0
- package/lib/actions/actionTramvaiReducer.browser.js +10 -0
- package/lib/actions/actionTramvaiReducer.es.js +10 -0
- package/lib/actions/actionTramvaiReducer.js +15 -0
- package/lib/actions/conditions/always.browser.js +10 -0
- package/lib/actions/conditions/always.es.js +10 -0
- package/lib/actions/conditions/always.js +14 -0
- package/lib/actions/conditions/helpers.browser.js +4 -0
- package/lib/actions/conditions/helpers.es.js +4 -0
- package/lib/actions/conditions/helpers.js +9 -0
- package/lib/actions/conditions/onlyBrowser.browser.js +12 -0
- package/lib/actions/conditions/onlyBrowser.es.js +12 -0
- package/lib/actions/conditions/onlyBrowser.js +16 -0
- package/lib/actions/conditions/onlyServer.browser.js +12 -0
- package/lib/actions/conditions/onlyServer.es.js +12 -0
- package/lib/actions/conditions/onlyServer.js +16 -0
- package/lib/actions/conditions/pageBrowser.browser.js +13 -0
- package/lib/actions/conditions/pageBrowser.es.js +13 -0
- package/lib/actions/conditions/pageBrowser.js +17 -0
- package/lib/actions/conditions/pageServer.browser.js +13 -0
- package/lib/actions/conditions/pageServer.es.js +13 -0
- package/lib/actions/conditions/pageServer.js +17 -0
- package/lib/actions/constants.browser.js +9 -0
- package/lib/actions/constants.es.js +9 -0
- package/lib/actions/constants.js +13 -0
- package/lib/bundleManager/bundleManager.browser.js +105 -0
- package/lib/bundleManager/bundleManager.es.js +105 -0
- package/lib/bundleManager/bundleManager.js +115 -0
- package/lib/cache/CacheModule.browser.js +58 -0
- package/lib/cache/CacheModule.es.js +58 -0
- package/lib/cache/CacheModule.js +62 -0
- package/lib/cache/cacheFactory.browser.js +7 -0
- package/lib/cache/cacheFactory.es.js +7 -0
- package/lib/cache/cacheFactory.js +15 -0
- package/lib/cache/clientProviders.browser.js +3 -0
- package/lib/cache/papi.es.js +18 -0
- package/lib/cache/papi.js +22 -0
- package/lib/cache/serverProviders.es.js +18 -0
- package/lib/cache/serverProviders.js +22 -0
- package/lib/child-app/ChildAppModule.browser.js +38 -0
- package/lib/child-app/ChildAppModule.es.js +38 -0
- package/lib/child-app/ChildAppModule.js +40 -0
- package/lib/child-app/actions.browser.js +19 -0
- package/lib/child-app/actions.es.js +19 -0
- package/lib/child-app/actions.js +23 -0
- package/lib/child-app/clientProviders.browser.js +18 -0
- package/lib/child-app/command.browser.js +35 -0
- package/lib/child-app/command.es.js +35 -0
- package/lib/child-app/command.js +40 -0
- package/lib/child-app/serverProviders.es.js +3 -0
- package/lib/child-app/serverProviders.js +7 -0
- package/lib/child-app/state.browser.js +13 -0
- package/lib/child-app/state.es.js +13 -0
- package/lib/child-app/state.js +17 -0
- package/lib/command/CommandModule.browser.js +52 -0
- package/lib/command/CommandModule.es.js +52 -0
- package/lib/command/CommandModule.js +54 -0
- package/lib/command/commandLineRunner.browser.js +147 -0
- package/lib/command/commandLineRunner.es.js +147 -0
- package/lib/command/commandLineRunner.js +151 -0
- package/lib/command/defaultLines.browser.js +25 -0
- package/lib/command/defaultLines.es.js +25 -0
- package/lib/command/defaultLines.js +29 -0
- package/lib/componentRegistry/componentRegistry.browser.js +25 -0
- package/lib/componentRegistry/componentRegistry.es.js +25 -0
- package/lib/componentRegistry/componentRegistry.js +34 -0
- package/lib/createConsumerContext/createConsumerContext.browser.js +62 -0
- package/lib/createConsumerContext/createConsumerContext.es.js +62 -0
- package/lib/createConsumerContext/createConsumerContext.js +67 -0
- package/lib/executionContext/executionContextManager.browser.js +57 -0
- package/lib/executionContext/executionContextManager.es.js +57 -0
- package/lib/executionContext/executionContextManager.js +61 -0
- package/lib/index.browser.js +13 -1300
- package/lib/index.es.js +13 -1318
- package/lib/index.js +38 -1341
- package/lib/providers/clientProviders.browser.js +22 -0
- package/lib/providers/serverProviders.es.js +3 -0
- package/lib/providers/serverProviders.js +7 -0
- package/lib/pubsub/PubSubModule.browser.js +44 -0
- package/lib/pubsub/PubSubModule.es.js +44 -0
- package/lib/pubsub/PubSubModule.js +46 -0
- package/lib/requestManager/RequestManagerModule.browser.browser.js +38 -0
- package/lib/requestManager/RequestManagerModule.es.js +35 -0
- package/lib/requestManager/RequestManagerModule.js +37 -0
- package/lib/requestManager/RequestManagerStore.browser.js +8 -0
- package/lib/requestManager/RequestManagerStore.es.js +8 -0
- package/lib/requestManager/RequestManagerStore.js +13 -0
- package/lib/requestManager/requestManager.browser.js +57 -0
- package/lib/requestManager/requestManager.es.js +57 -0
- package/lib/requestManager/requestManager.js +61 -0
- package/lib/requestManager/sharedProviders.browser.js +23 -0
- package/lib/requestManager/sharedProviders.es.js +23 -0
- package/lib/requestManager/sharedProviders.js +27 -0
- package/lib/responseManager/ResponseManagerModule.browser.browser.js +21 -0
- package/lib/responseManager/ResponseManagerModule.es.js +13 -0
- package/lib/responseManager/ResponseManagerModule.js +15 -0
- package/lib/responseManager/responseManager.browser.js +52 -0
- package/lib/responseManager/responseManager.es.js +52 -0
- package/lib/responseManager/responseManager.js +61 -0
- package/lib/responseManager/sharedProviders.browser.js +13 -0
- package/lib/responseManager/sharedProviders.es.js +13 -0
- package/lib/responseManager/sharedProviders.js +17 -0
- package/lib/state/StateModule.browser.js +54 -0
- package/lib/state/StateModule.es.js +54 -0
- package/lib/state/StateModule.js +60 -0
- package/package.json +24 -25
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { provide, Scope, commandLineListTokens, COMMAND_LINE_RUNNER_TOKEN } from '@tramvai/core';
|
|
2
|
+
import { INITIAL_APP_STATE_TOKEN } from '@tramvai/tokens-common';
|
|
3
|
+
|
|
4
|
+
const providers = [
|
|
5
|
+
provide({
|
|
6
|
+
provide: INITIAL_APP_STATE_TOKEN,
|
|
7
|
+
useFactory: () => { var _a, _b; return JSON.parse((_b = (_a = document.getElementById('__TRAMVAI_STATE__')) === null || _a === void 0 ? void 0 : _a.textContent) !== null && _b !== void 0 ? _b : '{}'); },
|
|
8
|
+
scope: Scope.REQUEST,
|
|
9
|
+
}),
|
|
10
|
+
provide({
|
|
11
|
+
provide: commandLineListTokens.listen,
|
|
12
|
+
useFactory: ({ commandLineRunner, }) => {
|
|
13
|
+
return function initClientCommand() {
|
|
14
|
+
return commandLineRunner.run('client', 'customer');
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
deps: { commandLineRunner: COMMAND_LINE_RUNNER_TOKEN },
|
|
18
|
+
multi: true,
|
|
19
|
+
}),
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
export { providers };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { __decorate } from 'tslib';
|
|
2
|
+
import { Module, provide, Scope } from '@tramvai/core';
|
|
3
|
+
import { PubSub } from '@tinkoff/pubsub';
|
|
4
|
+
import { PUBSUB_FACTORY_TOKEN, LOGGER_TOKEN, PUBSUB_TOKEN, ROOT_PUBSUB_TOKEN } from '@tramvai/tokens-common';
|
|
5
|
+
|
|
6
|
+
let PubSubModule = class PubSubModule {
|
|
7
|
+
};
|
|
8
|
+
PubSubModule = __decorate([
|
|
9
|
+
Module({
|
|
10
|
+
providers: [
|
|
11
|
+
provide({
|
|
12
|
+
// Фабрика для создания pubsub
|
|
13
|
+
provide: PUBSUB_FACTORY_TOKEN,
|
|
14
|
+
scope: Scope.SINGLETON,
|
|
15
|
+
useFactory: (deps) => () => {
|
|
16
|
+
return new PubSub({
|
|
17
|
+
logger: deps.logger('pubsub'),
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
deps: {
|
|
21
|
+
logger: LOGGER_TOKEN,
|
|
22
|
+
},
|
|
23
|
+
}),
|
|
24
|
+
provide({
|
|
25
|
+
provide: PUBSUB_TOKEN,
|
|
26
|
+
scope: Scope.REQUEST,
|
|
27
|
+
useFactory: ({ createPubsub }) => createPubsub(),
|
|
28
|
+
deps: {
|
|
29
|
+
createPubsub: PUBSUB_FACTORY_TOKEN,
|
|
30
|
+
},
|
|
31
|
+
}),
|
|
32
|
+
provide({
|
|
33
|
+
provide: ROOT_PUBSUB_TOKEN,
|
|
34
|
+
scope: Scope.SINGLETON,
|
|
35
|
+
useFactory: ({ createPubsub }) => createPubsub(),
|
|
36
|
+
deps: {
|
|
37
|
+
createPubsub: PUBSUB_FACTORY_TOKEN,
|
|
38
|
+
},
|
|
39
|
+
}),
|
|
40
|
+
],
|
|
41
|
+
})
|
|
42
|
+
], PubSubModule);
|
|
43
|
+
|
|
44
|
+
export { PubSubModule };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { __decorate } from 'tslib';
|
|
2
|
+
import { Module, provide, Scope } from '@tramvai/core';
|
|
3
|
+
import { PubSub } from '@tinkoff/pubsub';
|
|
4
|
+
import { PUBSUB_FACTORY_TOKEN, LOGGER_TOKEN, PUBSUB_TOKEN, ROOT_PUBSUB_TOKEN } from '@tramvai/tokens-common';
|
|
5
|
+
|
|
6
|
+
let PubSubModule = class PubSubModule {
|
|
7
|
+
};
|
|
8
|
+
PubSubModule = __decorate([
|
|
9
|
+
Module({
|
|
10
|
+
providers: [
|
|
11
|
+
provide({
|
|
12
|
+
// Фабрика для создания pubsub
|
|
13
|
+
provide: PUBSUB_FACTORY_TOKEN,
|
|
14
|
+
scope: Scope.SINGLETON,
|
|
15
|
+
useFactory: (deps) => () => {
|
|
16
|
+
return new PubSub({
|
|
17
|
+
logger: deps.logger('pubsub'),
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
deps: {
|
|
21
|
+
logger: LOGGER_TOKEN,
|
|
22
|
+
},
|
|
23
|
+
}),
|
|
24
|
+
provide({
|
|
25
|
+
provide: PUBSUB_TOKEN,
|
|
26
|
+
scope: Scope.REQUEST,
|
|
27
|
+
useFactory: ({ createPubsub }) => createPubsub(),
|
|
28
|
+
deps: {
|
|
29
|
+
createPubsub: PUBSUB_FACTORY_TOKEN,
|
|
30
|
+
},
|
|
31
|
+
}),
|
|
32
|
+
provide({
|
|
33
|
+
provide: ROOT_PUBSUB_TOKEN,
|
|
34
|
+
scope: Scope.SINGLETON,
|
|
35
|
+
useFactory: ({ createPubsub }) => createPubsub(),
|
|
36
|
+
deps: {
|
|
37
|
+
createPubsub: PUBSUB_FACTORY_TOKEN,
|
|
38
|
+
},
|
|
39
|
+
}),
|
|
40
|
+
],
|
|
41
|
+
})
|
|
42
|
+
], PubSubModule);
|
|
43
|
+
|
|
44
|
+
export { PubSubModule };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var tslib = require('tslib');
|
|
6
|
+
var core = require('@tramvai/core');
|
|
7
|
+
var pubsub = require('@tinkoff/pubsub');
|
|
8
|
+
var tokensCommon = require('@tramvai/tokens-common');
|
|
9
|
+
|
|
10
|
+
exports.PubSubModule = class PubSubModule {
|
|
11
|
+
};
|
|
12
|
+
exports.PubSubModule = tslib.__decorate([
|
|
13
|
+
core.Module({
|
|
14
|
+
providers: [
|
|
15
|
+
core.provide({
|
|
16
|
+
// Фабрика для создания pubsub
|
|
17
|
+
provide: tokensCommon.PUBSUB_FACTORY_TOKEN,
|
|
18
|
+
scope: core.Scope.SINGLETON,
|
|
19
|
+
useFactory: (deps) => () => {
|
|
20
|
+
return new pubsub.PubSub({
|
|
21
|
+
logger: deps.logger('pubsub'),
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
deps: {
|
|
25
|
+
logger: tokensCommon.LOGGER_TOKEN,
|
|
26
|
+
},
|
|
27
|
+
}),
|
|
28
|
+
core.provide({
|
|
29
|
+
provide: tokensCommon.PUBSUB_TOKEN,
|
|
30
|
+
scope: core.Scope.REQUEST,
|
|
31
|
+
useFactory: ({ createPubsub }) => createPubsub(),
|
|
32
|
+
deps: {
|
|
33
|
+
createPubsub: tokensCommon.PUBSUB_FACTORY_TOKEN,
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
core.provide({
|
|
37
|
+
provide: tokensCommon.ROOT_PUBSUB_TOKEN,
|
|
38
|
+
scope: core.Scope.SINGLETON,
|
|
39
|
+
useFactory: ({ createPubsub }) => createPubsub(),
|
|
40
|
+
deps: {
|
|
41
|
+
createPubsub: tokensCommon.PUBSUB_FACTORY_TOKEN,
|
|
42
|
+
},
|
|
43
|
+
}),
|
|
44
|
+
],
|
|
45
|
+
})
|
|
46
|
+
], exports.PubSubModule);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { __decorate } from 'tslib';
|
|
2
|
+
import { Module, provide } from '@tramvai/core';
|
|
3
|
+
import { STORE_TOKEN } from '@tramvai/tokens-common';
|
|
4
|
+
import { FASTIFY_REQUEST } from '@tramvai/tokens-server-private';
|
|
5
|
+
import { RequestManagerStore } from './RequestManagerStore.browser.js';
|
|
6
|
+
import { sharedProviders } from './sharedProviders.browser.js';
|
|
7
|
+
|
|
8
|
+
let RequestManagerModule = class RequestManagerModule {
|
|
9
|
+
};
|
|
10
|
+
RequestManagerModule = __decorate([
|
|
11
|
+
Module({
|
|
12
|
+
providers: [
|
|
13
|
+
...sharedProviders,
|
|
14
|
+
provide({
|
|
15
|
+
provide: FASTIFY_REQUEST,
|
|
16
|
+
useFactory: ({ store }) => {
|
|
17
|
+
const fromServer = store.getState(RequestManagerStore);
|
|
18
|
+
return {
|
|
19
|
+
...fromServer,
|
|
20
|
+
headers: {
|
|
21
|
+
...fromServer === null || fromServer === void 0 ? void 0 : fromServer.headers,
|
|
22
|
+
'user-agent': navigator.userAgent,
|
|
23
|
+
cookie: document.cookie,
|
|
24
|
+
},
|
|
25
|
+
// the type is not actually the same and is only partially compatible with actual request object
|
|
26
|
+
// but provide it as a backup for some of the isomorphic code
|
|
27
|
+
// anyway it is better not to use request/response on client
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
deps: {
|
|
31
|
+
store: STORE_TOKEN,
|
|
32
|
+
},
|
|
33
|
+
}),
|
|
34
|
+
],
|
|
35
|
+
})
|
|
36
|
+
], RequestManagerModule);
|
|
37
|
+
|
|
38
|
+
export { RequestManagerModule };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { __decorate } from 'tslib';
|
|
2
|
+
import { Module, provide, commandLineListTokens } from '@tramvai/core';
|
|
3
|
+
import { CONTEXT_TOKEN, REQUEST_MANAGER_TOKEN } from '@tramvai/tokens-common';
|
|
4
|
+
import { setRequest } from './RequestManagerStore.es.js';
|
|
5
|
+
import { sharedProviders } from './sharedProviders.es.js';
|
|
6
|
+
|
|
7
|
+
let RequestManagerModule = class RequestManagerModule {
|
|
8
|
+
};
|
|
9
|
+
RequestManagerModule = __decorate([
|
|
10
|
+
Module({
|
|
11
|
+
providers: [
|
|
12
|
+
...sharedProviders,
|
|
13
|
+
provide({
|
|
14
|
+
provide: commandLineListTokens.customerStart,
|
|
15
|
+
multi: true,
|
|
16
|
+
useFactory: ({ context, requestManager }) => {
|
|
17
|
+
return function dehydrateRequestManager() {
|
|
18
|
+
return context.dispatch(setRequest({
|
|
19
|
+
body: requestManager.getBody(),
|
|
20
|
+
headers: {
|
|
21
|
+
'x-real-ip': requestManager.getClientIp(),
|
|
22
|
+
},
|
|
23
|
+
}));
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
deps: {
|
|
27
|
+
context: CONTEXT_TOKEN,
|
|
28
|
+
requestManager: REQUEST_MANAGER_TOKEN,
|
|
29
|
+
},
|
|
30
|
+
}),
|
|
31
|
+
],
|
|
32
|
+
})
|
|
33
|
+
], RequestManagerModule);
|
|
34
|
+
|
|
35
|
+
export { RequestManagerModule };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var tslib = require('tslib');
|
|
6
|
+
var core = require('@tramvai/core');
|
|
7
|
+
var tokensCommon = require('@tramvai/tokens-common');
|
|
8
|
+
var RequestManagerStore = require('./RequestManagerStore.js');
|
|
9
|
+
var sharedProviders = require('./sharedProviders.js');
|
|
10
|
+
|
|
11
|
+
exports.RequestManagerModule = class RequestManagerModule {
|
|
12
|
+
};
|
|
13
|
+
exports.RequestManagerModule = tslib.__decorate([
|
|
14
|
+
core.Module({
|
|
15
|
+
providers: [
|
|
16
|
+
...sharedProviders.sharedProviders,
|
|
17
|
+
core.provide({
|
|
18
|
+
provide: core.commandLineListTokens.customerStart,
|
|
19
|
+
multi: true,
|
|
20
|
+
useFactory: ({ context, requestManager }) => {
|
|
21
|
+
return function dehydrateRequestManager() {
|
|
22
|
+
return context.dispatch(RequestManagerStore.setRequest({
|
|
23
|
+
body: requestManager.getBody(),
|
|
24
|
+
headers: {
|
|
25
|
+
'x-real-ip': requestManager.getClientIp(),
|
|
26
|
+
},
|
|
27
|
+
}));
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
deps: {
|
|
31
|
+
context: tokensCommon.CONTEXT_TOKEN,
|
|
32
|
+
requestManager: tokensCommon.REQUEST_MANAGER_TOKEN,
|
|
33
|
+
},
|
|
34
|
+
}),
|
|
35
|
+
],
|
|
36
|
+
})
|
|
37
|
+
], exports.RequestManagerModule);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createEvent, createReducer } from '@tramvai/state';
|
|
2
|
+
|
|
3
|
+
const setRequest = createEvent('setRequest');
|
|
4
|
+
const RequestManagerStore = createReducer('requestManager', {}).on(setRequest, (_, state) => {
|
|
5
|
+
return state;
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export { RequestManagerStore, setRequest };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createEvent, createReducer } from '@tramvai/state';
|
|
2
|
+
|
|
3
|
+
const setRequest = createEvent('setRequest');
|
|
4
|
+
const RequestManagerStore = createReducer('requestManager', {}).on(setRequest, (_, state) => {
|
|
5
|
+
return state;
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export { RequestManagerStore, setRequest };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var state = require('@tramvai/state');
|
|
6
|
+
|
|
7
|
+
const setRequest = state.createEvent('setRequest');
|
|
8
|
+
const RequestManagerStore = state.createReducer('requestManager', {}).on(setRequest, (_, state) => {
|
|
9
|
+
return state;
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
exports.RequestManagerStore = RequestManagerStore;
|
|
13
|
+
exports.setRequest = setRequest;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { format, parse } from '@tinkoff/url';
|
|
2
|
+
|
|
3
|
+
class RequestManager {
|
|
4
|
+
constructor({ request }) {
|
|
5
|
+
this.request = request || {};
|
|
6
|
+
if (typeof window === 'undefined') {
|
|
7
|
+
this.url = format({
|
|
8
|
+
protocol: this.getHeader('x-forwarded-proto') || this.request.protocol,
|
|
9
|
+
host: this.getHost(),
|
|
10
|
+
path: this.request.url,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
this.url = window.location.href;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
getBody() {
|
|
18
|
+
return this.request.body;
|
|
19
|
+
}
|
|
20
|
+
getUrl() {
|
|
21
|
+
return this.url;
|
|
22
|
+
}
|
|
23
|
+
getParsedUrl() {
|
|
24
|
+
if (!this.parsedUrl) {
|
|
25
|
+
this.parsedUrl = parse(this.url);
|
|
26
|
+
}
|
|
27
|
+
return this.parsedUrl;
|
|
28
|
+
}
|
|
29
|
+
getMethod() {
|
|
30
|
+
return this.request.method;
|
|
31
|
+
}
|
|
32
|
+
getHeader(key) {
|
|
33
|
+
var _a;
|
|
34
|
+
return (_a = this.request.headers) === null || _a === void 0 ? void 0 : _a[key];
|
|
35
|
+
}
|
|
36
|
+
getHeaders() {
|
|
37
|
+
return this.request.headers;
|
|
38
|
+
}
|
|
39
|
+
getCookie(key) {
|
|
40
|
+
return this.request.cookies[key];
|
|
41
|
+
}
|
|
42
|
+
getCookies() {
|
|
43
|
+
return this.request.cookies;
|
|
44
|
+
}
|
|
45
|
+
getClientIp() {
|
|
46
|
+
var _a, _b;
|
|
47
|
+
return this.getHeader('x-real-ip') || ((_b = (_a = this.request) === null || _a === void 0 ? void 0 : _a.socket) === null || _b === void 0 ? void 0 : _b.remoteAddress) || '';
|
|
48
|
+
}
|
|
49
|
+
getHost() {
|
|
50
|
+
if (typeof window === 'undefined') {
|
|
51
|
+
return (this.getHeader('x-original-host') || this.getHeader('host'));
|
|
52
|
+
}
|
|
53
|
+
return window.location.host;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { RequestManager };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { format, parse } from '@tinkoff/url';
|
|
2
|
+
|
|
3
|
+
class RequestManager {
|
|
4
|
+
constructor({ request }) {
|
|
5
|
+
this.request = request || {};
|
|
6
|
+
if (typeof window === 'undefined') {
|
|
7
|
+
this.url = format({
|
|
8
|
+
protocol: this.getHeader('x-forwarded-proto') || this.request.protocol,
|
|
9
|
+
host: this.getHost(),
|
|
10
|
+
path: this.request.url,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
this.url = window.location.href;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
getBody() {
|
|
18
|
+
return this.request.body;
|
|
19
|
+
}
|
|
20
|
+
getUrl() {
|
|
21
|
+
return this.url;
|
|
22
|
+
}
|
|
23
|
+
getParsedUrl() {
|
|
24
|
+
if (!this.parsedUrl) {
|
|
25
|
+
this.parsedUrl = parse(this.url);
|
|
26
|
+
}
|
|
27
|
+
return this.parsedUrl;
|
|
28
|
+
}
|
|
29
|
+
getMethod() {
|
|
30
|
+
return this.request.method;
|
|
31
|
+
}
|
|
32
|
+
getHeader(key) {
|
|
33
|
+
var _a;
|
|
34
|
+
return (_a = this.request.headers) === null || _a === void 0 ? void 0 : _a[key];
|
|
35
|
+
}
|
|
36
|
+
getHeaders() {
|
|
37
|
+
return this.request.headers;
|
|
38
|
+
}
|
|
39
|
+
getCookie(key) {
|
|
40
|
+
return this.request.cookies[key];
|
|
41
|
+
}
|
|
42
|
+
getCookies() {
|
|
43
|
+
return this.request.cookies;
|
|
44
|
+
}
|
|
45
|
+
getClientIp() {
|
|
46
|
+
var _a, _b;
|
|
47
|
+
return this.getHeader('x-real-ip') || ((_b = (_a = this.request) === null || _a === void 0 ? void 0 : _a.socket) === null || _b === void 0 ? void 0 : _b.remoteAddress) || '';
|
|
48
|
+
}
|
|
49
|
+
getHost() {
|
|
50
|
+
if (typeof window === 'undefined') {
|
|
51
|
+
return (this.getHeader('x-original-host') || this.getHeader('host'));
|
|
52
|
+
}
|
|
53
|
+
return window.location.host;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { RequestManager };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var url = require('@tinkoff/url');
|
|
6
|
+
|
|
7
|
+
class RequestManager {
|
|
8
|
+
constructor({ request }) {
|
|
9
|
+
this.request = request || {};
|
|
10
|
+
if (typeof window === 'undefined') {
|
|
11
|
+
this.url = url.format({
|
|
12
|
+
protocol: this.getHeader('x-forwarded-proto') || this.request.protocol,
|
|
13
|
+
host: this.getHost(),
|
|
14
|
+
path: this.request.url,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
this.url = window.location.href;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
getBody() {
|
|
22
|
+
return this.request.body;
|
|
23
|
+
}
|
|
24
|
+
getUrl() {
|
|
25
|
+
return this.url;
|
|
26
|
+
}
|
|
27
|
+
getParsedUrl() {
|
|
28
|
+
if (!this.parsedUrl) {
|
|
29
|
+
this.parsedUrl = url.parse(this.url);
|
|
30
|
+
}
|
|
31
|
+
return this.parsedUrl;
|
|
32
|
+
}
|
|
33
|
+
getMethod() {
|
|
34
|
+
return this.request.method;
|
|
35
|
+
}
|
|
36
|
+
getHeader(key) {
|
|
37
|
+
var _a;
|
|
38
|
+
return (_a = this.request.headers) === null || _a === void 0 ? void 0 : _a[key];
|
|
39
|
+
}
|
|
40
|
+
getHeaders() {
|
|
41
|
+
return this.request.headers;
|
|
42
|
+
}
|
|
43
|
+
getCookie(key) {
|
|
44
|
+
return this.request.cookies[key];
|
|
45
|
+
}
|
|
46
|
+
getCookies() {
|
|
47
|
+
return this.request.cookies;
|
|
48
|
+
}
|
|
49
|
+
getClientIp() {
|
|
50
|
+
var _a, _b;
|
|
51
|
+
return this.getHeader('x-real-ip') || ((_b = (_a = this.request) === null || _a === void 0 ? void 0 : _a.socket) === null || _b === void 0 ? void 0 : _b.remoteAddress) || '';
|
|
52
|
+
}
|
|
53
|
+
getHost() {
|
|
54
|
+
if (typeof window === 'undefined') {
|
|
55
|
+
return (this.getHeader('x-original-host') || this.getHeader('host'));
|
|
56
|
+
}
|
|
57
|
+
return window.location.host;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
exports.RequestManager = RequestManager;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { provide, Scope } from '@tramvai/core';
|
|
2
|
+
import { REQUEST_MANAGER_TOKEN, COMBINE_REDUCERS } from '@tramvai/tokens-common';
|
|
3
|
+
import { FASTIFY_REQUEST } from '@tramvai/tokens-server-private';
|
|
4
|
+
import { RequestManager } from './requestManager.browser.js';
|
|
5
|
+
import { RequestManagerStore } from './RequestManagerStore.browser.js';
|
|
6
|
+
|
|
7
|
+
const sharedProviders = [
|
|
8
|
+
provide({
|
|
9
|
+
provide: REQUEST_MANAGER_TOKEN,
|
|
10
|
+
scope: Scope.REQUEST,
|
|
11
|
+
useClass: RequestManager,
|
|
12
|
+
deps: {
|
|
13
|
+
request: FASTIFY_REQUEST,
|
|
14
|
+
},
|
|
15
|
+
}),
|
|
16
|
+
provide({
|
|
17
|
+
provide: COMBINE_REDUCERS,
|
|
18
|
+
multi: true,
|
|
19
|
+
useValue: RequestManagerStore,
|
|
20
|
+
}),
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
export { sharedProviders };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { provide, Scope } from '@tramvai/core';
|
|
2
|
+
import { REQUEST_MANAGER_TOKEN, COMBINE_REDUCERS } from '@tramvai/tokens-common';
|
|
3
|
+
import { FASTIFY_REQUEST } from '@tramvai/tokens-server-private';
|
|
4
|
+
import { RequestManager } from './requestManager.es.js';
|
|
5
|
+
import { RequestManagerStore } from './RequestManagerStore.es.js';
|
|
6
|
+
|
|
7
|
+
const sharedProviders = [
|
|
8
|
+
provide({
|
|
9
|
+
provide: REQUEST_MANAGER_TOKEN,
|
|
10
|
+
scope: Scope.REQUEST,
|
|
11
|
+
useClass: RequestManager,
|
|
12
|
+
deps: {
|
|
13
|
+
request: FASTIFY_REQUEST,
|
|
14
|
+
},
|
|
15
|
+
}),
|
|
16
|
+
provide({
|
|
17
|
+
provide: COMBINE_REDUCERS,
|
|
18
|
+
multi: true,
|
|
19
|
+
useValue: RequestManagerStore,
|
|
20
|
+
}),
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
export { sharedProviders };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var core = require('@tramvai/core');
|
|
6
|
+
var tokensCommon = require('@tramvai/tokens-common');
|
|
7
|
+
var tokensServerPrivate = require('@tramvai/tokens-server-private');
|
|
8
|
+
var requestManager = require('./requestManager.js');
|
|
9
|
+
var RequestManagerStore = require('./RequestManagerStore.js');
|
|
10
|
+
|
|
11
|
+
const sharedProviders = [
|
|
12
|
+
core.provide({
|
|
13
|
+
provide: tokensCommon.REQUEST_MANAGER_TOKEN,
|
|
14
|
+
scope: core.Scope.REQUEST,
|
|
15
|
+
useClass: requestManager.RequestManager,
|
|
16
|
+
deps: {
|
|
17
|
+
request: tokensServerPrivate.FASTIFY_REQUEST,
|
|
18
|
+
},
|
|
19
|
+
}),
|
|
20
|
+
core.provide({
|
|
21
|
+
provide: tokensCommon.COMBINE_REDUCERS,
|
|
22
|
+
multi: true,
|
|
23
|
+
useValue: RequestManagerStore.RequestManagerStore,
|
|
24
|
+
}),
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
exports.sharedProviders = sharedProviders;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { __decorate } from 'tslib';
|
|
2
|
+
import { Module, provide } from '@tramvai/core';
|
|
3
|
+
import { FASTIFY_RESPONSE } from '@tramvai/tokens-server-private';
|
|
4
|
+
import { sharedProviders } from './sharedProviders.browser.js';
|
|
5
|
+
|
|
6
|
+
let ResponseManagerModule = class ResponseManagerModule {
|
|
7
|
+
};
|
|
8
|
+
ResponseManagerModule = __decorate([
|
|
9
|
+
Module({
|
|
10
|
+
providers: [
|
|
11
|
+
...sharedProviders,
|
|
12
|
+
provide({
|
|
13
|
+
provide: FASTIFY_RESPONSE,
|
|
14
|
+
// @ts-expect-error
|
|
15
|
+
useValue: {},
|
|
16
|
+
}),
|
|
17
|
+
],
|
|
18
|
+
})
|
|
19
|
+
], ResponseManagerModule);
|
|
20
|
+
|
|
21
|
+
export { ResponseManagerModule };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { __decorate } from 'tslib';
|
|
2
|
+
import { Module } from '@tramvai/core';
|
|
3
|
+
import { sharedProviders } from './sharedProviders.es.js';
|
|
4
|
+
|
|
5
|
+
let ResponseManagerModule = class ResponseManagerModule {
|
|
6
|
+
};
|
|
7
|
+
ResponseManagerModule = __decorate([
|
|
8
|
+
Module({
|
|
9
|
+
providers: [...sharedProviders],
|
|
10
|
+
})
|
|
11
|
+
], ResponseManagerModule);
|
|
12
|
+
|
|
13
|
+
export { ResponseManagerModule };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var tslib = require('tslib');
|
|
6
|
+
var core = require('@tramvai/core');
|
|
7
|
+
var sharedProviders = require('./sharedProviders.js');
|
|
8
|
+
|
|
9
|
+
exports.ResponseManagerModule = class ResponseManagerModule {
|
|
10
|
+
};
|
|
11
|
+
exports.ResponseManagerModule = tslib.__decorate([
|
|
12
|
+
core.Module({
|
|
13
|
+
providers: [...sharedProviders.sharedProviders],
|
|
14
|
+
})
|
|
15
|
+
], exports.ResponseManagerModule);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import isEmpty from '@tinkoff/utils/is/empty';
|
|
2
|
+
import values from '@tinkoff/utils/object/values';
|
|
3
|
+
|
|
4
|
+
class ResponseManager {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.body = '';
|
|
7
|
+
this.headers = {};
|
|
8
|
+
this.cookies = {};
|
|
9
|
+
this.status = 200;
|
|
10
|
+
}
|
|
11
|
+
getBody() {
|
|
12
|
+
return this.body;
|
|
13
|
+
}
|
|
14
|
+
setBody(value) {
|
|
15
|
+
this.body = value;
|
|
16
|
+
}
|
|
17
|
+
getHeader(key) {
|
|
18
|
+
if (key === 'set-cookie') {
|
|
19
|
+
return values(this.cookies);
|
|
20
|
+
}
|
|
21
|
+
return this.headers[key];
|
|
22
|
+
}
|
|
23
|
+
getHeaders() {
|
|
24
|
+
if (isEmpty(this.cookies)) {
|
|
25
|
+
return this.headers;
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
...this.headers,
|
|
29
|
+
'Set-Cookie': values(this.cookies),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
setHeader(key, value) {
|
|
33
|
+
this.headers[key] = value;
|
|
34
|
+
}
|
|
35
|
+
getCookie(key) {
|
|
36
|
+
return this.cookies[key];
|
|
37
|
+
}
|
|
38
|
+
getCookies() {
|
|
39
|
+
return this.cookies;
|
|
40
|
+
}
|
|
41
|
+
setCookie(key, value) {
|
|
42
|
+
this.cookies[key] = value;
|
|
43
|
+
}
|
|
44
|
+
setStatus(status) {
|
|
45
|
+
this.status = status;
|
|
46
|
+
}
|
|
47
|
+
getStatus() {
|
|
48
|
+
return this.status;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { ResponseManager };
|