@servicetitan/log-service 23.4.0 → 23.5.1
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/bind-log.d.ts +3 -0
- package/dist/bind-log.d.ts.map +1 -0
- package/dist/bind-log.js +15 -0
- package/dist/bind-log.js.map +1 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -10
- package/dist/index.js.map +1 -1
- package/dist/log-config-provider.d.ts +8 -0
- package/dist/log-config-provider.d.ts.map +1 -0
- package/dist/log-config-provider.js +5 -0
- package/dist/log-config-provider.js.map +1 -0
- package/dist/log-config.d.ts +7 -0
- package/dist/log-config.d.ts.map +1 -0
- package/dist/log-config.js +7 -0
- package/dist/log-config.js.map +1 -0
- package/dist/log-sender.d.ts +1 -1
- package/dist/log-sender.d.ts.map +1 -1
- package/dist/log-sender.js +1 -1
- package/dist/log-sender.js.map +1 -1
- package/dist/log-service.d.ts +7 -0
- package/dist/log-service.d.ts.map +1 -0
- package/dist/log-service.js +30 -0
- package/dist/log-service.js.map +1 -0
- package/dist/log-storage.d.ts +6 -1
- package/dist/log-storage.d.ts.map +1 -1
- package/dist/log-storage.js +30 -18
- package/dist/log-storage.js.map +1 -1
- package/dist/log.d.ts +5 -11
- package/dist/log.d.ts.map +1 -1
- package/dist/log.js +35 -10
- package/dist/log.js.map +1 -1
- package/package.json +6 -6
- package/src/__tests__/log-config-provider.test.tsx +3 -2
- package/src/__tests__/log-sender.test.ts +2 -2
- package/src/__tests__/log-service.test.tsx +77 -0
- package/src/__tests__/log-storage.test.ts +11 -9
- package/src/__tests__/log.test.ts +33 -3
- package/src/bind-log.ts +17 -0
- package/src/index.ts +22 -29
- package/src/log-config-provider.tsx +10 -0
- package/src/log-config.ts +13 -0
- package/src/log-sender.ts +1 -1
- package/src/log-service.tsx +51 -0
- package/src/log-storage.ts +22 -18
- package/src/{log.tsx → log.ts} +29 -18
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bind-log.d.ts","sourceRoot":"","sources":["../src/bind-log.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AASpD,wBAAgB,OAAO,CAAC,SAAS,EAAE,SAAS,QAO3C"}
|
package/dist/bind-log.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ConnectionService } from './connection-service';
|
|
2
|
+
import { GlobalErrorHandler } from './global-error-handler';
|
|
3
|
+
import { Log } from './log';
|
|
4
|
+
import { LOG_CONFIG_TOKEN, defaultLogConfig } from './log-config';
|
|
5
|
+
import { LogSender } from './log-sender';
|
|
6
|
+
import { LogStorage } from './log-storage';
|
|
7
|
+
export function bindLog(container) {
|
|
8
|
+
container.bind(LOG_CONFIG_TOKEN).toConstantValue(defaultLogConfig);
|
|
9
|
+
container.bind(LogStorage).toSelf().inSingletonScope();
|
|
10
|
+
container.bind(Log).toSelf().inSingletonScope();
|
|
11
|
+
container.bind(ConnectionService).toSelf().inSingletonScope();
|
|
12
|
+
container.bind(LogSender).toSelf().inSingletonScope();
|
|
13
|
+
container.bind(GlobalErrorHandler).toSelf().inSingletonScope();
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=bind-log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bind-log.js","sourceRoot":"","sources":["../src/bind-log.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAa,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,UAAU,OAAO,CAAC,SAAoB;IACxC,SAAS,CAAC,IAAI,CAAY,gBAAgB,CAAC,CAAC,eAAe,CAAC,gBAAgB,CAAC,CAAC;IAC9E,SAAS,CAAC,IAAI,CAAa,UAAU,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IACnE,SAAS,CAAC,IAAI,CAAM,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IACrD,SAAS,CAAC,IAAI,CAAoB,iBAAiB,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IACjF,SAAS,CAAC,IAAI,CAAY,SAAS,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IACjE,SAAS,CAAC,IAAI,CAAqB,kBAAkB,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;AACvF,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ArbitaryData,
|
|
1
|
+
import { bindLog } from './bind-log';
|
|
2
|
+
import { ArbitaryData, EntryComplete, EntryCompleteError, ILog, LOG_CONFIG_TOKEN, Log, LogConfig, LogEntry, LogEntryType, LogError, LogInfo, LogWarning } from './log';
|
|
3
|
+
import { LogConfigProvider } from './log-config-provider';
|
|
3
4
|
import { LogStorage, StorageItem } from './log-storage';
|
|
4
5
|
import { LogSender } from './log-sender';
|
|
6
|
+
import { LogService } from './log-service';
|
|
5
7
|
import { ConnectionService } from './connection-service';
|
|
6
8
|
import { GlobalErrorHandler } from './global-error-handler';
|
|
7
|
-
export
|
|
8
|
-
export { ArbitaryData, LogInfo, LogWarning, LogError, ILog, LogEntryType, LogEntry, EntryComplete, EntryCompleteError, Log, LOG_CONFIG_TOKEN, LogConfig, LogConfigProvider, LogStorage, StorageItem, LogSender, ConnectionService, GlobalErrorHandler, };
|
|
9
|
+
export { ArbitaryData, bindLog, ConnectionService, EntryComplete, EntryCompleteError, GlobalErrorHandler, ILog, LOG_CONFIG_TOKEN, Log, LogConfig, LogConfigProvider, LogEntry, LogEntryType, LogError, LogInfo, LogSender, LogService, LogStorage, LogWarning, StorageItem, };
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EACH,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,IAAI,EACJ,gBAAgB,EAChB,GAAG,EACH,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,OAAO,EACP,UAAU,EACb,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D,OAAO,EACH,YAAY,EACZ,OAAO,EACP,iBAAiB,EACjB,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,IAAI,EACJ,gBAAgB,EAChB,GAAG,EACH,SAAS,EACT,iBAAiB,EACjB,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,OAAO,EACP,SAAS,EACT,UAAU,EACV,UAAU,EACV,UAAU,EACV,WAAW,GACd,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { bindLog } from './bind-log';
|
|
2
|
+
import { LOG_CONFIG_TOKEN, Log, LogEntryType, } from './log';
|
|
3
|
+
import { LogConfigProvider } from './log-config-provider';
|
|
2
4
|
import { LogStorage } from './log-storage';
|
|
3
5
|
import { LogSender } from './log-sender';
|
|
6
|
+
import { LogService } from './log-service';
|
|
4
7
|
import { ConnectionService } from './connection-service';
|
|
5
8
|
import { GlobalErrorHandler } from './global-error-handler';
|
|
6
|
-
export
|
|
7
|
-
container.bind(LOG_CONFIG_TOKEN).toConstantValue({ endpoint: '/Log/Send' });
|
|
8
|
-
container.bind(LogStorage).toSelf().inSingletonScope();
|
|
9
|
-
container.bind(Log).to(Log).inSingletonScope();
|
|
10
|
-
container.bind(ConnectionService).toSelf().inSingletonScope();
|
|
11
|
-
container.bind(LogSender).toSelf().inSingletonScope();
|
|
12
|
-
container.bind(GlobalErrorHandler).toSelf().inSingletonScope();
|
|
13
|
-
}
|
|
14
|
-
export { LogEntryType, Log, LOG_CONFIG_TOKEN, LogConfigProvider, LogStorage, LogSender, ConnectionService, GlobalErrorHandler, };
|
|
9
|
+
export { bindLog, ConnectionService, GlobalErrorHandler, LOG_CONFIG_TOKEN, Log, LogConfigProvider, LogEntryType, LogSender, LogService, LogStorage, };
|
|
15
10
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAKH,gBAAgB,EAChB,GAAG,EAGH,YAAY,GAIf,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAe,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D,OAAO,EAEH,OAAO,EACP,iBAAiB,EAGjB,kBAAkB,EAElB,gBAAgB,EAChB,GAAG,EAEH,iBAAiB,EAEjB,YAAY,EAGZ,SAAS,EACT,UAAU,EACV,UAAU,GAGb,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FC, PropsWithChildren } from 'react';
|
|
2
|
+
import { LogConfig } from './log-config';
|
|
3
|
+
declare type LogConfigProviderProps = PropsWithChildren<{
|
|
4
|
+
value: LogConfig;
|
|
5
|
+
}>;
|
|
6
|
+
export declare const LogConfigProvider: FC<LogConfigProviderProps>;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=log-config-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-config-provider.d.ts","sourceRoot":"","sources":["../src/log-config-provider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE9C,OAAO,EAAoB,SAAS,EAAE,MAAM,cAAc,CAAC;AAE3D,aAAK,sBAAsB,GAAG,iBAAiB,CAAC;IAAE,KAAK,EAAE,SAAS,CAAA;CAAE,CAAC,CAAC;AAEtE,eAAO,MAAM,iBAAiB,EAAE,EAAE,CAAC,sBAAsB,CAExD,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Provider } from '@servicetitan/react-ioc';
|
|
3
|
+
import { LOG_CONFIG_TOKEN } from './log-config';
|
|
4
|
+
export const LogConfigProvider = ({ value, children }) => (_jsx(Provider, Object.assign({ singletons: [{ provide: LOG_CONFIG_TOKEN, useValue: value }] }, { children: children })));
|
|
5
|
+
//# sourceMappingURL=log-config-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-config-provider.js","sourceRoot":"","sources":["../src/log-config-provider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAGnD,OAAO,EAAE,gBAAgB,EAAa,MAAM,cAAc,CAAC;AAI3D,MAAM,CAAC,MAAM,iBAAiB,GAA+B,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAClF,KAAC,QAAQ,kBAAC,UAAU,EAAE,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,gBAAG,QAAQ,IAAY,CAChG,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const LOG_CONFIG_TOKEN: import("@servicetitan/react-ioc").SymbolToken<LogConfig>;
|
|
2
|
+
export interface LogConfig {
|
|
3
|
+
endpoint: string;
|
|
4
|
+
storageKey: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const defaultLogConfig: LogConfig;
|
|
7
|
+
//# sourceMappingURL=log-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-config.d.ts","sourceRoot":"","sources":["../src/log-config.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB,0DAA6C,CAAC;AAE3E,MAAM,WAAW,SAAS;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,gBAAgB,EAAE,SAG9B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-config.js","sourceRoot":"","sources":["../src/log-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,MAAM,CAAC,MAAM,gBAAgB,GAAG,WAAW,CAAY,kBAAkB,CAAC,CAAC;AAO3E,MAAM,CAAC,MAAM,gBAAgB,GAAc;IACvC,QAAQ,EAAE,WAAW;IACrB,UAAU,EAAE,YAAY;CAC3B,CAAC"}
|
package/dist/log-sender.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { ConnectionService } from './connection-service';
|
|
1
2
|
import { LogConfig, Log } from './log';
|
|
2
3
|
import { LogStorage } from './log-storage';
|
|
3
|
-
import { ConnectionService } from './connection-service';
|
|
4
4
|
export declare class LogSender {
|
|
5
5
|
readonly connectionService: ConnectionService;
|
|
6
6
|
readonly logStorage: LogStorage;
|
package/dist/log-sender.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log-sender.d.ts","sourceRoot":"","sources":["../src/log-sender.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"log-sender.d.ts","sourceRoot":"","sources":["../src/log-sender.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAoB,GAAG,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,UAAU,EAAuB,MAAM,eAAe,CAAC;AAEhE,qBACa,SAAS;IAgBa,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB;IACpD,QAAQ,CAAC,UAAU,EAAE,UAAU;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS;IACvC,QAAQ,CAAC,GAAG,EAAE,GAAG;IAlBlC,OAAO,CAAC,SAAS,CAAS;IAE1B,OAAO,CAAC,SAAS,CAAO;IAExB,OAAO,CAAC,eAAe,CAAa;IACpC,OAAO,CAAC,mBAAmB,CAAQ;IACnC,OAAO,CAAC,oBAAoB,CAA4B;IACxD,OAAO,CAAC,mBAAmB,CAAkC;IAE7D,OAAO,CAAC,uBAAuB,CAAS;IAExC,OAAO,CAAC,YAAY,CAAC,CAAS;IAC9B,OAAO,CAAC,sBAAsB,CAAC,CAAoB;gBAGX,iBAAiB,EAAE,iBAAiB,EAC3C,UAAU,EAAE,UAAU,EACR,SAAS,EAAE,SAAS,EACzC,GAAG,EAAE,GAAG;IAMlC,OAAO,CAAC,cAAc;IAOtB,OAAO,CAAC,eAAe;YAST,IAAI;IAgDlB,OAAO,CAAC,sBAAsB;IAW9B,OAAO,CAAC,mBAAmB;IAO3B,OAAO,CAAC,oBAAoB;CAQ/B"}
|
package/dist/log-sender.js
CHANGED
|
@@ -22,9 +22,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
22
22
|
import axios from 'axios';
|
|
23
23
|
import { injectable, inject } from '@servicetitan/react-ioc';
|
|
24
24
|
import { reaction } from 'mobx';
|
|
25
|
+
import { ConnectionService } from './connection-service';
|
|
25
26
|
import { LOG_CONFIG_TOKEN, Log } from './log';
|
|
26
27
|
import { LogStorage, lastId } from './log-storage';
|
|
27
|
-
import { ConnectionService } from './connection-service';
|
|
28
28
|
let LogSender = class LogSender {
|
|
29
29
|
constructor(connectionService, logStorage, logConfig, log) {
|
|
30
30
|
Object.defineProperty(this, "connectionService", {
|
package/dist/log-sender.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log-sender.js","sourceRoot":"","sources":["../src/log-sender.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAqB,MAAM,MAAM,CAAC;AAEnD,OAAO,
|
|
1
|
+
{"version":3,"file":"log-sender.js","sourceRoot":"","sources":["../src/log-sender.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,U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AAE,iBAAiB,EAAW,MAAM,OAAO,CAAC;AAavD,MAAM,WAAW,eAAgB,SAAQ,iBAAiB,CAAC,EAAE,CAAC;IAC1D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,eAAO,MAAM,UAAU,EAAE,EAAE,CAAC,eAAe,CA2B1C,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { Provider, useDependencies, useOptionalDependencies, } from '@servicetitan/react-ioc';
|
|
4
|
+
import { ConnectionService } from './connection-service';
|
|
5
|
+
import { LOG_PARENT_TOKEN, Log } from './log';
|
|
6
|
+
import { LOG_CONFIG_TOKEN, defaultLogConfig } from './log-config';
|
|
7
|
+
import { LogSender } from './log-sender';
|
|
8
|
+
import { LogStorage } from './log-storage';
|
|
9
|
+
export const LogService = ({ children, endpoint = defaultLogConfig.endpoint, storageKey = defaultLogConfig.storageKey, }) => {
|
|
10
|
+
const [parentLog] = useOptionalDependencies(Log);
|
|
11
|
+
const singletons = useMemo(() => {
|
|
12
|
+
const result = [
|
|
13
|
+
{ provide: LOG_CONFIG_TOKEN, useValue: { endpoint, storageKey } },
|
|
14
|
+
ConnectionService,
|
|
15
|
+
Log,
|
|
16
|
+
LogStorage,
|
|
17
|
+
LogSender,
|
|
18
|
+
];
|
|
19
|
+
if (parentLog) {
|
|
20
|
+
result.push({ provide: LOG_PARENT_TOKEN, useValue: parentLog });
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
}, [endpoint, parentLog, storageKey]);
|
|
24
|
+
return (_jsxs(Provider, Object.assign({ singletons: singletons }, { children: [_jsx(InitializeLogSender, {}), children] })));
|
|
25
|
+
};
|
|
26
|
+
const InitializeLogSender = () => {
|
|
27
|
+
useDependencies(LogSender);
|
|
28
|
+
return null;
|
|
29
|
+
};
|
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AAQ,kBAAC,UAAU,EAAE,UAAU,iBAC5B,KAAC,mBAAmB,KAAG,EACtB,QAAQ,KACF,CACd,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,mBAAmB,GAAO,GAAG,EAAE;IACjC,eAAe,CAAC,SAAS,CAAC,CAAC;IAC3B,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC"}
|
package/dist/log-storage.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EntryComplete, Nullable } from './log';
|
|
2
|
+
import { LogConfig } from './log-config';
|
|
2
3
|
export interface StorageItem {
|
|
3
4
|
id: number;
|
|
4
5
|
type: string;
|
|
@@ -9,15 +10,19 @@ export interface StorageItem {
|
|
|
9
10
|
exception: string;
|
|
10
11
|
}
|
|
11
12
|
export declare class LogStorage {
|
|
13
|
+
private readonly logConfig;
|
|
12
14
|
items: StorageItem[];
|
|
13
15
|
private readonly maxLogSize;
|
|
14
16
|
private readonly version;
|
|
15
17
|
private nextItemId;
|
|
16
|
-
constructor();
|
|
18
|
+
constructor(logConfig: LogConfig);
|
|
19
|
+
get config(): LogConfig;
|
|
17
20
|
store(entry: EntryComplete): void;
|
|
18
21
|
deleteToId(id: number): void;
|
|
19
22
|
loadBatch(batchSize: number): StorageItem[];
|
|
20
23
|
private setItems;
|
|
24
|
+
private get storageKey();
|
|
25
|
+
private get storageVersionKey();
|
|
21
26
|
private stringifyError;
|
|
22
27
|
}
|
|
23
28
|
export declare function lastId(items: StorageItem[]): number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log-storage.d.ts","sourceRoot":"","sources":["../src/log-storage.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"log-storage.d.ts","sourceRoot":"","sources":["../src/log-storage.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAChD,OAAO,EAAoB,SAAS,EAAE,MAAM,cAAc,CAAC;AAE3D,MAAM,WAAW,WAAW;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC3B,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACvB,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,qBACa,UAAU;IASmB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAPhE,KAAK,EAAE,WAAW,EAAE,CAAM;IAE1B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAQ;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAK;IAE7B,OAAO,CAAC,UAAU,CAAS;gBAE4B,SAAS,EAAE,SAAS;IA2B3E,IAAI,MAAM,IAAI,SAAS,CAEtB;IAED,KAAK,CAAC,KAAK,EAAE,aAAa;IAgB1B,UAAU,CAAC,EAAE,EAAE,MAAM;IAKrB,SAAS,CAAC,SAAS,EAAE,MAAM;IAK3B,OAAO,CAAC,QAAQ;IAKhB,OAAO,KAAK,UAAU,GAErB;IAED,OAAO,KAAK,iBAAiB,GAE5B;IAED,OAAO,CAAC,cAAc;CAIzB;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,MAAM,CAMnD"}
|
package/dist/log-storage.js
CHANGED
|
@@ -7,13 +7,21 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import { inject, injectable } from '@servicetitan/react-ioc';
|
|
11
14
|
import { observable, action, makeObservable } from 'mobx';
|
|
12
|
-
|
|
13
|
-
const storageKey = 'LogStorage';
|
|
15
|
+
import { LOG_CONFIG_TOKEN } from './log-config';
|
|
14
16
|
let LogStorage = class LogStorage {
|
|
15
|
-
constructor() {
|
|
17
|
+
constructor(logConfig) {
|
|
16
18
|
var _a;
|
|
19
|
+
Object.defineProperty(this, "logConfig", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true,
|
|
23
|
+
value: logConfig
|
|
24
|
+
});
|
|
17
25
|
Object.defineProperty(this, "items", {
|
|
18
26
|
enumerable: true,
|
|
19
27
|
configurable: true,
|
|
@@ -39,13 +47,13 @@ let LogStorage = class LogStorage {
|
|
|
39
47
|
value: void 0
|
|
40
48
|
});
|
|
41
49
|
makeObservable(this);
|
|
42
|
-
const version = window.parseInt(localStorage.getItem(storageVersionKey));
|
|
50
|
+
const version = window.parseInt(localStorage.getItem(this.storageVersionKey));
|
|
43
51
|
if (version !== this.version) {
|
|
44
|
-
localStorage.removeItem(storageKey);
|
|
45
|
-
localStorage.setItem(storageVersionKey, String(this.version));
|
|
52
|
+
localStorage.removeItem(this.storageKey);
|
|
53
|
+
localStorage.setItem(this.storageVersionKey, String(this.version));
|
|
46
54
|
}
|
|
47
55
|
try {
|
|
48
|
-
const items = (_a = JSON.parse(localStorage.getItem(storageKey))) !== null && _a !== void 0 ? _a : [];
|
|
56
|
+
const items = (_a = JSON.parse(localStorage.getItem(this.storageKey))) !== null && _a !== void 0 ? _a : [];
|
|
49
57
|
/* migrate error -> exception */
|
|
50
58
|
items.forEach((item) => {
|
|
51
59
|
if (typeof item.error === 'string') {
|
|
@@ -60,6 +68,9 @@ let LogStorage = class LogStorage {
|
|
|
60
68
|
}
|
|
61
69
|
this.nextItemId = lastId(this.items);
|
|
62
70
|
}
|
|
71
|
+
get config() {
|
|
72
|
+
return this.logConfig;
|
|
73
|
+
}
|
|
63
74
|
store(entry) {
|
|
64
75
|
const item = {
|
|
65
76
|
id: this.nextItemId++,
|
|
@@ -83,17 +94,17 @@ let LogStorage = class LogStorage {
|
|
|
83
94
|
}
|
|
84
95
|
setItems(items) {
|
|
85
96
|
this.items = [...items];
|
|
86
|
-
localStorage.setItem(storageKey, JSON.stringify(this.items));
|
|
97
|
+
localStorage.setItem(this.storageKey, JSON.stringify(this.items));
|
|
98
|
+
}
|
|
99
|
+
get storageKey() {
|
|
100
|
+
return this.logConfig.storageKey;
|
|
101
|
+
}
|
|
102
|
+
get storageVersionKey() {
|
|
103
|
+
return `${this.storageKey}Version`;
|
|
87
104
|
}
|
|
88
105
|
stringifyError(error) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
repr = {
|
|
92
|
-
message: error.message.toString(),
|
|
93
|
-
stack: error.stack,
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
return JSON.stringify(repr);
|
|
106
|
+
const detail = error ? { message: error.message.toString(), stack: error.stack } : null;
|
|
107
|
+
return JSON.stringify(detail);
|
|
97
108
|
}
|
|
98
109
|
};
|
|
99
110
|
__decorate([
|
|
@@ -108,7 +119,8 @@ __decorate([
|
|
|
108
119
|
], LogStorage.prototype, "setItems", null);
|
|
109
120
|
LogStorage = __decorate([
|
|
110
121
|
injectable(),
|
|
111
|
-
|
|
122
|
+
__param(0, inject(LOG_CONFIG_TOKEN)),
|
|
123
|
+
__metadata("design:paramtypes", [Object])
|
|
112
124
|
], LogStorage);
|
|
113
125
|
export { LogStorage };
|
|
114
126
|
export function lastId(items) {
|
package/dist/log-storage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log-storage.js","sourceRoot":"","sources":["../src/log-storage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"log-storage.js","sourceRoot":"","sources":["../src/log-storage.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,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AI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACtE,CAAC;IAED,IAAY,UAAU;QAClB,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;IACrC,CAAC;IAED,IAAY,iBAAiB;QACzB,OAAO,GAAG,IAAI,CAAC,UAAU,SAAS,CAAC;IACvC,CAAC;IAEO,cAAc,CAAC,KAAsB;QACzC,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QACxF,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;CACJ,CAAA;AAjFG;IADC,UAAU;;yCACe;AAgE1B;IADC,MAAM;;;;0CAIN;AArEQ,UAAU;IADtB,UAAU,EAAE;IAUI,WAAA,MAAM,CAAC,gBAAgB,CAAC,CAAA;;GAT5B,UAAU,CAmFtB;SAnFY,UAAU;AAqFvB,MAAM,UAAU,MAAM,CAAC,KAAoB;IACvC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;QACf,OAAO,CAAC,CAAC;KACZ;IACD,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACrC,OAAO,IAAI,CAAC,EAAE,CAAC;AACnB,CAAC"}
|
package/dist/log.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FC, PropsWithChildren } from 'react';
|
|
2
1
|
import { LogStorage } from './log-storage';
|
|
2
|
+
export { LOG_CONFIG_TOKEN, LogConfig } from './log-config';
|
|
3
3
|
export interface ArbitaryData extends Record<string, boolean | number | string | Date> {
|
|
4
4
|
}
|
|
5
5
|
export interface LogEntry {
|
|
@@ -37,18 +37,12 @@ export interface EntryComplete {
|
|
|
37
37
|
export declare type EntryCompleteError = EntryComplete & {
|
|
38
38
|
error: Error;
|
|
39
39
|
};
|
|
40
|
-
export
|
|
41
|
-
endpoint: string;
|
|
42
|
-
}
|
|
43
|
-
export declare const LOG_CONFIG_TOKEN: import("@servicetitan/react-ioc").SymbolToken<LogConfig>;
|
|
44
|
-
declare type LogConfigProviderProps = PropsWithChildren<{
|
|
45
|
-
value: LogConfig;
|
|
46
|
-
}>;
|
|
47
|
-
export declare const LogConfigProvider: FC<LogConfigProviderProps>;
|
|
40
|
+
export declare const LOG_PARENT_TOKEN: import("@servicetitan/react-ioc").SymbolToken<Log>;
|
|
48
41
|
export declare class Log implements ILog {
|
|
49
42
|
private readonly logStorage;
|
|
43
|
+
private readonly parent?;
|
|
50
44
|
private errorLogHandler;
|
|
51
|
-
constructor(logStorage: LogStorage);
|
|
45
|
+
constructor(logStorage: LogStorage, parent?: Log | undefined);
|
|
52
46
|
info(entry: LogInfo): void;
|
|
53
47
|
warning(entry: LogWarning): void;
|
|
54
48
|
error(entry: LogError): void;
|
|
@@ -56,6 +50,6 @@ export declare class Log implements ILog {
|
|
|
56
50
|
private expand;
|
|
57
51
|
private expandError;
|
|
58
52
|
private dataDefault;
|
|
53
|
+
private validate;
|
|
59
54
|
}
|
|
60
|
-
export {};
|
|
61
55
|
//# sourceMappingURL=log.d.ts.map
|
package/dist/log.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.
|
|
1
|
+
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE3D,MAAM,WAAW,YAAa,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;CAAG;AAEzF,MAAM,WAAW,QAAQ;IAC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EACJ,MAAM,CAAC,iBAAK;IAMvE,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IAK1B,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAKhC,KAAK,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAO5B,OAAO,CAAC,KAAK;IAIb,OAAO,CAAC,MAAM;IAiBd,OAAO,CAAC,WAAW;IAiBnB,OAAO,CAAC,WAAW;IAYnB,OAAO,CAAC,QAAQ;CAUnB"}
|
package/dist/log.js
CHANGED
|
@@ -21,42 +21,55 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
21
21
|
}
|
|
22
22
|
return t;
|
|
23
23
|
};
|
|
24
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
25
24
|
import throttle from 'lodash.throttle';
|
|
26
|
-
import { injectable, inject,
|
|
25
|
+
import { injectable, inject, optional, symbolToken } from '@servicetitan/react-ioc';
|
|
26
|
+
import { defaultLogConfig } from './log-config';
|
|
27
27
|
import { LogStorage } from './log-storage';
|
|
28
28
|
import { serializeWithMetadata } from './serialize-with-metadata';
|
|
29
|
+
export { LOG_CONFIG_TOKEN } from './log-config';
|
|
29
30
|
export var LogEntryType;
|
|
30
31
|
(function (LogEntryType) {
|
|
31
32
|
LogEntryType["Info"] = "Info";
|
|
32
33
|
LogEntryType["Warning"] = "Warning";
|
|
33
34
|
LogEntryType["Error"] = "Error";
|
|
34
35
|
})(LogEntryType || (LogEntryType = {}));
|
|
35
|
-
export const
|
|
36
|
-
export const LogConfigProvider = ({ value, children }) => (_jsx(Provider, Object.assign({ singletons: [{ provide: LOG_CONFIG_TOKEN, useValue: value }] }, { children: children })));
|
|
36
|
+
export const LOG_PARENT_TOKEN = symbolToken('LOG_PARENT_TOKEN');
|
|
37
37
|
let Log = class Log {
|
|
38
|
-
constructor(logStorage) {
|
|
38
|
+
constructor(logStorage, parent) {
|
|
39
39
|
Object.defineProperty(this, "logStorage", {
|
|
40
40
|
enumerable: true,
|
|
41
41
|
configurable: true,
|
|
42
42
|
writable: true,
|
|
43
43
|
value: logStorage
|
|
44
44
|
});
|
|
45
|
+
Object.defineProperty(this, "parent", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
configurable: true,
|
|
48
|
+
writable: true,
|
|
49
|
+
value: parent
|
|
50
|
+
});
|
|
45
51
|
Object.defineProperty(this, "errorLogHandler", {
|
|
46
52
|
enumerable: true,
|
|
47
53
|
configurable: true,
|
|
48
54
|
writable: true,
|
|
49
55
|
value: void 0
|
|
50
56
|
});
|
|
57
|
+
this.validate();
|
|
51
58
|
this.errorLogHandler = new ErrorLogHandler(this, this.logStorage);
|
|
52
59
|
}
|
|
53
60
|
info(entry) {
|
|
61
|
+
var _a;
|
|
62
|
+
(_a = this.parent) === null || _a === void 0 ? void 0 : _a.info(entry);
|
|
54
63
|
return this.store(this.expand(LogEntryType.Info, entry));
|
|
55
64
|
}
|
|
56
65
|
warning(entry) {
|
|
66
|
+
var _a;
|
|
67
|
+
(_a = this.parent) === null || _a === void 0 ? void 0 : _a.warning(entry);
|
|
57
68
|
return this.store(this.expand(LogEntryType.Warning, entry));
|
|
58
69
|
}
|
|
59
70
|
error(entry) {
|
|
71
|
+
var _a;
|
|
72
|
+
(_a = this.parent) === null || _a === void 0 ? void 0 : _a.error(entry);
|
|
60
73
|
// eslint-disable-next-line no-console
|
|
61
74
|
console.error('@log-service/error', entry);
|
|
62
75
|
return this.errorLogHandler.handle(this.expandError(entry)); // with errorLogHandler throttling
|
|
@@ -80,13 +93,25 @@ let Log = class Log {
|
|
|
80
93
|
return Object.assign(Object.assign({ message: message !== null && message !== void 0 ? message : error.message }, rest), { error });
|
|
81
94
|
}
|
|
82
95
|
dataDefault() {
|
|
83
|
-
return Object.assign({ CreatedOn: new Date(), Online: window.navigator.onLine, Url: window.location.toString(), UserAgent: window.navigator.userAgent, Source: 'Frontend', Plugins: plugins() },
|
|
96
|
+
return Object.assign({ CreatedOn: new Date(), Online: window.navigator.onLine, Url: window.location.toString(), UserAgent: window.navigator.userAgent, Source: 'Frontend', Plugins: plugins() }, timezoneInfo());
|
|
97
|
+
}
|
|
98
|
+
validate() {
|
|
99
|
+
if (!this.parent) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const { endpoint, storageKey } = this.logStorage.config;
|
|
103
|
+
if (endpoint === defaultLogConfig.endpoint || storageKey === defaultLogConfig.storageKey) {
|
|
104
|
+
throw new Error('nested Log cannot use default configuration');
|
|
105
|
+
}
|
|
84
106
|
}
|
|
85
107
|
};
|
|
86
108
|
Log = __decorate([
|
|
87
109
|
injectable(),
|
|
88
110
|
__param(0, inject(LogStorage)),
|
|
89
|
-
|
|
111
|
+
__param(1, inject(LOG_PARENT_TOKEN)),
|
|
112
|
+
__param(1, optional()),
|
|
113
|
+
__metadata("design:paramtypes", [LogStorage,
|
|
114
|
+
Log])
|
|
90
115
|
], Log);
|
|
91
116
|
export { Log };
|
|
92
117
|
class ErrorLogHandler {
|
|
@@ -147,14 +172,14 @@ class ErrorLogHandler {
|
|
|
147
172
|
add(entry) {
|
|
148
173
|
const key = this.keyFor(entry);
|
|
149
174
|
if (this.repetitiveLogsCache.get(key)) {
|
|
150
|
-
/* error is a
|
|
175
|
+
/* error is a repetitive error and has been reported, we don't need to report it again */
|
|
151
176
|
return;
|
|
152
177
|
}
|
|
153
178
|
if (this.logTable.get(key) == null) {
|
|
154
179
|
this.logTable.set(key, entry);
|
|
155
180
|
}
|
|
156
181
|
else {
|
|
157
|
-
/* present in entry table, hence a duplicate,
|
|
182
|
+
/* present in entry table, hence a duplicate, don't set, rather increase count */
|
|
158
183
|
const entry = this.logTable.get(key);
|
|
159
184
|
if (typeof entry.data.count === 'number') {
|
|
160
185
|
entry.data.count++;
|
|
@@ -218,7 +243,7 @@ function plugins() {
|
|
|
218
243
|
return 'unknown';
|
|
219
244
|
}
|
|
220
245
|
}
|
|
221
|
-
function
|
|
246
|
+
function timezoneInfo() {
|
|
222
247
|
// https://stackoverflow.com/questions/11887934/how-to-check-if-dst-daylight-saving-time-is-in-effect-and-if-so-the-offset
|
|
223
248
|
const now = new Date();
|
|
224
249
|
const jan = new Date(now.getFullYear(), 0, 1);
|
package/dist/log.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.js","sourceRoot":"","sources":["../src/log.
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEpF,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAElE,OAAO,EAAE,gBAAgB,EAAa,MAAM,cAAc,CAAC;AAyB3D,MAAM,CAAN,IAAY,YAIX;AAJD,WAAY,YAAY;IACpB,6BAAa,CAAA;IACb,mCAAmB,CAAA;IACnB,+BAAe,CAAA;AACnB,CAAC,EAJW,YAAY,KAAZ,YAAY,QAIvB;AAiBD,MAAM,CAAC,MAAM,gBAAgB,GAAG,WAAW,CAAM,kBAAkB,CAAC,CAAC;AAGrE,IAAa,GAAG,GAAhB,MAAa,GAAG;IAGZ,YACyC,UAAsB,EACJ,MAAY;;;;;mBAD9B;;;;;;mBACkB;;QAJ3D;;;;;WAAyC;QAMrC,IAAI,CAAC,QAAQ,EAAE,CAAC;QAChB,IAAI,CAAC,eAAe,GAAG,IAAI,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACtE,CAAC;IAED,IAAI,CAAC,KAAc;;QACf,MAAA,IAAI,CAAC,MAAM,0CAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QACzB,OAAO,IAAI,CAA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
3
|
+
"version": "23.5.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"homepage": "https://docs.st.dev/docs/frontend/log-service",
|
|
6
6
|
"repository": {
|
|
@@ -16,15 +16,15 @@
|
|
|
16
16
|
"src"
|
|
17
17
|
],
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@servicetitan/react-ioc": "23.
|
|
20
|
-
"@testing-library/react": "^
|
|
19
|
+
"@servicetitan/react-ioc": "23.5.1",
|
|
20
|
+
"@testing-library/react": "^15.0.6",
|
|
21
21
|
"@types/lodash.throttle": "~4.1.6",
|
|
22
22
|
"axios": "~0.28.0",
|
|
23
23
|
"mobx": "~6.10.2",
|
|
24
|
-
"react": "~18.
|
|
24
|
+
"react": "~18.3.1"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@servicetitan/react-ioc": "23.
|
|
27
|
+
"@servicetitan/react-ioc": "23.5.1",
|
|
28
28
|
"axios": "~0.28.0",
|
|
29
29
|
"mobx": ">=6.10.0",
|
|
30
30
|
"react": ">=17.0.2"
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"cli": {
|
|
39
39
|
"webpack": false
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "afaf6f83281aa08beea5d57952c712108894654b"
|
|
42
42
|
}
|
|
@@ -2,10 +2,11 @@ import { useDependencies } from '@servicetitan/react-ioc';
|
|
|
2
2
|
import { render } from '@testing-library/react';
|
|
3
3
|
import { FC } from 'react';
|
|
4
4
|
|
|
5
|
-
import { LOG_CONFIG_TOKEN, LogConfig
|
|
5
|
+
import { LOG_CONFIG_TOKEN, LogConfig } from '../log-config';
|
|
6
|
+
import { LogConfigProvider } from '../log-config-provider';
|
|
6
7
|
|
|
7
8
|
describe(`[log-service] ${LogConfigProvider.name}`, () => {
|
|
8
|
-
const logConfig: LogConfig = { endpoint: '
|
|
9
|
+
const logConfig: LogConfig = { endpoint: '/Log/Foo', storageKey: 'LogStorage_Foo' };
|
|
9
10
|
let providedLogConfig: LogConfig;
|
|
10
11
|
|
|
11
12
|
const Wrapper: FC = () => {
|
|
@@ -30,7 +30,7 @@ const MINUTE = 60 * SECOND;
|
|
|
30
30
|
|
|
31
31
|
describe(`[log-service] ${LogSender.name}`, () => {
|
|
32
32
|
const connectionService = new ConnectionService();
|
|
33
|
-
const logConfig: LogConfig = { endpoint: '
|
|
33
|
+
const logConfig: LogConfig = { endpoint: '/Log/Foo', storageKey: 'LogStorage_Foo' };
|
|
34
34
|
let logStorage: LogStorage;
|
|
35
35
|
let log: Pick<Log, 'info' | 'warning'>;
|
|
36
36
|
|
|
@@ -43,7 +43,7 @@ describe(`[log-service] ${LogSender.name}`, () => {
|
|
|
43
43
|
jest.clearAllMocks();
|
|
44
44
|
jest.spyOn(axios, 'post').mockImplementation(jest.fn());
|
|
45
45
|
|
|
46
|
-
logStorage = new LogStorage();
|
|
46
|
+
logStorage = new LogStorage(logConfig);
|
|
47
47
|
log = new MockLog(logStorage);
|
|
48
48
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
49
49
|
const logSender = new LogSender(connectionService, logStorage, logConfig, log as Log);
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Provider,
|
|
4
|
+
ProviderProps,
|
|
5
|
+
useDependencies,
|
|
6
|
+
useOptionalDependencies,
|
|
7
|
+
} from '@servicetitan/react-ioc';
|
|
8
|
+
import { render } from '@testing-library/react';
|
|
9
|
+
import { LOG_CONFIG_TOKEN, LOG_PARENT_TOKEN, Log, LogConfig } from '../log';
|
|
10
|
+
import { defaultLogConfig } from '../log-config';
|
|
11
|
+
import { LogStorage } from '../log-storage';
|
|
12
|
+
|
|
13
|
+
import { LogService, LogServiceProps } from '../log-service';
|
|
14
|
+
|
|
15
|
+
describe(`[log-service] ${LogService.name}`, () => {
|
|
16
|
+
let props: LogServiceProps;
|
|
17
|
+
let providedLog: Log;
|
|
18
|
+
let providedLogConfig: LogConfig;
|
|
19
|
+
let providedParent: Log | undefined;
|
|
20
|
+
let singletons: ProviderProps['singletons'];
|
|
21
|
+
|
|
22
|
+
const Component: FC = () => {
|
|
23
|
+
[providedLog, providedLogConfig] = useDependencies(Log, LOG_CONFIG_TOKEN);
|
|
24
|
+
[providedParent] = useOptionalDependencies(LOG_PARENT_TOKEN);
|
|
25
|
+
return null;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const subject = () => {
|
|
29
|
+
return render(
|
|
30
|
+
<Provider singletons={singletons}>
|
|
31
|
+
<LogService {...props}>
|
|
32
|
+
<Component />
|
|
33
|
+
</LogService>
|
|
34
|
+
</Provider>
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
test('provides Log instance', () => {
|
|
39
|
+
subject();
|
|
40
|
+
|
|
41
|
+
expect(providedLog).toBeInstanceOf(Log);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('defaults to endpoint "/Log/Send" and storageKey "LogStorage"', () => {
|
|
45
|
+
subject();
|
|
46
|
+
|
|
47
|
+
expect(providedLogConfig).toEqual({ endpoint: '/Log/Send', storageKey: 'LogStorage' });
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe.each(['endpoint', 'storageKey'] as (keyof LogConfig)[])(
|
|
51
|
+
'when "%s" is specified',
|
|
52
|
+
prop => {
|
|
53
|
+
beforeEach(() => (props = { [prop]: 'Foo' }));
|
|
54
|
+
|
|
55
|
+
test(`uses the specified ${prop}`, () => {
|
|
56
|
+
subject();
|
|
57
|
+
|
|
58
|
+
expect(providedLogConfig[prop]).toEqual(props[prop]);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
describe('with a parent log', () => {
|
|
64
|
+
const parent: Log = new Log(new LogStorage(defaultLogConfig));
|
|
65
|
+
|
|
66
|
+
beforeEach(() => {
|
|
67
|
+
singletons = [{ provide: Log, useValue: parent }];
|
|
68
|
+
props = { endpoint: '/Log/Foo', storageKey: 'LogStorage_Foo' };
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('provides parent Log', () => {
|
|
72
|
+
subject();
|
|
73
|
+
|
|
74
|
+
expect(providedParent).toBe(parent);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { EntryComplete, LogEntryType } from '../log';
|
|
2
|
+
import { LogConfig } from '../log-config';
|
|
2
3
|
import { LogStorage } from '../log-storage';
|
|
3
4
|
|
|
4
5
|
describe(`${LogStorage.name}`, () => {
|
|
5
|
-
const LOCAL_STORAGE_KEY = 'LogStorage';
|
|
6
6
|
const LOCAL_STORAGE_VERSION = '1';
|
|
7
|
-
const
|
|
7
|
+
const logConfig: LogConfig = { endpoint: '/Log/Foo', storageKey: 'LogStorage_Foo' };
|
|
8
8
|
|
|
9
9
|
beforeEach(() => window.localStorage.clear());
|
|
10
10
|
|
|
11
11
|
const subject = (entryOrEntries: EntryComplete | EntryComplete[] = []) => {
|
|
12
12
|
const entries = Array.isArray(entryOrEntries) ? entryOrEntries : [entryOrEntries];
|
|
13
|
-
const logStorage = new LogStorage();
|
|
13
|
+
const logStorage = new LogStorage(logConfig);
|
|
14
14
|
entries.forEach(entry => logStorage.store(entry));
|
|
15
15
|
return logStorage;
|
|
16
16
|
};
|
|
@@ -27,7 +27,7 @@ describe(`${LogStorage.name}`, () => {
|
|
|
27
27
|
const entries = createEntries(3);
|
|
28
28
|
|
|
29
29
|
beforeEach(() => {
|
|
30
|
-
const logStorage = new LogStorage();
|
|
30
|
+
const logStorage = new LogStorage(logConfig);
|
|
31
31
|
entries.map(entry => logStorage.store(entry));
|
|
32
32
|
});
|
|
33
33
|
|
|
@@ -40,20 +40,22 @@ describe(`${LogStorage.name}`, () => {
|
|
|
40
40
|
itLoadsSavedItems();
|
|
41
41
|
|
|
42
42
|
describe('when saved data has incompatible version', () => {
|
|
43
|
-
|
|
43
|
+
const storageVersionKey = `${logConfig.storageKey}Version`;
|
|
44
|
+
|
|
45
|
+
beforeEach(() => window.localStorage.setItem(storageVersionKey, '-1'));
|
|
44
46
|
|
|
45
47
|
itLoadsNoItems();
|
|
46
48
|
|
|
47
49
|
test('updates version', () => {
|
|
48
50
|
subject();
|
|
49
51
|
|
|
50
|
-
expect(localStorage.getItem(
|
|
52
|
+
expect(localStorage.getItem(storageVersionKey)).toBe(LOCAL_STORAGE_VERSION);
|
|
51
53
|
});
|
|
52
54
|
});
|
|
53
55
|
|
|
54
56
|
describe('when saved data is not valid', () => {
|
|
55
57
|
beforeEach(() => {
|
|
56
|
-
window.localStorage.setItem(
|
|
58
|
+
window.localStorage.setItem(logConfig.storageKey, '}{');
|
|
57
59
|
});
|
|
58
60
|
|
|
59
61
|
itLoadsNoItems();
|
|
@@ -62,9 +64,9 @@ describe(`${LogStorage.name}`, () => {
|
|
|
62
64
|
describe('when saved data contains old "error" field', () => {
|
|
63
65
|
beforeEach(() => {
|
|
64
66
|
const itemsWithErrorField = (
|
|
65
|
-
JSON.parse(localStorage.getItem(
|
|
67
|
+
JSON.parse(localStorage.getItem(logConfig.storageKey)!) as LogStorage['items']
|
|
66
68
|
).map(({ exception, ...rest }) => ({ ...rest, error: exception }));
|
|
67
|
-
localStorage.setItem(
|
|
69
|
+
localStorage.setItem(logConfig.storageKey, JSON.stringify(itemsWithErrorField));
|
|
68
70
|
});
|
|
69
71
|
|
|
70
72
|
itLoadsSavedItems();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Log, LogEntry, LogEntryType } from '../log';
|
|
1
|
+
import { Log, LogConfig, LogEntry, LogEntryType } from '../log';
|
|
2
|
+
import { defaultLogConfig } from '../log-config';
|
|
2
3
|
import { LogStorage } from '../log-storage';
|
|
3
4
|
import { serializeWithMetadata } from '../serialize-with-metadata';
|
|
4
5
|
|
|
@@ -6,7 +7,9 @@ const SECOND = 1000;
|
|
|
6
7
|
const THROTTLE_INTERVAL = 30 * SECOND;
|
|
7
8
|
|
|
8
9
|
describe(`[log-service] ${Log.name}`, () => {
|
|
10
|
+
const logConfig: LogConfig = { endpoint: '/Log/Foo', storageKey: 'LogStorage_Foo' };
|
|
9
11
|
const entry: LogEntry = { category: 'category', code: 'code', message: 'foo' };
|
|
12
|
+
let parentLog: Log;
|
|
10
13
|
|
|
11
14
|
beforeAll(() => jest.useFakeTimers());
|
|
12
15
|
|
|
@@ -17,8 +20,8 @@ describe(`[log-service] ${Log.name}`, () => {
|
|
|
17
20
|
});
|
|
18
21
|
|
|
19
22
|
const subject = () => {
|
|
20
|
-
const logStorage = new LogStorage();
|
|
21
|
-
const log = new Log(logStorage);
|
|
23
|
+
const logStorage = new LogStorage(logConfig);
|
|
24
|
+
const log = new Log(logStorage, parentLog);
|
|
22
25
|
jest.spyOn(logStorage, 'store');
|
|
23
26
|
return { log, logStorage };
|
|
24
27
|
};
|
|
@@ -164,4 +167,31 @@ describe(`[log-service] ${Log.name}`, () => {
|
|
|
164
167
|
});
|
|
165
168
|
});
|
|
166
169
|
});
|
|
170
|
+
|
|
171
|
+
describe('when log has parent', () => {
|
|
172
|
+
beforeEach(() => (parentLog = new Log(new LogStorage(defaultLogConfig))));
|
|
173
|
+
|
|
174
|
+
test.each(['info', 'warning', 'error'] as (keyof Log)[])(
|
|
175
|
+
'forwards %s to parent log',
|
|
176
|
+
method => {
|
|
177
|
+
jest.spyOn(parentLog, method);
|
|
178
|
+
|
|
179
|
+
const logEntry = { ...entry, error: new Error('Oops!') };
|
|
180
|
+
subject().log[method](logEntry);
|
|
181
|
+
|
|
182
|
+
expect(parentLog[method]).toHaveBeenCalledWith(logEntry);
|
|
183
|
+
}
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
describe.each(['endpoint', 'storageKey'] as (keyof LogConfig)[])(
|
|
187
|
+
'when log uses default %s',
|
|
188
|
+
key => {
|
|
189
|
+
beforeEach(() => (logConfig[key] = defaultLogConfig[key]));
|
|
190
|
+
|
|
191
|
+
test('throws error', () => {
|
|
192
|
+
expect(() => subject()).toThrow(/cannot use default configuration/);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
);
|
|
196
|
+
});
|
|
167
197
|
});
|
package/src/bind-log.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Container } from '@servicetitan/react-ioc';
|
|
2
|
+
|
|
3
|
+
import { ConnectionService } from './connection-service';
|
|
4
|
+
import { GlobalErrorHandler } from './global-error-handler';
|
|
5
|
+
import { Log } from './log';
|
|
6
|
+
import { LOG_CONFIG_TOKEN, LogConfig, defaultLogConfig } from './log-config';
|
|
7
|
+
import { LogSender } from './log-sender';
|
|
8
|
+
import { LogStorage } from './log-storage';
|
|
9
|
+
|
|
10
|
+
export function bindLog(container: Container) {
|
|
11
|
+
container.bind<LogConfig>(LOG_CONFIG_TOKEN).toConstantValue(defaultLogConfig);
|
|
12
|
+
container.bind<LogStorage>(LogStorage).toSelf().inSingletonScope();
|
|
13
|
+
container.bind<Log>(Log).toSelf().inSingletonScope();
|
|
14
|
+
container.bind<ConnectionService>(ConnectionService).toSelf().inSingletonScope();
|
|
15
|
+
container.bind<LogSender>(LogSender).toSelf().inSingletonScope();
|
|
16
|
+
container.bind<GlobalErrorHandler>(GlobalErrorHandler).toSelf().inSingletonScope();
|
|
17
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,51 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { bindLog } from './bind-log';
|
|
3
2
|
import {
|
|
4
3
|
ArbitaryData,
|
|
5
|
-
LogInfo,
|
|
6
|
-
LogWarning,
|
|
7
|
-
LogError,
|
|
8
|
-
ILog,
|
|
9
|
-
LogEntryType,
|
|
10
|
-
LogEntry,
|
|
11
4
|
EntryComplete,
|
|
12
5
|
EntryCompleteError,
|
|
13
|
-
|
|
6
|
+
ILog,
|
|
14
7
|
LOG_CONFIG_TOKEN,
|
|
8
|
+
Log,
|
|
15
9
|
LogConfig,
|
|
16
|
-
|
|
10
|
+
LogEntry,
|
|
11
|
+
LogEntryType,
|
|
12
|
+
LogError,
|
|
13
|
+
LogInfo,
|
|
14
|
+
LogWarning,
|
|
17
15
|
} from './log';
|
|
16
|
+
import { LogConfigProvider } from './log-config-provider';
|
|
18
17
|
import { LogStorage, StorageItem } from './log-storage';
|
|
19
18
|
import { LogSender } from './log-sender';
|
|
19
|
+
import { LogService } from './log-service';
|
|
20
20
|
import { ConnectionService } from './connection-service';
|
|
21
21
|
import { GlobalErrorHandler } from './global-error-handler';
|
|
22
22
|
|
|
23
|
-
export function bindLog(container: Container) {
|
|
24
|
-
container.bind<LogConfig>(LOG_CONFIG_TOKEN).toConstantValue({ endpoint: '/Log/Send' });
|
|
25
|
-
container.bind<LogStorage>(LogStorage).toSelf().inSingletonScope();
|
|
26
|
-
container.bind<Log>(Log).to(Log).inSingletonScope();
|
|
27
|
-
container.bind<ConnectionService>(ConnectionService).toSelf().inSingletonScope();
|
|
28
|
-
container.bind<LogSender>(LogSender).toSelf().inSingletonScope();
|
|
29
|
-
container.bind<GlobalErrorHandler>(GlobalErrorHandler).toSelf().inSingletonScope();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
23
|
export {
|
|
33
24
|
ArbitaryData,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
LogError,
|
|
37
|
-
ILog,
|
|
38
|
-
LogEntryType,
|
|
39
|
-
LogEntry,
|
|
25
|
+
bindLog,
|
|
26
|
+
ConnectionService,
|
|
40
27
|
EntryComplete,
|
|
41
28
|
EntryCompleteError,
|
|
42
|
-
|
|
29
|
+
GlobalErrorHandler,
|
|
30
|
+
ILog,
|
|
43
31
|
LOG_CONFIG_TOKEN,
|
|
32
|
+
Log,
|
|
44
33
|
LogConfig,
|
|
45
34
|
LogConfigProvider,
|
|
35
|
+
LogEntry,
|
|
36
|
+
LogEntryType,
|
|
37
|
+
LogError,
|
|
38
|
+
LogInfo,
|
|
39
|
+
LogSender,
|
|
40
|
+
LogService,
|
|
46
41
|
LogStorage,
|
|
42
|
+
LogWarning,
|
|
47
43
|
StorageItem,
|
|
48
|
-
LogSender,
|
|
49
|
-
ConnectionService,
|
|
50
|
-
GlobalErrorHandler,
|
|
51
44
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Provider } from '@servicetitan/react-ioc';
|
|
2
|
+
import { FC, PropsWithChildren } from 'react';
|
|
3
|
+
|
|
4
|
+
import { LOG_CONFIG_TOKEN, LogConfig } from './log-config';
|
|
5
|
+
|
|
6
|
+
type LogConfigProviderProps = PropsWithChildren<{ value: LogConfig }>;
|
|
7
|
+
|
|
8
|
+
export const LogConfigProvider: FC<LogConfigProviderProps> = ({ value, children }) => (
|
|
9
|
+
<Provider singletons={[{ provide: LOG_CONFIG_TOKEN, useValue: value }]}>{children}</Provider>
|
|
10
|
+
);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { symbolToken } from '@servicetitan/react-ioc';
|
|
2
|
+
|
|
3
|
+
export const LOG_CONFIG_TOKEN = symbolToken<LogConfig>('LOG_CONFIG_TOKEN');
|
|
4
|
+
|
|
5
|
+
export interface LogConfig {
|
|
6
|
+
endpoint: string;
|
|
7
|
+
storageKey: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const defaultLogConfig: LogConfig = {
|
|
11
|
+
endpoint: '/Log/Send',
|
|
12
|
+
storageKey: 'LogStorage',
|
|
13
|
+
};
|
package/src/log-sender.ts
CHANGED
|
@@ -3,9 +3,9 @@ import axios from 'axios';
|
|
|
3
3
|
import { injectable, inject } from '@servicetitan/react-ioc';
|
|
4
4
|
import { reaction, IReactionDisposer } from 'mobx';
|
|
5
5
|
|
|
6
|
+
import { ConnectionService } from './connection-service';
|
|
6
7
|
import { LogConfig, LOG_CONFIG_TOKEN, Log } from './log';
|
|
7
8
|
import { LogStorage, lastId, StorageItem } from './log-storage';
|
|
8
|
-
import { ConnectionService } from './connection-service';
|
|
9
9
|
|
|
10
10
|
@injectable()
|
|
11
11
|
export class LogSender {
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { FC, PropsWithChildren, useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Provider,
|
|
4
|
+
ProviderProps,
|
|
5
|
+
useDependencies,
|
|
6
|
+
useOptionalDependencies,
|
|
7
|
+
} from '@servicetitan/react-ioc';
|
|
8
|
+
import { ConnectionService } from './connection-service';
|
|
9
|
+
import { LOG_PARENT_TOKEN, Log } from './log';
|
|
10
|
+
import { LOG_CONFIG_TOKEN, defaultLogConfig } from './log-config';
|
|
11
|
+
import { LogSender } from './log-sender';
|
|
12
|
+
import { LogStorage } from './log-storage';
|
|
13
|
+
|
|
14
|
+
export interface LogServiceProps extends PropsWithChildren<{}> {
|
|
15
|
+
endpoint?: string;
|
|
16
|
+
storageKey?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const LogService: FC<LogServiceProps> = ({
|
|
20
|
+
children,
|
|
21
|
+
endpoint = defaultLogConfig.endpoint,
|
|
22
|
+
storageKey = defaultLogConfig.storageKey,
|
|
23
|
+
}) => {
|
|
24
|
+
const [parentLog] = useOptionalDependencies(Log);
|
|
25
|
+
|
|
26
|
+
const singletons = useMemo(() => {
|
|
27
|
+
const result: ProviderProps['singletons'] = [
|
|
28
|
+
{ provide: LOG_CONFIG_TOKEN, useValue: { endpoint, storageKey } },
|
|
29
|
+
ConnectionService,
|
|
30
|
+
Log,
|
|
31
|
+
LogStorage,
|
|
32
|
+
LogSender,
|
|
33
|
+
];
|
|
34
|
+
if (parentLog) {
|
|
35
|
+
result.push({ provide: LOG_PARENT_TOKEN, useValue: parentLog });
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}, [endpoint, parentLog, storageKey]);
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<Provider singletons={singletons}>
|
|
42
|
+
<InitializeLogSender />
|
|
43
|
+
{children}
|
|
44
|
+
</Provider>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const InitializeLogSender: FC = () => {
|
|
49
|
+
useDependencies(LogSender);
|
|
50
|
+
return null;
|
|
51
|
+
};
|
package/src/log-storage.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { injectable } from '@servicetitan/react-ioc';
|
|
1
|
+
import { inject, injectable } from '@servicetitan/react-ioc';
|
|
2
2
|
import { observable, action, makeObservable } from 'mobx';
|
|
3
3
|
|
|
4
4
|
import { EntryComplete, Nullable } from './log';
|
|
5
|
+
import { LOG_CONFIG_TOKEN, LogConfig } from './log-config';
|
|
5
6
|
|
|
6
7
|
export interface StorageItem {
|
|
7
8
|
id: number;
|
|
@@ -13,9 +14,6 @@ export interface StorageItem {
|
|
|
13
14
|
exception: string;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
const storageVersionKey = 'LogStorageVersion';
|
|
17
|
-
const storageKey = 'LogStorage';
|
|
18
|
-
|
|
19
17
|
@injectable()
|
|
20
18
|
export class LogStorage {
|
|
21
19
|
@observable
|
|
@@ -26,17 +24,17 @@ export class LogStorage {
|
|
|
26
24
|
|
|
27
25
|
private nextItemId: number;
|
|
28
26
|
|
|
29
|
-
constructor() {
|
|
27
|
+
constructor(@inject(LOG_CONFIG_TOKEN) private readonly logConfig: LogConfig) {
|
|
30
28
|
makeObservable(this);
|
|
31
29
|
|
|
32
|
-
const version = window.parseInt(localStorage.getItem(storageVersionKey) as string);
|
|
30
|
+
const version = window.parseInt(localStorage.getItem(this.storageVersionKey) as string);
|
|
33
31
|
if (version !== this.version) {
|
|
34
|
-
localStorage.removeItem(storageKey);
|
|
35
|
-
localStorage.setItem(storageVersionKey, String(this.version));
|
|
32
|
+
localStorage.removeItem(this.storageKey);
|
|
33
|
+
localStorage.setItem(this.storageVersionKey, String(this.version));
|
|
36
34
|
}
|
|
37
35
|
|
|
38
36
|
try {
|
|
39
|
-
const items = JSON.parse(localStorage.getItem(storageKey) as string) ?? [];
|
|
37
|
+
const items = JSON.parse(localStorage.getItem(this.storageKey) as string) ?? [];
|
|
40
38
|
|
|
41
39
|
/* migrate error -> exception */
|
|
42
40
|
items.forEach((item: StorageItem & { error?: string }) => {
|
|
@@ -53,6 +51,10 @@ export class LogStorage {
|
|
|
53
51
|
this.nextItemId = lastId(this.items);
|
|
54
52
|
}
|
|
55
53
|
|
|
54
|
+
get config(): LogConfig {
|
|
55
|
+
return this.logConfig;
|
|
56
|
+
}
|
|
57
|
+
|
|
56
58
|
store(entry: EntryComplete) {
|
|
57
59
|
const item: StorageItem = {
|
|
58
60
|
id: this.nextItemId++,
|
|
@@ -81,18 +83,20 @@ export class LogStorage {
|
|
|
81
83
|
@action
|
|
82
84
|
private setItems(items: StorageItem[]) {
|
|
83
85
|
this.items = [...items];
|
|
84
|
-
localStorage.setItem(storageKey, JSON.stringify(this.items));
|
|
86
|
+
localStorage.setItem(this.storageKey, JSON.stringify(this.items));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private get storageKey() {
|
|
90
|
+
return this.logConfig.storageKey;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
private get storageVersionKey() {
|
|
94
|
+
return `${this.storageKey}Version`;
|
|
85
95
|
}
|
|
86
96
|
|
|
87
97
|
private stringifyError(error: Nullable<Error>) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
repr = {
|
|
91
|
-
message: error.message.toString(),
|
|
92
|
-
stack: error.stack,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
return JSON.stringify(repr);
|
|
98
|
+
const detail = error ? { message: error.message.toString(), stack: error.stack } : null;
|
|
99
|
+
return JSON.stringify(detail);
|
|
96
100
|
}
|
|
97
101
|
}
|
|
98
102
|
|
package/src/{log.tsx → log.ts}
RENAMED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { FC, PropsWithChildren } from 'react';
|
|
2
1
|
import throttle from 'lodash.throttle';
|
|
3
|
-
import { injectable, inject,
|
|
2
|
+
import { injectable, inject, optional, symbolToken } from '@servicetitan/react-ioc';
|
|
3
|
+
|
|
4
|
+
import { defaultLogConfig } from './log-config';
|
|
4
5
|
import { LogStorage } from './log-storage';
|
|
5
6
|
import { serializeWithMetadata } from './serialize-with-metadata';
|
|
6
7
|
|
|
8
|
+
export { LOG_CONFIG_TOKEN, LogConfig } from './log-config';
|
|
9
|
+
|
|
7
10
|
export interface ArbitaryData extends Record<string, boolean | number | string | Date> {}
|
|
8
11
|
|
|
9
12
|
export interface LogEntry {
|
|
@@ -48,35 +51,32 @@ export type EntryCompleteError = EntryComplete & {
|
|
|
48
51
|
error: Error;
|
|
49
52
|
};
|
|
50
53
|
|
|
51
|
-
export
|
|
52
|
-
endpoint: string;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export const LOG_CONFIG_TOKEN = symbolToken<LogConfig>('LOG_CONFIG_TOKEN');
|
|
56
|
-
|
|
57
|
-
type LogConfigProviderProps = PropsWithChildren<{ value: LogConfig }>;
|
|
58
|
-
|
|
59
|
-
export const LogConfigProvider: FC<LogConfigProviderProps> = ({ value, children }) => (
|
|
60
|
-
<Provider singletons={[{ provide: LOG_CONFIG_TOKEN, useValue: value }]}>{children}</Provider>
|
|
61
|
-
);
|
|
54
|
+
export const LOG_PARENT_TOKEN = symbolToken<Log>('LOG_PARENT_TOKEN');
|
|
62
55
|
|
|
63
56
|
@injectable()
|
|
64
57
|
export class Log implements ILog {
|
|
65
58
|
private errorLogHandler: ErrorLogHandler;
|
|
66
59
|
|
|
67
|
-
constructor(
|
|
60
|
+
constructor(
|
|
61
|
+
@inject(LogStorage) private readonly logStorage: LogStorage,
|
|
62
|
+
@inject(LOG_PARENT_TOKEN) @optional() private readonly parent?: Log
|
|
63
|
+
) {
|
|
64
|
+
this.validate();
|
|
68
65
|
this.errorLogHandler = new ErrorLogHandler(this, this.logStorage);
|
|
69
66
|
}
|
|
70
67
|
|
|
71
68
|
info(entry: LogInfo): void {
|
|
69
|
+
this.parent?.info(entry);
|
|
72
70
|
return this.store(this.expand(LogEntryType.Info, entry));
|
|
73
71
|
}
|
|
74
72
|
|
|
75
73
|
warning(entry: LogWarning): void {
|
|
74
|
+
this.parent?.warning(entry);
|
|
76
75
|
return this.store(this.expand(LogEntryType.Warning, entry));
|
|
77
76
|
}
|
|
78
77
|
|
|
79
78
|
error(entry: LogError): void {
|
|
79
|
+
this.parent?.error(entry);
|
|
80
80
|
// eslint-disable-next-line no-console
|
|
81
81
|
console.error('@log-service/error', entry);
|
|
82
82
|
return this.errorLogHandler.handle(this.expandError(entry)); // with errorLogHandler throttling
|
|
@@ -128,9 +128,20 @@ export class Log implements ILog {
|
|
|
128
128
|
UserAgent: window.navigator.userAgent,
|
|
129
129
|
Source: 'Frontend',
|
|
130
130
|
Plugins: plugins(),
|
|
131
|
-
...
|
|
131
|
+
...timezoneInfo(),
|
|
132
132
|
};
|
|
133
133
|
}
|
|
134
|
+
|
|
135
|
+
private validate() {
|
|
136
|
+
if (!this.parent) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const { endpoint, storageKey } = this.logStorage.config;
|
|
141
|
+
if (endpoint === defaultLogConfig.endpoint || storageKey === defaultLogConfig.storageKey) {
|
|
142
|
+
throw new Error('nested Log cannot use default configuration');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
134
145
|
}
|
|
135
146
|
|
|
136
147
|
class ErrorLogHandler {
|
|
@@ -163,14 +174,14 @@ class ErrorLogHandler {
|
|
|
163
174
|
private add(entry: EntryCompleteError) {
|
|
164
175
|
const key = this.keyFor(entry);
|
|
165
176
|
if (this.repetitiveLogsCache.get(key)) {
|
|
166
|
-
/* error is a
|
|
177
|
+
/* error is a repetitive error and has been reported, we don't need to report it again */
|
|
167
178
|
return;
|
|
168
179
|
}
|
|
169
180
|
|
|
170
181
|
if (this.logTable.get(key) == null) {
|
|
171
182
|
this.logTable.set(key, entry);
|
|
172
183
|
} else {
|
|
173
|
-
/* present in entry table, hence a duplicate,
|
|
184
|
+
/* present in entry table, hence a duplicate, don't set, rather increase count */
|
|
174
185
|
const entry = this.logTable.get(key) as EntryCompleteError & {
|
|
175
186
|
data: { count?: number };
|
|
176
187
|
};
|
|
@@ -238,7 +249,7 @@ function plugins() {
|
|
|
238
249
|
}
|
|
239
250
|
}
|
|
240
251
|
|
|
241
|
-
function
|
|
252
|
+
function timezoneInfo() {
|
|
242
253
|
// https://stackoverflow.com/questions/11887934/how-to-check-if-dst-daylight-saving-time-is-in-effect-and-if-so-the-offset
|
|
243
254
|
|
|
244
255
|
const now = new Date();
|