@sima-land/isomorph 11.0.0-alpha.0 → 11.0.0-alpha.11
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/{dist/cache → cache}/types.d.ts +0 -0
- package/{dist/utils/webpack/module-federation → cache}/types.js +0 -0
- package/{dist/cache → cache}/types.js.map +0 -0
- package/{dist/config/index.d.ts → config/base.d.ts} +0 -0
- package/{dist/config/index.js → config/base.js} +1 -1
- package/config/base.js.map +1 -0
- package/{dist/config → config}/browser.d.ts +0 -0
- package/config/browser.js +22 -0
- package/config/browser.js.map +1 -0
- package/{dist/config → config}/node.d.ts +0 -0
- package/{dist/config → config}/node.js +10 -5
- package/config/node.js.map +1 -0
- package/{dist/config → config}/types.d.ts +0 -0
- package/{dist/tracer → config}/types.js +0 -0
- package/{dist/config → config}/types.js.map +0 -0
- package/di/application.d.ts +6 -0
- package/{dist/container → di}/application.js +17 -8
- package/di/application.js.map +1 -0
- package/di/container.d.ts +6 -0
- package/di/container.js +49 -0
- package/di/container.js.map +1 -0
- package/di/errors.d.ts +21 -0
- package/di/errors.js +33 -0
- package/di/errors.js.map +1 -0
- package/di/index.d.ts +6 -0
- package/di/index.js +16 -0
- package/di/index.js.map +1 -0
- package/di/preset.d.ts +9 -0
- package/di/preset.js +27 -0
- package/di/preset.js.map +1 -0
- package/di/token.d.ts +7 -0
- package/di/token.js +17 -0
- package/di/token.js.map +1 -0
- package/di/types.d.ts +32 -0
- package/{dist/saga-runner → di}/types.js +0 -0
- package/{dist/preset → di}/types.js.map +1 -1
- package/error-tracking/index.d.ts +22 -0
- package/{dist/error-tracker/utils.js → error-tracking/index.js} +14 -3
- package/error-tracking/index.js.map +1 -0
- package/error-tracking/types.d.ts +13 -0
- package/{dist/preset → error-tracking}/types.js +0 -0
- package/{dist/container → error-tracking}/types.js.map +1 -1
- package/{dist/http-client → http-client}/middleware/cookie.d.ts +0 -0
- package/{dist/http-client → http-client}/middleware/cookie.js +0 -0
- package/{dist/http-client → http-client}/middleware/cookie.js.map +0 -0
- package/http-client/middleware/logging.d.ts +15 -0
- package/http-client/middleware/logging.js +93 -0
- package/http-client/middleware/logging.js.map +1 -0
- package/{dist/http-client → http-client}/middleware/tracing.d.ts +0 -0
- package/{dist/http-client → http-client}/middleware/tracing.js +0 -0
- package/{dist/http-client → http-client}/middleware/tracing.js.map +0 -0
- package/{dist/http-client/utils.d.ts → http-client/sauce/index.d.ts} +0 -9
- package/{dist/http-client/utils.js → http-client/sauce/index.js} +2 -18
- package/http-client/sauce/index.js.map +1 -0
- package/{dist/http-client → http-client}/types.d.ts +0 -0
- package/{dist/logger → http-client}/types.js +0 -0
- package/{dist/http-client → http-client}/types.js.map +0 -0
- package/http-client/utils.d.ts +9 -0
- package/http-client/utils.js +20 -0
- package/http-client/utils.js.map +1 -0
- package/{dist/http-server → http-server}/constants.d.ts +0 -0
- package/{dist/http-server → http-server}/constants.js +0 -0
- package/{dist/http-server → http-server}/constants.js.map +0 -0
- package/{dist/http-server → http-server}/handler/health-check.d.ts +0 -0
- package/{dist/http-server → http-server}/handler/health-check.js +0 -0
- package/{dist/http-server → http-server}/handler/health-check.js.map +0 -0
- package/{dist/http-server → http-server}/middleware/logging.d.ts +0 -0
- package/{dist/http-server → http-server}/middleware/logging.js +0 -0
- package/{dist/http-server → http-server}/middleware/logging.js.map +0 -0
- package/{dist/http-server → http-server}/middleware/metrics.d.ts +0 -0
- package/{dist/http-server → http-server}/middleware/metrics.js +0 -0
- package/{dist/http-server → http-server}/middleware/metrics.js.map +0 -0
- package/http-server/middleware/tracing.d.ts +14 -0
- package/{dist/http-server → http-server}/middleware/tracing.js +22 -3
- package/http-server/middleware/tracing.js.map +1 -0
- package/http-server/template/index.d.ts +1 -0
- package/http-server/template/index.js +36 -0
- package/http-server/template/index.js.map +1 -0
- package/{dist/http-server → http-server}/types.d.ts +8 -0
- package/{dist/http-server → http-server}/types.js +0 -0
- package/{dist/http-server → http-server}/types.js.map +0 -0
- package/{dist/http-server → http-server}/utils.d.ts +5 -1
- package/{dist/http-server → http-server}/utils.js +16 -4
- package/http-server/utils.js.map +1 -0
- package/{dist/logger → logger}/handler/console.d.ts +1 -1
- package/{dist/logger → logger}/handler/console.js +8 -1
- package/logger/handler/console.js.map +1 -0
- package/logger/handler/sentry.d.ts +8 -0
- package/{dist/logger → logger}/handler/sentry.js +13 -7
- package/logger/handler/sentry.js.map +1 -0
- package/logger/index.d.ts +2 -0
- package/logger/index.js +6 -0
- package/logger/index.js.map +1 -0
- package/{dist/logger/index.d.ts → logger/logger.d.ts} +0 -0
- package/{dist/logger/index.js → logger/logger.js} +1 -1
- package/logger/logger.js.map +1 -0
- package/{dist/logger → logger}/types.d.ts +0 -0
- package/{dist/http-client → logger}/types.js +0 -0
- package/{dist/logger → logger}/types.js.map +0 -0
- package/{dist/metrics → metrics}/constants.d.ts +0 -0
- package/{dist/metrics → metrics}/constants.js +0 -0
- package/{dist/metrics → metrics}/constants.js.map +0 -0
- package/{dist/metrics → metrics}/node.d.ts +0 -0
- package/{dist/metrics → metrics}/node.js +0 -0
- package/{dist/metrics → metrics}/node.js.map +0 -0
- package/package.json +8 -11
- package/preset/browser/index.d.ts +8 -0
- package/preset/browser/index.js +48 -0
- package/preset/browser/index.js.map +1 -0
- package/preset/node/index.d.ts +19 -0
- package/preset/node/index.js +127 -0
- package/preset/node/index.js.map +1 -0
- package/preset/node/response.d.ts +20 -0
- package/preset/node/response.js +82 -0
- package/preset/node/response.js.map +1 -0
- package/tokens.d.ts +48 -0
- package/tokens.js +50 -0
- package/tokens.js.map +1 -0
- package/tracing/index.d.ts +9 -0
- package/tracing/index.js +20 -0
- package/tracing/index.js.map +1 -0
- package/{dist/utils → utils}/browser/analytics/data-layer.d.ts +0 -0
- package/{dist/utils → utils}/browser/analytics/data-layer.js +0 -0
- package/{dist/utils → utils}/browser/analytics/data-layer.js.map +0 -0
- package/{dist/utils → utils}/browser/analytics/oko.d.ts +0 -0
- package/{dist/utils → utils}/browser/analytics/oko.js +0 -0
- package/{dist/utils → utils}/browser/analytics/oko.js.map +0 -0
- package/{dist/utils → utils}/browser/storage/index.d.ts +0 -0
- package/{dist/utils → utils}/browser/storage/index.js +0 -0
- package/{dist/utils → utils}/browser/storage/index.js.map +0 -0
- package/{dist/utils → utils}/number.d.ts +0 -0
- package/{dist/utils → utils}/number.js +0 -0
- package/{dist/utils → utils}/number.js.map +0 -0
- package/{dist/utils → utils}/react/error-handlers/index.d.ts +0 -0
- package/{dist/utils → utils}/react/error-handlers/index.js +1 -0
- package/utils/react/error-handlers/index.js.map +1 -0
- package/{dist/utils → utils}/redux/remote-data.d.ts +0 -0
- package/{dist/utils → utils}/redux/remote-data.js +0 -0
- package/{dist/utils → utils}/redux/remote-data.js.map +0 -0
- package/utils/redux-saga/index.d.ts +3 -0
- package/utils/redux-saga/index.js +8 -0
- package/utils/redux-saga/index.js.map +1 -0
- package/utils/redux-saga/middleware.d.ts +9 -0
- package/utils/redux-saga/middleware.js +87 -0
- package/utils/redux-saga/middleware.js.map +1 -0
- package/{dist/utils → utils}/redux-saga/take-chain.d.ts +0 -0
- package/{dist/utils → utils}/redux-saga/take-chain.js +0 -0
- package/{dist/utils → utils}/redux-saga/take-chain.js.map +0 -0
- package/utils/redux-saga/types.d.ts +6 -0
- package/{dist/error-tracker → utils/redux-saga}/types.js +0 -0
- package/{dist/error-tracker → utils/redux-saga}/types.js.map +1 -1
- package/utils/ssr/index.d.ts +30 -0
- package/utils/ssr/index.js +51 -0
- package/utils/ssr/index.js.map +1 -0
- package/utils/webpack/index.d.ts +23 -0
- package/utils/webpack/index.js +66 -0
- package/utils/webpack/index.js.map +1 -0
- package/{dist/utils → utils}/webpack/module-federation/index.d.ts +0 -0
- package/{dist/utils → utils}/webpack/module-federation/index.js +0 -0
- package/{dist/utils → utils}/webpack/module-federation/index.js.map +0 -0
- package/{dist/utils → utils}/webpack/module-federation/types.d.ts +0 -0
- package/{dist/container → utils/webpack/module-federation}/types.js +0 -0
- package/{dist/utils → utils}/webpack/module-federation/types.js.map +0 -0
- package/{dist/utils → utils}/webpack/module-federation/utils.d.ts +0 -0
- package/{dist/utils → utils}/webpack/module-federation/utils.js +0 -0
- package/{dist/utils → utils}/webpack/module-federation/utils.js.map +0 -0
- package/LICENSE +0 -201
- package/dist/cache/types.js +0 -3
- package/dist/config/browser.js +0 -13
- package/dist/config/browser.js.map +0 -1
- package/dist/config/index.js.map +0 -1
- package/dist/config/node.js.map +0 -1
- package/dist/config/types.js +0 -3
- package/dist/config/utils.d.ts +0 -5
- package/dist/config/utils.js +0 -12
- package/dist/config/utils.js.map +0 -1
- package/dist/container/application.d.ts +0 -25
- package/dist/container/application.js.map +0 -1
- package/dist/container/index.d.ts +0 -18
- package/dist/container/index.js +0 -74
- package/dist/container/index.js.map +0 -1
- package/dist/container/types.d.ts +0 -14
- package/dist/error-tracker/browser.d.ts +0 -8
- package/dist/error-tracker/browser.js +0 -40
- package/dist/error-tracker/browser.js.map +0 -1
- package/dist/error-tracker/node.d.ts +0 -8
- package/dist/error-tracker/node.js +0 -40
- package/dist/error-tracker/node.js.map +0 -1
- package/dist/error-tracker/types.d.ts +0 -18
- package/dist/error-tracker/utils.d.ts +0 -12
- package/dist/error-tracker/utils.js.map +0 -1
- package/dist/http-client/utils.js.map +0 -1
- package/dist/http-server/middleware/tracing.d.ts +0 -8
- package/dist/http-server/middleware/tracing.js.map +0 -1
- package/dist/http-server/utils.js.map +0 -1
- package/dist/logger/handler/console.js.map +0 -1
- package/dist/logger/handler/sentry.d.ts +0 -8
- package/dist/logger/handler/sentry.js.map +0 -1
- package/dist/logger/index.js.map +0 -1
- package/dist/preset/index.d.ts +0 -7
- package/dist/preset/index.js +0 -23
- package/dist/preset/index.js.map +0 -1
- package/dist/preset/node/index.d.ts +0 -15
- package/dist/preset/node/index.js +0 -90
- package/dist/preset/node/index.js.map +0 -1
- package/dist/preset/node/response.d.ts +0 -12
- package/dist/preset/node/response.js +0 -52
- package/dist/preset/node/response.js.map +0 -1
- package/dist/preset/types.d.ts +0 -7
- package/dist/saga-runner/index.d.ts +0 -8
- package/dist/saga-runner/index.js +0 -77
- package/dist/saga-runner/index.js.map +0 -1
- package/dist/saga-runner/types.d.ts +0 -10
- package/dist/saga-runner/types.js.map +0 -1
- package/dist/tokens.d.ts +0 -40
- package/dist/tokens.js +0 -43
- package/dist/tokens.js.map +0 -1
- package/dist/tracer/node.d.ts +0 -10
- package/dist/tracer/node.js +0 -38
- package/dist/tracer/node.js.map +0 -1
- package/dist/tracer/types.d.ts +0 -2
- package/dist/tracer/types.js.map +0 -1
- package/dist/utils/react/error-handlers/index.js.map +0 -1
- package/readme.md +0 -23
- package/src/cache/types.ts +0 -7
- package/src/config/browser.ts +0 -10
- package/src/config/index.ts +0 -18
- package/src/config/node.ts +0 -18
- package/src/config/types.ts +0 -9
- package/src/config/utils.ts +0 -7
- package/src/container/application.ts +0 -91
- package/src/container/index.ts +0 -79
- package/src/container/types.ts +0 -17
- package/src/error-tracker/browser.ts +0 -14
- package/src/error-tracker/node.ts +0 -14
- package/src/error-tracker/types.ts +0 -22
- package/src/error-tracker/utils.ts +0 -18
- package/src/http-client/middleware/cookie.ts +0 -73
- package/src/http-client/middleware/tracing.ts +0 -79
- package/src/http-client/types.ts +0 -8
- package/src/http-client/utils.ts +0 -76
- package/src/http-server/constants.ts +0 -4
- package/src/http-server/handler/health-check.ts +0 -13
- package/src/http-server/middleware/logging.ts +0 -34
- package/src/http-server/middleware/metrics.ts +0 -87
- package/src/http-server/middleware/tracing.ts +0 -35
- package/src/http-server/types.ts +0 -29
- package/src/http-server/utils.ts +0 -105
- package/src/logger/handler/console.ts +0 -35
- package/src/logger/handler/sentry.ts +0 -38
- package/src/logger/index.ts +0 -31
- package/src/logger/types.ts +0 -28
- package/src/metrics/constants.ts +0 -4
- package/src/metrics/node.ts +0 -54
- package/src/preset/index.ts +0 -24
- package/src/preset/node/index.ts +0 -101
- package/src/preset/node/response.ts +0 -57
- package/src/preset/types.ts +0 -9
- package/src/saga-runner/index.ts +0 -59
- package/src/saga-runner/types.ts +0 -13
- package/src/tokens.ts +0 -54
- package/src/tracer/node.ts +0 -40
- package/src/tracer/types.ts +0 -3
- package/src/utils/browser/analytics/__test__/data-layer.test.ts +0 -50
- package/src/utils/browser/analytics/__test__/oko.test.tsx +0 -143
- package/src/utils/browser/analytics/data-layer.ts +0 -12
- package/src/utils/browser/analytics/oko.ts +0 -44
- package/src/utils/browser/storage/index.ts +0 -75
- package/src/utils/number.ts +0 -8
- package/src/utils/react/error-handlers/__test__/__snapshots__/index.test.tsx.snap +0 -27
- package/src/utils/react/error-handlers/__test__/index.test.tsx +0 -64
- package/src/utils/react/error-handlers/index.tsx +0 -62
- package/src/utils/redux/__test__/remote-data.test.ts +0 -50
- package/src/utils/redux/remote-data.ts +0 -34
- package/src/utils/redux-saga/__test__/take-chain.test.ts +0 -141
- package/src/utils/redux-saga/take-chain.ts +0 -65
- package/src/utils/webpack/module-federation/__test__/index.test.ts +0 -246
- package/src/utils/webpack/module-federation/index.ts +0 -92
- package/src/utils/webpack/module-federation/types.ts +0 -44
- package/src/utils/webpack/module-federation/utils.ts +0 -43
package/src/preset/types.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Application } from '../container/application';
|
|
2
|
-
import type { Token, Provider } from '../container/types';
|
|
3
|
-
|
|
4
|
-
export type PresetEntry<T = any> = [Token<T>, Provider<T>];
|
|
5
|
-
|
|
6
|
-
export interface Preset {
|
|
7
|
-
override: <T>(token: Token<T>, provider: Provider<T>) => void;
|
|
8
|
-
apply: (application: Application) => void;
|
|
9
|
-
}
|
package/src/saga-runner/index.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import type { Store } from '@reduxjs/toolkit';
|
|
2
|
-
import type { Logger } from '../logger/types';
|
|
3
|
-
import type { SagaRunner } from './types';
|
|
4
|
-
import createSagaMiddleware, { Saga, END } from 'redux-saga';
|
|
5
|
-
import { SentryError } from '../error-tracker/utils';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Возвращает новый runner для redux-saga.
|
|
9
|
-
* @param logger Logger.
|
|
10
|
-
* @return Runner.
|
|
11
|
-
*/
|
|
12
|
-
export function createSagaRunner(logger: Logger): SagaRunner {
|
|
13
|
-
const middleware = createSagaMiddleware({
|
|
14
|
-
onError: (error, { sagaStack }) => {
|
|
15
|
-
logger.error(
|
|
16
|
-
new SentryError(error.message, {
|
|
17
|
-
extra: { key: 'Saga stack', data: sagaStack },
|
|
18
|
-
}),
|
|
19
|
-
);
|
|
20
|
-
},
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
middleware,
|
|
25
|
-
|
|
26
|
-
// eslint-disable-next-line require-jsdoc, jsdoc/require-jsdoc
|
|
27
|
-
prepare(store: Store, { timeout }: { timeout?: number } = {}) {
|
|
28
|
-
return {
|
|
29
|
-
// eslint-disable-next-line require-jsdoc, jsdoc/require-jsdoc
|
|
30
|
-
async run<S extends Saga>(saga: S, ...args: Parameters<S>) {
|
|
31
|
-
let ready = false;
|
|
32
|
-
|
|
33
|
-
await Promise.race([
|
|
34
|
-
// ждем пока сага выполнится
|
|
35
|
-
middleware
|
|
36
|
-
.run(saga, ...args)
|
|
37
|
-
.toPromise()
|
|
38
|
-
.then(() => {
|
|
39
|
-
ready = true;
|
|
40
|
-
}),
|
|
41
|
-
|
|
42
|
-
// если сага не выполнилась за положенное время - прерываем
|
|
43
|
-
typeof timeout === 'number' &&
|
|
44
|
-
Number.isFinite(timeout) &&
|
|
45
|
-
new Promise<void>(resolve => {
|
|
46
|
-
setTimeout(() => {
|
|
47
|
-
if (!ready) {
|
|
48
|
-
logger.error(Error('Сага прервана по таймауту'));
|
|
49
|
-
store.dispatch(END);
|
|
50
|
-
}
|
|
51
|
-
resolve();
|
|
52
|
-
}, timeout);
|
|
53
|
-
}),
|
|
54
|
-
]);
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
}
|
package/src/saga-runner/types.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Saga, SagaMiddleware } from 'redux-saga';
|
|
2
|
-
import type { Store } from '@reduxjs/toolkit';
|
|
3
|
-
|
|
4
|
-
export interface SagaRunner {
|
|
5
|
-
middleware: SagaMiddleware<any>;
|
|
6
|
-
|
|
7
|
-
prepare: (
|
|
8
|
-
store: Store,
|
|
9
|
-
options?: { timeout?: number },
|
|
10
|
-
) => {
|
|
11
|
-
run: <S extends Saga>(saga: S, ...args: Parameters<S>) => Promise<void>;
|
|
12
|
-
};
|
|
13
|
-
}
|
package/src/tokens.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { createToken } from './container';
|
|
2
|
-
import type { Application } from 'express';
|
|
3
|
-
import type { DefaultMiddleware, PageAssets, ResponseContext } from './http-server/types';
|
|
4
|
-
import type { SagaRunner } from './saga-runner/types';
|
|
5
|
-
import type { Logger } from './logger/types';
|
|
6
|
-
import type { HttpClientFactory } from './http-client/types';
|
|
7
|
-
import type { ConfigSource, BaseConfig } from './config/types';
|
|
8
|
-
import type { Tracer } from './tracer/types';
|
|
9
|
-
import type { Cache } from './cache/types';
|
|
10
|
-
|
|
11
|
-
export const KnownToken = {
|
|
12
|
-
// config
|
|
13
|
-
Config: {
|
|
14
|
-
source: createToken<ConfigSource>('config.source'),
|
|
15
|
-
base: createToken<BaseConfig>('config.base'),
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
// cache
|
|
19
|
-
cache: createToken<Cache>('cache'),
|
|
20
|
-
|
|
21
|
-
// logging
|
|
22
|
-
logger: createToken<Logger>('logger'),
|
|
23
|
-
|
|
24
|
-
// tracing
|
|
25
|
-
tracer: createToken<Tracer>('tracer'),
|
|
26
|
-
|
|
27
|
-
// metrics
|
|
28
|
-
Metrics: {
|
|
29
|
-
httpApp: createToken<Application>('metrics.http-app'),
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
// http
|
|
33
|
-
Http: {
|
|
34
|
-
Client: {
|
|
35
|
-
factory: createToken<HttpClientFactory>('http.client.factory'),
|
|
36
|
-
},
|
|
37
|
-
Server: {
|
|
38
|
-
factory: createToken<() => Application>('http.server.factory'),
|
|
39
|
-
Defaults: {
|
|
40
|
-
middleware: createToken<DefaultMiddleware>('http.server.defaults.middleware'),
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
// scope: page response
|
|
46
|
-
Response: {
|
|
47
|
-
context: createToken<ResponseContext>('response/context'),
|
|
48
|
-
assets: createToken<PageAssets>('response/assets'),
|
|
49
|
-
prepare: createToken<() => JSX.Element | Promise<JSX.Element>>('response/prepare'),
|
|
50
|
-
render: createToken<(element: JSX.Element) => string | Promise<string>>('response/render'),
|
|
51
|
-
main: createToken<() => void>('response/main'),
|
|
52
|
-
sagaRunner: createToken<SagaRunner>('response/saga-runner'),
|
|
53
|
-
},
|
|
54
|
-
} as const;
|
package/src/tracer/node.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { Tracer } from './types';
|
|
2
|
-
import type { BaseConfig } from '../config/types';
|
|
3
|
-
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
|
|
4
|
-
import { BatchSpanProcessor, SpanExporter } from '@opentelemetry/tracing';
|
|
5
|
-
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
|
|
6
|
-
import { registerInstrumentations } from '@opentelemetry/instrumentation';
|
|
7
|
-
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';
|
|
8
|
-
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
|
|
9
|
-
import { Resource } from '@opentelemetry/resources';
|
|
10
|
-
import { JaegerPropagator } from '@opentelemetry/propagator-jaeger';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Возвращает новый tracer - объект для трассировки стадий различных процессов.
|
|
14
|
-
* @param config Конфиг.
|
|
15
|
-
* @param exporter Экспортер данных трассировки.
|
|
16
|
-
* @return Tracer.
|
|
17
|
-
*/
|
|
18
|
-
export function createTracer(config: BaseConfig, exporter: SpanExporter): Tracer {
|
|
19
|
-
// @todo доделать по инструкции: https://selvaganesh93.medium.com/tracing-node-js-application-with-opentelemetry-jaeger-ui-9523c0ac8453
|
|
20
|
-
const provider = new NodeTracerProvider({
|
|
21
|
-
resource: new Resource({
|
|
22
|
-
[SemanticResourceAttributes.SERVICE_NAME]: config.appName,
|
|
23
|
-
[SemanticResourceAttributes.SERVICE_VERSION]: config.appVersion,
|
|
24
|
-
[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: config.env,
|
|
25
|
-
}),
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
// @todo выяснить, почему не сходятся типы и приходится оставлять as any
|
|
29
|
-
provider.addSpanProcessor(new BatchSpanProcessor(exporter) as any);
|
|
30
|
-
|
|
31
|
-
provider.register({
|
|
32
|
-
propagator: new JaegerPropagator(),
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
registerInstrumentations({
|
|
36
|
-
instrumentations: [new ExpressInstrumentation(), new HttpInstrumentation()],
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
return provider.getTracer(config.appName, config.appVersion);
|
|
40
|
-
}
|
package/src/tracer/types.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { dataLayerPush } from '../data-layer';
|
|
2
|
-
|
|
3
|
-
describe('dataLayerPush', () => {
|
|
4
|
-
beforeAll(() => {
|
|
5
|
-
(window as any).dataLayer = {
|
|
6
|
-
checkContext: () => 123,
|
|
7
|
-
|
|
8
|
-
push: jest.fn(function (this: any, data) {
|
|
9
|
-
// имитируем реальную работу window.dataLayer.push: в процессе удаляет data.n
|
|
10
|
-
delete data.n;
|
|
11
|
-
|
|
12
|
-
// имитируем реальную работу window.dataLayer.push: в процессе вызывает другие методы с this
|
|
13
|
-
this.checkContext();
|
|
14
|
-
}),
|
|
15
|
-
};
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
afterAll(() => {
|
|
19
|
-
delete (window as any).dataLayer;
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('should handle window.dataLayer.push mutates object argument', () => {
|
|
23
|
-
const testData = {
|
|
24
|
-
n: 'test-event',
|
|
25
|
-
prop1: 1,
|
|
26
|
-
prop2: 2,
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
expect((window as any).dataLayer.push).toBeCalledTimes(0);
|
|
30
|
-
|
|
31
|
-
dataLayerPush(testData);
|
|
32
|
-
|
|
33
|
-
expect((window as any).dataLayer.push).toBeCalledTimes(1);
|
|
34
|
-
expect((window as any).dataLayer.push.mock.calls[0][0]).toEqual({
|
|
35
|
-
prop1: 1,
|
|
36
|
-
prop2: 2,
|
|
37
|
-
});
|
|
38
|
-
expect(testData).toEqual({
|
|
39
|
-
n: 'test-event',
|
|
40
|
-
prop1: 1,
|
|
41
|
-
prop2: 2,
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('should handle window.dataLayer.push absence', () => {
|
|
46
|
-
delete (window as any).dataLayer;
|
|
47
|
-
|
|
48
|
-
expect(() => dataLayerPush({ n: 'test-123' })).not.toThrow();
|
|
49
|
-
});
|
|
50
|
-
});
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import React, { createElement } from 'react';
|
|
2
|
-
import { render } from 'react-dom';
|
|
3
|
-
import { act, Simulate } from 'react-dom/test-utils';
|
|
4
|
-
import { okoPush, useOkoPush } from '../oko';
|
|
5
|
-
|
|
6
|
-
describe('useOkoPush', () => {
|
|
7
|
-
const TestComponent = ({ prop }: any) => {
|
|
8
|
-
const fn = useOkoPush({
|
|
9
|
-
n: 'test-event',
|
|
10
|
-
prop,
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
return createElement('div', { 'data-testid': 'test-block', onClick: fn });
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
beforeAll(() => {
|
|
17
|
-
(window as any).oko = {
|
|
18
|
-
push: jest.fn(),
|
|
19
|
-
};
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
afterAll(() => {
|
|
23
|
-
delete (window as any).oko;
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('should call', () => {
|
|
27
|
-
const container = document.createElement('div');
|
|
28
|
-
|
|
29
|
-
document.body.append(container);
|
|
30
|
-
|
|
31
|
-
render(<TestComponent prop={123} />, container);
|
|
32
|
-
|
|
33
|
-
expect((window as any).oko.push).toHaveBeenCalledTimes(0);
|
|
34
|
-
|
|
35
|
-
act(() => {
|
|
36
|
-
Simulate.click(container.querySelector('[data-testid="test-block"]') as HTMLElement);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
expect((window as any).oko.push).toHaveBeenCalledTimes(1);
|
|
40
|
-
expect((window as any).oko.push).toHaveBeenCalledWith({
|
|
41
|
-
n: 'test-event',
|
|
42
|
-
prop: 123,
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('should throw error', async () => {
|
|
47
|
-
const container = document.createElement('div');
|
|
48
|
-
|
|
49
|
-
document.body.append(container);
|
|
50
|
-
|
|
51
|
-
render(<TestComponent prop={1} />, container);
|
|
52
|
-
|
|
53
|
-
const renderWithError = () => {
|
|
54
|
-
render(<TestComponent prop={2} />, container);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
expect(renderWithError).toThrow(
|
|
58
|
-
Error(
|
|
59
|
-
[
|
|
60
|
-
'useAnalytics: Данные для аналитики изменились.',
|
|
61
|
-
'Если необходимо использовать динамические данные, вынесите логику из React-компонента.',
|
|
62
|
-
].join('\n'),
|
|
63
|
-
),
|
|
64
|
-
);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('should do not throw for complex object structure', () => {
|
|
68
|
-
const ComplexTest = () => {
|
|
69
|
-
const fn = useOkoPush({
|
|
70
|
-
n: 'custom',
|
|
71
|
-
category: 'balance_goods',
|
|
72
|
-
custom_str: ['minus'],
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
return <div data-testid='test-block' onClick={fn} />;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const container = document.createElement('div');
|
|
79
|
-
|
|
80
|
-
document.body.append(container);
|
|
81
|
-
|
|
82
|
-
act(() => {
|
|
83
|
-
render(<ComplexTest />, container);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
const secondRender = () => {
|
|
87
|
-
act(() => {
|
|
88
|
-
render(<ComplexTest />, container);
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
expect(secondRender).not.toThrow();
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
describe('okoPush', () => {
|
|
97
|
-
beforeAll(() => {
|
|
98
|
-
(window as any).oko = {
|
|
99
|
-
checkContext: () => 123,
|
|
100
|
-
|
|
101
|
-
push: jest.fn(function (this: any, data) {
|
|
102
|
-
// имитируем реальную работу window.oko.push: в процессе удаляет data.n
|
|
103
|
-
delete data.n;
|
|
104
|
-
|
|
105
|
-
// имитируем реальную работу window.oko.push: в процессе вызывает другие методы с this
|
|
106
|
-
this.checkContext();
|
|
107
|
-
}),
|
|
108
|
-
};
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
afterAll(() => {
|
|
112
|
-
delete (window as any).oko;
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('should handle window.oko.push mutates object argument', () => {
|
|
116
|
-
const testData = {
|
|
117
|
-
n: 'test-event',
|
|
118
|
-
prop1: 1,
|
|
119
|
-
prop2: 2,
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
expect((window as any).oko.push).toBeCalledTimes(0);
|
|
123
|
-
|
|
124
|
-
okoPush(testData);
|
|
125
|
-
|
|
126
|
-
expect((window as any).oko.push).toBeCalledTimes(1);
|
|
127
|
-
expect((window as any).oko.push.mock.calls[0][0]).toEqual({
|
|
128
|
-
prop1: 1,
|
|
129
|
-
prop2: 2,
|
|
130
|
-
});
|
|
131
|
-
expect(testData).toEqual({
|
|
132
|
-
n: 'test-event',
|
|
133
|
-
prop1: 1,
|
|
134
|
-
prop2: 2,
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('should handle window.oko.push absence', () => {
|
|
139
|
-
delete (window as any).oko;
|
|
140
|
-
|
|
141
|
-
expect(() => okoPush({ n: 'test-123' })).not.toThrow();
|
|
142
|
-
});
|
|
143
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { isFunction } from 'lodash';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Отправка аналитики в око.
|
|
5
|
-
* @param eventData Данные события для отправки.
|
|
6
|
-
*/
|
|
7
|
-
export const dataLayerPush = (eventData: Record<string, any>) => {
|
|
8
|
-
const win: any = window;
|
|
9
|
-
|
|
10
|
-
// копируем объект так как window.dataLayer.push может менять аргумент в процессе работы
|
|
11
|
-
isFunction(win.dataLayer?.push) && win.dataLayer.push({ ...eventData });
|
|
12
|
-
};
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { useRef } from 'react';
|
|
2
|
-
import { isEqual, isFunction } from 'lodash';
|
|
3
|
-
|
|
4
|
-
export type OkoEvent = Record<string, any>;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Отправка аналитики в око.
|
|
8
|
-
* @param eventData Данные события для отправки.
|
|
9
|
-
*/
|
|
10
|
-
export const okoPush = (eventData: OkoEvent) => {
|
|
11
|
-
const win: any = window;
|
|
12
|
-
|
|
13
|
-
// копируем объект так как window.oko.push меняет свой аргумент в процессе выполнения
|
|
14
|
-
isFunction(win.oko?.push) && win.oko.push({ ...eventData });
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Хук, возвращающий функцию, которая отправит аналитику в ОКО.
|
|
19
|
-
* @param data Данные события для отправки в ОКО.
|
|
20
|
-
* @return Функция.
|
|
21
|
-
*/
|
|
22
|
-
export const useOkoPush = (data: OkoEvent) => {
|
|
23
|
-
const dataRef = useRef<OkoEvent>();
|
|
24
|
-
const fnRef = useRef<() => void>();
|
|
25
|
-
|
|
26
|
-
if (!dataRef.current) {
|
|
27
|
-
dataRef.current = { ...data };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (!fnRef.current) {
|
|
31
|
-
fnRef.current = () => okoPush(dataRef.current as OkoEvent);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (!isEqual(data, dataRef.current)) {
|
|
35
|
-
throw Error(
|
|
36
|
-
[
|
|
37
|
-
'useAnalytics: Данные для аналитики изменились.',
|
|
38
|
-
'Если необходимо использовать динамические данные, вынесите логику из React-компонента.',
|
|
39
|
-
].join('\n'),
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return fnRef.current;
|
|
44
|
-
};
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/* eslint-disable require-jsdoc, jsdoc/require-jsdoc */
|
|
2
|
-
|
|
3
|
-
export interface StorageUtils
|
|
4
|
-
extends Pick<Storage, 'clear' | 'getItem' | 'key' | 'removeItem' | 'setItem' | 'length'> {
|
|
5
|
-
isAvailable: () => boolean;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function createStorageUtils(getStorage: () => Storage): StorageUtils {
|
|
9
|
-
function isAvailable(): boolean {
|
|
10
|
-
try {
|
|
11
|
-
const testKey = `local_storage_test_key::${Date.now()}`;
|
|
12
|
-
|
|
13
|
-
getStorage().setItem(testKey, testKey);
|
|
14
|
-
getStorage().removeItem(testKey);
|
|
15
|
-
|
|
16
|
-
return true;
|
|
17
|
-
} catch {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function clear(): void {
|
|
23
|
-
if (isAvailable()) {
|
|
24
|
-
getStorage().clear();
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function getItem(name: string): string | null {
|
|
29
|
-
if (isAvailable()) {
|
|
30
|
-
return getStorage().getItem(name);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function key(index: number): string | null {
|
|
37
|
-
if (isAvailable()) {
|
|
38
|
-
return getStorage().key(index);
|
|
39
|
-
}
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function removeItem(name: string): void {
|
|
44
|
-
if (isAvailable()) {
|
|
45
|
-
getStorage().removeItem(name);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function setItem(name: string, value: string): void {
|
|
50
|
-
if (isAvailable()) {
|
|
51
|
-
getStorage().setItem(name, value);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function length(): number {
|
|
56
|
-
if (isAvailable()) {
|
|
57
|
-
return getStorage().length;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return 0;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
isAvailable,
|
|
65
|
-
|
|
66
|
-
clear,
|
|
67
|
-
getItem,
|
|
68
|
-
key,
|
|
69
|
-
removeItem,
|
|
70
|
-
setItem,
|
|
71
|
-
get length() {
|
|
72
|
-
return length();
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
}
|
package/src/utils/number.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`ErrorBoundary should call captureException 1`] = `<div />`;
|
|
4
|
-
|
|
5
|
-
exports[`ErrorBoundary should render children component 1`] = `
|
|
6
|
-
<div>
|
|
7
|
-
<div>
|
|
8
|
-
Normal component
|
|
9
|
-
</div>
|
|
10
|
-
</div>
|
|
11
|
-
`;
|
|
12
|
-
|
|
13
|
-
exports[`ErrorBoundary should render fallback component 1`] = `
|
|
14
|
-
<div>
|
|
15
|
-
<div>
|
|
16
|
-
Fallback
|
|
17
|
-
</div>
|
|
18
|
-
</div>
|
|
19
|
-
`;
|
|
20
|
-
|
|
21
|
-
exports[`SafeSuspense should render with props 1`] = `
|
|
22
|
-
<div>
|
|
23
|
-
<div>
|
|
24
|
-
Normal component
|
|
25
|
-
</div>
|
|
26
|
-
</div>
|
|
27
|
-
`;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
3
|
-
import { ErrorBoundary, SafeSuspense } from '..';
|
|
4
|
-
|
|
5
|
-
describe('ErrorBoundary', () => {
|
|
6
|
-
const error = new Error('Test error');
|
|
7
|
-
|
|
8
|
-
const FailedComponent = () => {
|
|
9
|
-
throw error;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
it('should render children component', () => {
|
|
13
|
-
const { container } = render(
|
|
14
|
-
<ErrorBoundary fallback={null}>
|
|
15
|
-
<div>Normal component</div>
|
|
16
|
-
</ErrorBoundary>,
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
expect(container.textContent).toContain('Normal component');
|
|
20
|
-
expect(container).toMatchSnapshot();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('should render fallback component', () => {
|
|
24
|
-
const { container } = render(
|
|
25
|
-
<ErrorBoundary fallback={<div>Fallback</div>}>
|
|
26
|
-
<>
|
|
27
|
-
<div>Normal component</div>
|
|
28
|
-
<FailedComponent />
|
|
29
|
-
</>
|
|
30
|
-
</ErrorBoundary>,
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
expect(container.textContent).toContain('Fallback');
|
|
34
|
-
expect(container).toMatchSnapshot();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('should call captureException', () => {
|
|
38
|
-
const handlerException = jest.fn();
|
|
39
|
-
|
|
40
|
-
const { container } = render(
|
|
41
|
-
<ErrorBoundary fallback={null} onError={handlerException}>
|
|
42
|
-
<>
|
|
43
|
-
<div>Normal component</div>
|
|
44
|
-
<FailedComponent />
|
|
45
|
-
</>
|
|
46
|
-
</ErrorBoundary>,
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
expect(handlerException).toBeCalledWith(error, { componentStack: expect.any(String) });
|
|
50
|
-
expect(container).toMatchSnapshot();
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
describe('SafeSuspense', () => {
|
|
55
|
-
it('should render with props', () => {
|
|
56
|
-
const { container } = render(
|
|
57
|
-
<SafeSuspense fallback={<div>Fallback</div>} onError={jest.fn()}>
|
|
58
|
-
<div>Normal component</div>
|
|
59
|
-
</SafeSuspense>,
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
expect(container).toMatchSnapshot();
|
|
63
|
-
});
|
|
64
|
-
});
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
export interface Props {
|
|
4
|
-
/** Дочерний компонент. */
|
|
5
|
-
children: NonNullable<React.ReactNode> | null;
|
|
6
|
-
|
|
7
|
-
/** Запасной элемент, если возникла ошибка. */
|
|
8
|
-
fallback: NonNullable<React.ReactNode> | null;
|
|
9
|
-
|
|
10
|
-
/** Функция для логирования ошибки. */
|
|
11
|
-
onError?: (error: Error, errorInfo: React.ErrorInfo) => void;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Обработчик ошибок в React-компонентах.
|
|
16
|
-
*/
|
|
17
|
-
export class ErrorBoundary extends React.Component<Props, { hasError: boolean }> {
|
|
18
|
-
/**
|
|
19
|
-
* @param props Свойства.
|
|
20
|
-
*/
|
|
21
|
-
constructor(props: Props) {
|
|
22
|
-
super(props);
|
|
23
|
-
|
|
24
|
-
this.state = { hasError: false };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** @inheritdoc */
|
|
28
|
-
static getDerivedStateFromError() {
|
|
29
|
-
return { hasError: true };
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** @inheritdoc */
|
|
33
|
-
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
|
|
34
|
-
const { onError } = this.props;
|
|
35
|
-
|
|
36
|
-
onError?.(error, errorInfo);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Рендер.
|
|
41
|
-
* @return Дочерний элемент либо запасное значение.
|
|
42
|
-
*/
|
|
43
|
-
render() {
|
|
44
|
-
const { children, fallback } = this.props;
|
|
45
|
-
|
|
46
|
-
return this.state.hasError ? fallback : children;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Обертка над Suspense c перехватом ошибок.
|
|
52
|
-
* @todo Возможно этот компонент не нужен...
|
|
53
|
-
* @param props Свойства.
|
|
54
|
-
* @return Элемент.
|
|
55
|
-
*/
|
|
56
|
-
export const SafeSuspense = ({ children, fallback, onError }: Props) => (
|
|
57
|
-
<React.Suspense fallback={fallback}>
|
|
58
|
-
<ErrorBoundary fallback={fallback} onError={onError}>
|
|
59
|
-
{children}
|
|
60
|
-
</ErrorBoundary>
|
|
61
|
-
</React.Suspense>
|
|
62
|
-
);
|