@servicetitan/log-service 30.3.1 → 31.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/log.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { LogStorage } from './log-storage';
2
- export { LOG_CONFIG_TOKEN, LogConfig } from './log-config';
2
+ export type { LogConfig } from './log-config';
3
+ export { LOG_CONFIG_TOKEN } from './log-config';
3
4
  export interface ArbitraryData extends Record<string, boolean | number | string | Date> {
4
5
  }
5
6
  export interface LogEntry {
package/dist/log.d.ts.map CHANGED
@@ -1 +1 @@
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,aAAc,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;CAAG;AAE1F,MAAM,WAAW,QAAQ;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,aAAa,CAAC;CACxB;AAED,MAAM,WAAW,OAAQ,SAAQ,QAAQ;CAAG;AAE5C,MAAM,WAAW,UAAW,SAAQ,QAAQ;CAAG;AAE/C,MAAM,WAAW,QAAS,SAAQ,QAAQ;IACtC,KAAK,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IACzB,WAAW,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,IAAI;IACjB,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IAC3B,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;IACjC,KAAK,CAAC,KAA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C;IAC1B,IAAI,EAAE,aAAa,CAAC;IACpB,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;CAC1B;AAED,MAAM,MAAM,kBAAkB,GAAG,aAAa,GAAG;IAC7C,KAAK,EAAE,KAAK,CAAC;CAChB,CAAC;AAEF,eAAO,MAAM,gBAAgB,oDAAuC,CAAC;AAYrE,qBACa,GAAI,YAAW,IAAI;IAIJ,OAAO,CAAC,QAAQ,CAAC,UAAU;IACT,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IAJlE,OAAO,CAAC,eAAe,CAAkB;gBAGA,UAAU,EAAE,UAAU,EACJ,MAAM,CAAC,EAAE,GAAG,YAAA;IAMvE,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IAK1B,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAKhC,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,WAAmB,EAAE;;KAAK,GAAG,IAAI;IAa1D,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
@@ -1,27 +1,42 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
1
+ function _define_property(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value: value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else {
10
+ obj[key] = value;
11
+ }
12
+ return obj;
13
+ }
14
+ function _ts_decorate(decorators, target, key, desc) {
2
15
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
16
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
17
+ else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
18
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
19
+ }
20
+ function _ts_metadata(k, v) {
8
21
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- var __param = (this && this.__param) || function (paramIndex, decorator) {
11
- return function (target, key) { decorator(target, key, paramIndex); }
12
- };
22
+ }
23
+ function _ts_param(paramIndex, decorator) {
24
+ return function(target, key) {
25
+ decorator(target, key, paramIndex);
26
+ };
27
+ }
13
28
  import throttle from 'lodash.throttle';
14
29
  import { injectable, inject, optional, symbolToken } from '@servicetitan/react-ioc';
15
30
  import { defaultLogConfig } from './log-config';
16
31
  import { LogStorage } from './log-storage';
17
32
  import { serializeWithMetadata } from './serialize-with-metadata';
18
33
  export { LOG_CONFIG_TOKEN } from './log-config';
19
- export var LogEntryType;
20
- (function (LogEntryType) {
34
+ export var LogEntryType = /*#__PURE__*/ function(LogEntryType) {
21
35
  LogEntryType["Info"] = "Info";
22
36
  LogEntryType["Warning"] = "Warning";
23
37
  LogEntryType["Error"] = "Error";
24
- })(LogEntryType || (LogEntryType = {}));
38
+ return LogEntryType;
39
+ }({});
25
40
  export const LOG_PARENT_TOKEN = symbolToken('LOG_PARENT_TOKEN');
26
41
  function ensureError(error) {
27
42
  if (error instanceof Error) {
@@ -32,45 +47,24 @@ function ensureError(error) {
32
47
  }
33
48
  return new Error(serializeWithMetadata(error));
34
49
  }
35
- let Log = class Log {
36
- constructor(logStorage, parent) {
37
- Object.defineProperty(this, "logStorage", {
38
- enumerable: true,
39
- configurable: true,
40
- writable: true,
41
- value: logStorage
42
- });
43
- Object.defineProperty(this, "parent", {
44
- enumerable: true,
45
- configurable: true,
46
- writable: true,
47
- value: parent
48
- });
49
- Object.defineProperty(this, "errorLogHandler", {
50
- enumerable: true,
51
- configurable: true,
52
- writable: true,
53
- value: void 0
54
- });
55
- this.validate();
56
- this.errorLogHandler = new ErrorLogHandler(this, this.logStorage);
57
- }
50
+ export class Log {
58
51
  info(entry) {
59
- var _a;
60
- (_a = this.parent) === null || _a === void 0 ? void 0 : _a.info(entry);
61
- return this.store(this.expand(LogEntryType.Info, entry));
52
+ var _this_parent;
53
+ (_this_parent = this.parent) === null || _this_parent === void 0 ? void 0 : _this_parent.info(entry);
54
+ return this.store(this.expand("Info", entry));
62
55
  }
63
56
  warning(entry) {
64
- var _a;
65
- (_a = this.parent) === null || _a === void 0 ? void 0 : _a.warning(entry);
66
- return this.store(this.expand(LogEntryType.Warning, entry));
57
+ var _this_parent;
58
+ (_this_parent = this.parent) === null || _this_parent === void 0 ? void 0 : _this_parent.warning(entry);
59
+ return this.store(this.expand("Warning", entry));
67
60
  }
68
61
  error(entry, { skipConsole = false } = {}) {
69
- var _a, _b, _c;
70
- (_a = this.parent) === null || _a === void 0 ? void 0 : _a.error(entry);
62
+ var _this_parent;
63
+ (_this_parent = this.parent) === null || _this_parent === void 0 ? void 0 : _this_parent.error(entry);
71
64
  if (!skipConsole) {
65
+ var _entry_error, _ref;
72
66
  // eslint-disable-next-line no-console
73
- console.error('@log-service/error', entry, ensureError((_c = (_b = entry === null || entry === void 0 ? void 0 : entry.error) !== null && _b !== void 0 ? _b : entry === null || entry === void 0 ? void 0 : entry.message) !== null && _c !== void 0 ? _c : 'Undefined entry'));
67
+ console.error('@log-service/error', entry, ensureError((_ref = (_entry_error = entry === null || entry === void 0 ? void 0 : entry.error) !== null && _entry_error !== void 0 ? _entry_error : entry === null || entry === void 0 ? void 0 : entry.message) !== null && _ref !== void 0 ? _ref : 'Undefined entry'));
74
68
  }
75
69
  return this.errorLogHandler.handle(this.expandError(entry)); // with errorLogHandler throttling
76
70
  }
@@ -80,7 +74,7 @@ let Log = class Log {
80
74
  expand(type, entry) {
81
75
  const data = {
82
76
  ...entry.data,
83
- ...this.dataDefault(),
77
+ ...this.dataDefault()
84
78
  };
85
79
  return {
86
80
  type,
@@ -89,22 +83,21 @@ let Log = class Log {
89
83
  code: null,
90
84
  ...entry,
91
85
  error: null,
92
- data,
86
+ data
93
87
  };
94
88
  }
95
89
  expandError(entry) {
96
90
  let error;
97
91
  if (entry.error instanceof Error) {
98
92
  error = entry.error;
99
- }
100
- else {
93
+ } else {
101
94
  error = new Error(serializeWithMetadata(entry.error));
102
95
  }
103
- const { message, ...rest } = this.expand(LogEntryType.Error, entry);
96
+ const { message, ...rest } = this.expand("Error", entry);
104
97
  return {
105
98
  message: message !== null && message !== void 0 ? message : error.message,
106
99
  ...rest,
107
- error,
100
+ error
108
101
  };
109
102
  }
110
103
  dataDefault() {
@@ -115,7 +108,7 @@ let Log = class Log {
115
108
  UserAgent: window.navigator.userAgent,
116
109
  Source: 'Frontend',
117
110
  Plugins: plugins(),
118
- ...timezoneInfo(),
111
+ ...timezoneInfo()
119
112
  };
120
113
  }
121
114
  validate() {
@@ -127,67 +120,28 @@ let Log = class Log {
127
120
  throw new Error('nested Log cannot use default configuration');
128
121
  }
129
122
  }
130
- };
131
- Log = __decorate([
123
+ constructor(logStorage, parent){
124
+ _define_property(this, "logStorage", void 0);
125
+ _define_property(this, "parent", void 0);
126
+ _define_property(this, "errorLogHandler", void 0);
127
+ this.logStorage = logStorage;
128
+ this.parent = parent;
129
+ this.validate();
130
+ this.errorLogHandler = new ErrorLogHandler(this, this.logStorage);
131
+ }
132
+ }
133
+ Log = _ts_decorate([
132
134
  injectable(),
133
- __param(0, inject(LogStorage)),
134
- __param(1, inject(LOG_PARENT_TOKEN)),
135
- __param(1, optional()),
136
- __metadata("design:paramtypes", [LogStorage,
137
- Log])
135
+ _ts_param(0, inject(LogStorage)),
136
+ _ts_param(1, inject(LOG_PARENT_TOKEN)),
137
+ _ts_param(1, optional()),
138
+ _ts_metadata("design:type", Function),
139
+ _ts_metadata("design:paramtypes", [
140
+ typeof LogStorage === "undefined" ? Object : LogStorage,
141
+ Object
142
+ ])
138
143
  ], Log);
139
- export { Log };
140
144
  class ErrorLogHandler {
141
- constructor(logService, logStorage) {
142
- Object.defineProperty(this, "logService", {
143
- enumerable: true,
144
- configurable: true,
145
- writable: true,
146
- value: void 0
147
- });
148
- Object.defineProperty(this, "logStorage", {
149
- enumerable: true,
150
- configurable: true,
151
- writable: true,
152
- value: void 0
153
- });
154
- Object.defineProperty(this, "logTable", {
155
- enumerable: true,
156
- configurable: true,
157
- writable: true,
158
- value: new HashTable()
159
- });
160
- Object.defineProperty(this, "repetitiveLogsCache", {
161
- enumerable: true,
162
- configurable: true,
163
- writable: true,
164
- value: new HashTable()
165
- });
166
- Object.defineProperty(this, "cacheFlushDuration", {
167
- enumerable: true,
168
- configurable: true,
169
- writable: true,
170
- value: 30000
171
- });
172
- Object.defineProperty(this, "throttleLogsDuration", {
173
- enumerable: true,
174
- configurable: true,
175
- writable: true,
176
- value: 2000
177
- });
178
- Object.defineProperty(this, "flushThrottled", {
179
- enumerable: true,
180
- configurable: true,
181
- writable: true,
182
- value: throttle(() => this.flush(), this.throttleLogsDuration, {
183
- leading: false,
184
- trailing: true,
185
- })
186
- });
187
- this.logService = logService;
188
- this.logStorage = logStorage;
189
- setInterval(() => this.repetitiveLogsCache.clear(), this.cacheFlushDuration);
190
- }
191
145
  handle(entry) {
192
146
  this.add(entry);
193
147
  this.flushThrottled();
@@ -195,53 +149,55 @@ class ErrorLogHandler {
195
149
  add(entry) {
196
150
  const key = this.keyFor(entry);
197
151
  if (this.repetitiveLogsCache.get(key)) {
198
- /* error is a repetitive error and has been reported, we don't need to report it again */
199
- return;
152
+ /* error is a repetitive error and has been reported, we don't need to report it again */ return;
200
153
  }
201
154
  if (this.logTable.get(key) == null) {
202
155
  this.logTable.set(key, entry);
203
- }
204
- else {
205
- /* present in entry table, hence a duplicate, don't set, rather increase count */
206
- const entry = this.logTable.get(key);
156
+ } else {
157
+ /* present in entry table, hence a duplicate, don't set, rather increase count */ const entry = this.logTable.get(key);
207
158
  if (typeof entry.data.count === 'number') {
208
159
  entry.data.count++;
209
- }
210
- else {
160
+ } else {
211
161
  entry.data.count = 2;
212
162
  }
213
163
  this.logTable.set(key, entry);
214
164
  }
215
165
  }
216
166
  keyFor(entry) {
217
- var _a;
167
+ var _entry_error_stack;
218
168
  return {
219
169
  message: entry.error.message,
220
- stack: (_a = entry.error.stack) !== null && _a !== void 0 ? _a : '',
170
+ stack: (_entry_error_stack = entry.error.stack) !== null && _entry_error_stack !== void 0 ? _entry_error_stack : ''
221
171
  };
222
172
  }
223
173
  flush() {
224
174
  const hashes = this.logTable.getHashes();
225
- for (const key of hashes) {
175
+ for (const key of hashes){
226
176
  const entry = this.logTable.get(key);
227
177
  if ('count' in entry.data) {
228
- /* insert into cache if it is a repetitive error */
229
- this.repetitiveLogsCache.set(key, true);
178
+ /* insert into cache if it is a repetitive error */ this.repetitiveLogsCache.set(key, true);
230
179
  }
231
180
  this.logStorage.store(entry);
232
181
  }
233
182
  this.logTable.clear();
234
183
  }
184
+ constructor(logService, logStorage){
185
+ _define_property(this, "logService", void 0);
186
+ _define_property(this, "logStorage", void 0);
187
+ _define_property(this, "logTable", new HashTable());
188
+ _define_property(this, "repetitiveLogsCache", new HashTable());
189
+ _define_property(this, "cacheFlushDuration", 30000);
190
+ _define_property(this, "throttleLogsDuration", 2000);
191
+ _define_property(this, "flushThrottled", throttle(()=>this.flush(), this.throttleLogsDuration, {
192
+ leading: false,
193
+ trailing: true
194
+ }));
195
+ this.logService = logService;
196
+ this.logStorage = logStorage;
197
+ setInterval(()=>this.repetitiveLogsCache.clear(), this.cacheFlushDuration);
198
+ }
235
199
  }
236
200
  class HashTable {
237
- constructor() {
238
- Object.defineProperty(this, "hashes", {
239
- enumerable: true,
240
- configurable: true,
241
- writable: true,
242
- value: {}
243
- });
244
- }
245
201
  set(key, value) {
246
202
  this.hashes[JSON.stringify(key)] = value;
247
203
  }
@@ -249,20 +205,23 @@ class HashTable {
249
205
  return this.hashes[JSON.stringify(key)];
250
206
  }
251
207
  getHashes() {
252
- return Object.keys(this.hashes).map(value => JSON.parse(value));
208
+ return Object.keys(this.hashes).map((value)=>JSON.parse(value));
253
209
  }
254
210
  clear() {
255
211
  this.hashes = {};
256
212
  }
213
+ constructor(){
214
+ _define_property(this, "hashes", {});
215
+ }
257
216
  }
258
217
  function plugins() {
259
218
  try {
260
- return Array.prototype.slice
261
- .call(window.navigator.plugins)
262
- .map(p => [p.name, p.filename, p.description].join(','))
263
- .join('/');
264
- }
265
- catch (_a) {
219
+ return Array.prototype.slice.call(window.navigator.plugins).map((p)=>[
220
+ p.name,
221
+ p.filename,
222
+ p.description
223
+ ].join(',')).join('/');
224
+ } catch (e) {
266
225
  return 'unknown';
267
226
  }
268
227
  }
@@ -277,7 +236,8 @@ function timezoneInfo() {
277
236
  return {
278
237
  TzOffset,
279
238
  IsDst,
280
- IsDstSubject,
239
+ IsDstSubject
281
240
  };
282
241
  }
242
+
283
243
  //# sourceMappingURL=log.js.map
package/dist/log.js.map CHANGED
@@ -1 +1 @@
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;AA6B3D,MAAM,CAAN,IAAY,YAIX;AAJD,WAAY,YAAY;IACpB,6BAAa,CAAA;IACb,mCAAmB,CAAA;IACnB,+BAAe,CAAA;AACnB,CAAC,EAJW,YAAY,KAAZ,YAAY,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C,MAAM,GAAG,EAAE,CAAC;IACrB,CAAC;CACJ;AAED,SAAS,OAAO;IACZ,IAAI,CAAC;QACD,OAAO,KAAK,CAAC,SAAS,CAAC,KAAK;aACvB,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC;aAC9B,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;aACvD,IAAI,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;IAAC,WAAM,CAAC;QACL,OAAO,SAAS,CAAC;IACrB,CAAC;AACL,CAAC;AAED,SAAS,YAAY;IACjB,0HAA0H;IAE1H,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC9C,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAE9C,MAAM,QAAQ,GAAG,GAAG,CAAC,iBAAiB,EAAE,CAAC;IACzC,MAAM,KAAK,GAAG,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,iBAAiB,EAAE,EAAE,GAAG,CAAC,iBAAiB,EAAE,CAAC,CAAC;IACpF,MAAM,YAAY,GAAG,GAAG,CAAC,iBAAiB,EAAE,KAAK,GAAG,CAAC,iBAAiB,EAAE,CAAC;IAEzE,OAAO;QACH,QAAQ;QACR,KAAK;QACL,YAAY;KACf,CAAC;AACN,CAAC"}
1
+ {"version":3,"sources":["../src/log.ts"],"sourcesContent":["import throttle from 'lodash.throttle';\nimport { injectable, inject, optional, symbolToken } from '@servicetitan/react-ioc';\n\nimport { defaultLogConfig } from './log-config';\nimport { LogStorage } from './log-storage';\nimport { serializeWithMetadata } from './serialize-with-metadata';\n\nexport type { LogConfig } from './log-config';\nexport { LOG_CONFIG_TOKEN } from './log-config';\n\nexport interface ArbitraryData extends Record<string, boolean | number | string | Date> {}\n\nexport interface LogEntry {\n category?: string;\n code?: string;\n message?: string;\n data?: ArbitraryData;\n}\n\nexport interface LogInfo extends LogEntry {}\n\nexport interface LogWarning extends LogEntry {}\n\nexport interface LogError extends LogEntry {\n error: unknown;\n}\n\nexport interface ErrorOptions {\n skipConsole?: boolean;\n}\n\nexport interface ILog {\n info(entry: LogInfo): void;\n warning(entry: LogWarning): void;\n error(entry: LogError, options?: ErrorOptions): void;\n}\n\nexport enum LogEntryType {\n Info = 'Info',\n Warning = 'Warning',\n Error = 'Error',\n}\n\nexport type Nullable<T> = T | null;\n\nexport interface EntryComplete {\n type: LogEntryType;\n category: Nullable<string>;\n code: Nullable<string>;\n message: Nullable<string>;\n data: ArbitraryData;\n error: Nullable<Error>;\n}\n\nexport type EntryCompleteError = EntryComplete & {\n error: Error;\n};\n\nexport const LOG_PARENT_TOKEN = symbolToken<Log>('LOG_PARENT_TOKEN');\n\nfunction ensureError(error: unknown): Error {\n if (error instanceof Error) {\n return error;\n }\n if (typeof error === 'string') {\n return new Error(error);\n }\n return new Error(serializeWithMetadata(error));\n}\n\n@injectable()\nexport class Log implements ILog {\n private errorLogHandler: ErrorLogHandler;\n\n constructor(\n @inject(LogStorage) private readonly logStorage: LogStorage,\n @inject(LOG_PARENT_TOKEN) @optional() private readonly parent?: Log\n ) {\n this.validate();\n this.errorLogHandler = new ErrorLogHandler(this, this.logStorage);\n }\n\n info(entry: LogInfo): void {\n this.parent?.info(entry);\n return this.store(this.expand(LogEntryType.Info, entry));\n }\n\n warning(entry: LogWarning): void {\n this.parent?.warning(entry);\n return this.store(this.expand(LogEntryType.Warning, entry));\n }\n\n error(entry: LogError, { skipConsole = false } = {}): void {\n this.parent?.error(entry);\n if (!skipConsole) {\n // eslint-disable-next-line no-console\n console.error(\n '@log-service/error',\n entry,\n ensureError(entry?.error ?? entry?.message ?? 'Undefined entry')\n );\n }\n return this.errorLogHandler.handle(this.expandError(entry)); // with errorLogHandler throttling\n }\n\n private store(entry: EntryComplete) {\n return this.logStorage.store(entry);\n }\n\n private expand(type: LogEntryType, entry: LogEntry): EntryComplete {\n const data = {\n ...entry.data,\n ...this.dataDefault(),\n };\n\n return {\n type,\n category: null,\n message: null,\n code: null,\n ...entry,\n error: null,\n data,\n };\n }\n\n private expandError(entry: LogError): EntryCompleteError {\n let error: Error;\n if (entry.error instanceof Error) {\n error = entry.error;\n } else {\n error = new Error(serializeWithMetadata(entry.error));\n }\n\n const { message, ...rest } = this.expand(LogEntryType.Error, entry);\n\n return {\n message: message ?? error.message,\n ...rest,\n error,\n };\n }\n\n private dataDefault() {\n return {\n CreatedOn: new Date(),\n Online: window.navigator.onLine,\n Url: window.location.toString(),\n UserAgent: window.navigator.userAgent,\n Source: 'Frontend',\n Plugins: plugins(),\n ...timezoneInfo(),\n };\n }\n\n private validate() {\n if (!this.parent) {\n return;\n }\n\n const { endpoint, storageKey } = this.logStorage.config;\n if (endpoint === defaultLogConfig.endpoint || storageKey === defaultLogConfig.storageKey) {\n throw new Error('nested Log cannot use default configuration');\n }\n }\n}\n\nclass ErrorLogHandler {\n private logService: Log;\n private logStorage: LogStorage;\n\n private logTable = new HashTable<EntryCompleteError>();\n private repetitiveLogsCache = new HashTable<boolean>();\n\n private readonly cacheFlushDuration = 30000;\n private readonly throttleLogsDuration = 2000;\n\n private flushThrottled = throttle(() => this.flush(), this.throttleLogsDuration, {\n leading: false,\n trailing: true,\n });\n\n constructor(logService: Log, logStorage: LogStorage) {\n this.logService = logService;\n this.logStorage = logStorage;\n\n setInterval(() => this.repetitiveLogsCache.clear(), this.cacheFlushDuration);\n }\n\n handle(entry: EntryCompleteError) {\n this.add(entry);\n this.flushThrottled();\n }\n\n private add(entry: EntryCompleteError) {\n const key = this.keyFor(entry);\n if (this.repetitiveLogsCache.get(key)) {\n /* error is a repetitive error and has been reported, we don't need to report it again */\n return;\n }\n\n if (this.logTable.get(key) == null) {\n this.logTable.set(key, entry);\n } else {\n /* present in entry table, hence a duplicate, don't set, rather increase count */\n const entry = this.logTable.get(key) as EntryCompleteError & {\n data: { count?: number };\n };\n if (typeof entry.data.count === 'number') {\n entry.data.count++;\n } else {\n entry.data.count = 2;\n }\n this.logTable.set(key, entry);\n }\n }\n\n private keyFor(entry: EntryCompleteError) {\n return {\n message: entry.error.message,\n stack: entry.error.stack ?? '',\n };\n }\n\n private flush() {\n const hashes = this.logTable.getHashes();\n for (const key of hashes) {\n const entry = this.logTable.get(key);\n\n if ('count' in entry.data) {\n /* insert into cache if it is a repetitive error */\n this.repetitiveLogsCache.set(key, true);\n }\n\n this.logStorage.store(entry);\n }\n\n this.logTable.clear();\n }\n}\n\nclass HashTable<T> {\n private hashes: Record<string, T> = {};\n\n set(key: { message: string; stack: string }, value: T) {\n this.hashes[JSON.stringify(key)] = value;\n }\n\n get(key: { message: string; stack: string }): T {\n return this.hashes[JSON.stringify(key)];\n }\n\n getHashes() {\n return Object.keys(this.hashes).map(value => JSON.parse(value));\n }\n\n clear() {\n this.hashes = {};\n }\n}\n\nfunction plugins() {\n try {\n return Array.prototype.slice\n .call(window.navigator.plugins)\n .map(p => [p.name, p.filename, p.description].join(','))\n .join('/');\n } catch {\n return 'unknown';\n }\n}\n\nfunction timezoneInfo() {\n // https://stackoverflow.com/questions/11887934/how-to-check-if-dst-daylight-saving-time-is-in-effect-and-if-so-the-offset\n\n const now = new Date();\n const jan = new Date(now.getFullYear(), 0, 1);\n const jul = new Date(now.getFullYear(), 6, 1);\n\n const TzOffset = now.getTimezoneOffset();\n const IsDst = TzOffset < Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());\n const IsDstSubject = jan.getTimezoneOffset() !== jul.getTimezoneOffset();\n\n return {\n TzOffset,\n IsDst,\n IsDstSubject,\n };\n}\n"],"names":["throttle","injectable","inject","optional","symbolToken","defaultLogConfig","LogStorage","serializeWithMetadata","LOG_CONFIG_TOKEN","LogEntryType","LOG_PARENT_TOKEN","ensureError","error","Error","Log","info","entry","parent","store","expand","warning","skipConsole","console","message","errorLogHandler","handle","expandError","logStorage","type","data","dataDefault","category","code","rest","CreatedOn","Date","Online","window","navigator","onLine","Url","location","toString","UserAgent","userAgent","Source","Plugins","plugins","timezoneInfo","validate","endpoint","storageKey","config","constructor","ErrorLogHandler","add","flushThrottled","key","keyFor","repetitiveLogsCache","get","logTable","set","count","stack","flush","hashes","getHashes","clear","logService","HashTable","cacheFlushDuration","throttleLogsDuration","leading","trailing","setInterval","value","JSON","stringify","Object","keys","map","parse","Array","prototype","slice","call","p","name","filename","description","join","now","jan","getFullYear","jul","TzOffset","getTimezoneOffset","IsDst","Math","max","IsDstSubject"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAOA,cAAc,kBAAkB;AACvC,SAASC,UAAU,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,WAAW,QAAQ,0BAA0B;AAEpF,SAASC,gBAAgB,QAAQ,eAAe;AAChD,SAASC,UAAU,QAAQ,gBAAgB;AAC3C,SAASC,qBAAqB,QAAQ,4BAA4B;AAGlE,SAASC,gBAAgB,QAAQ,eAAe;AA6BhD,OAAO,IAAA,AAAKC,sCAAAA;;;;WAAAA;MAIX;AAiBD,OAAO,MAAMC,mBAAmBN,YAAiB,oBAAoB;AAErE,SAASO,YAAYC,KAAc;IAC/B,IAAIA,iBAAiBC,OAAO;QACxB,OAAOD;IACX;IACA,IAAI,OAAOA,UAAU,UAAU;QAC3B,OAAO,IAAIC,MAAMD;IACrB;IACA,OAAO,IAAIC,MAAMN,sBAAsBK;AAC3C;AAGA,OAAO,MAAME;IAWTC,KAAKC,KAAc,EAAQ;YACvB;SAAA,eAAA,IAAI,CAACC,MAAM,cAAX,mCAAA,aAAaF,IAAI,CAACC;QAClB,OAAO,IAAI,CAACE,KAAK,CAAC,IAAI,CAACC,MAAM,SAAoBH;I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IAEtE,OAAO;QACHD;QACAE;QACAG;IACJ;AACJ"}
@@ -1,22 +1,20 @@
1
1
  export function serializeWithMetadata(obj) {
2
- var _a, _b;
3
2
  let result = `Type:${typeof obj}`;
4
3
  try {
5
4
  if (typeof obj === 'object') {
5
+ var _JSON_stringify;
6
6
  result += `|Constructor:${obj === null || obj === void 0 ? void 0 : obj.constructor.name}`;
7
7
  if (obj instanceof Event) {
8
8
  result += `|EventType:${obj.type}`;
9
9
  }
10
- result += `|Value:${(_a = JSON.stringify(obj)) === null || _a === void 0 ? void 0 : _a.substring(0, 100)}`;
11
- }
12
- else if (typeof obj === 'function') {
10
+ result += `|Value:${(_JSON_stringify = JSON.stringify(obj)) === null || _JSON_stringify === void 0 ? void 0 : _JSON_stringify.substring(0, 100)}`;
11
+ } else if (typeof obj === 'function') {
13
12
  result += `|Name:${obj.name}`;
13
+ } else {
14
+ var _JSON_stringify1;
15
+ result += `|Value:${(_JSON_stringify1 = JSON.stringify(obj)) === null || _JSON_stringify1 === void 0 ? void 0 : _JSON_stringify1.substring(0, 100)}`;
14
16
  }
15
- else {
16
- result += `|Value:${(_b = JSON.stringify(obj)) === null || _b === void 0 ? void 0 : _b.substring(0, 100)}`;
17
- }
18
- }
19
- catch (e) {
17
+ } catch (e) {
20
18
  result += '|Unable to serialize';
21
19
  if (e instanceof Error) {
22
20
  result += `: ${e.message.substring(0, 100)}`;
@@ -24,4 +22,5 @@ export function serializeWithMetadata(obj) {
24
22
  }
25
23
  return result;
26
24
  }
25
+
27
26
  //# sourceMappingURL=serialize-with-metadata.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"serialize-with-metadata.js","sourceRoot":"","sources":["../src/serialize-with-metadata.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,qBAAqB,CAAC,GAAY;;IAC9C,IAAI,MAAM,GAAG,QAAQ,OAAO,GAAG,EAAE,CAAC;IAClC,IAAI,CAAC;QACD,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YAC1B,MAAM,IAAI,gBAAgB,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,WAAW,CAAC,IAAI,EAAE,CAAC;YAClD,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;gBACvB,MAAM,IAAI,cAAc,GAAG,CAAC,IAAI,EAAE,CAAC;YACvC,CAAC;YACD,MAAM,IAAI,UAAU,MAAA,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,0CAAE,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;QACjE,CAAC;aAAM,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE,CAAC;YACnC,MAAM,IAAI,SAAS,GAAG,CAAC,IAAI,EAAE,CAAC;QAClC,CAAC;aAAM,CAAC;YACJ,MAAM,IAAI,UAAU,MAAA,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,0CAAE,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;QACjE,CAAC;IACL,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,MAAM,IAAI,sBAAsB,CAAC;QACjC,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;QACjD,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC"}
1
+ {"version":3,"sources":["../src/serialize-with-metadata.ts"],"sourcesContent":["export function serializeWithMetadata(obj: unknown) {\n let result = `Type:${typeof obj}`;\n try {\n if (typeof obj === 'object') {\n result += `|Constructor:${obj?.constructor.name}`;\n if (obj instanceof Event) {\n result += `|EventType:${obj.type}`;\n }\n result += `|Value:${JSON.stringify(obj)?.substring(0, 100)}`;\n } else if (typeof obj === 'function') {\n result += `|Name:${obj.name}`;\n } else {\n result += `|Value:${JSON.stringify(obj)?.substring(0, 100)}`;\n }\n } catch (e) {\n result += '|Unable to serialize';\n if (e instanceof Error) {\n result += `: ${e.message.substring(0, 100)}`;\n }\n }\n return result;\n}\n"],"names":["serializeWithMetadata","obj","result","JSON","constructor","name","Event","type","stringify","substring","e","Error","message"],"mappings":"AAAA,OAAO,SAASA,sBAAsBC,GAAY;IAC9C,IAAIC,SAAS,CAAC,KAAK,EAAE,OAAOD,KAAK;IACjC,IAAI;QACA,IAAI,OAAOA,QAAQ,UAAU;gBAKLE;YAJpBD,UAAU,CAAC,aAAa,EAAED,gBAAAA,0BAAAA,IAAKG,WAAW,CAACC,IAAI,EAAE;YACjD,IAAIJ,eAAeK,OAAO;gBACtBJ,UAAU,CAAC,WAAW,EAAED,IAAIM,IAAI,EAAE;YACtC;YACAL,UAAU,CAAC,OAAO,GAAEC,kBAAAA,KAAKK,SAAS,CAACP,kBAAfE,sCAAAA,gBAAqBM,SAAS,CAAC,GAAG,MAAM;QAChE,OAAO,IAAI,OAAOR,QAAQ,YAAY;YAClCC,UAAU,CAAC,MAAM,EAAED,IAAII,IAAI,EAAE;QACjC,OAAO;gBACiBF;YAApBD,UAAU,CAAC,OAAO,GAAEC,mBAAAA,KAAKK,SAAS,CAACP,kBAAfE,uCAAAA,iBAAqBM,SAAS,CAAC,GAAG,MAAM;QAChE;IACJ,EAAE,OAAOC,GAAG;QACRR,UAAU;QACV,IAAIQ,aAAaC,OAAO;YACpBT,UAAU,CAAC,EAAE,EAAEQ,EAAEE,OAAO,CAACH,SAAS,CAAC,GAAG,MAAM;QAChD;IACJ;IACA,OAAOP;AACX"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@servicetitan/log-service",
3
- "version": "30.3.1",
3
+ "version": "31.1.0",
4
4
  "description": "",
5
5
  "homepage": "https://docs.st.dev/docs/frontend/log-service",
6
6
  "repository": {
@@ -16,16 +16,16 @@
16
16
  "src"
17
17
  ],
18
18
  "devDependencies": {
19
- "@servicetitan/react-ioc": "30.3.1",
19
+ "@servicetitan/react-ioc": "31.1.0",
20
20
  "@testing-library/dom": "^10.4.0",
21
21
  "@testing-library/react": "^16.3.0",
22
22
  "@types/lodash.throttle": "~4.1.6",
23
- "axios": "^1.9.0",
23
+ "axios": "^1.10.0",
24
24
  "mobx": "~6.13.7",
25
25
  "react": "~18.3.1"
26
26
  },
27
27
  "peerDependencies": {
28
- "@servicetitan/react-ioc": "30.3.1",
28
+ "@servicetitan/react-ioc": "31.1.0",
29
29
  "axios": ">=0.30.0 <1 || ^1.8.3",
30
30
  "mobx": ">=6.13.7",
31
31
  "react": ">=17.0.2"
@@ -39,5 +39,5 @@
39
39
  "cli": {
40
40
  "webpack": false
41
41
  },
42
- "gitHead": "4d7f01d86d64fc00160d63a2e2a3448f28aa7a2d"
42
+ "gitHead": "d01cfe32c50461245ce52c911710e8eb879290e9"
43
43
  }
package/src/index.ts CHANGED
@@ -20,25 +20,28 @@ import { LogService } from './log-service';
20
20
  import { ConnectionService } from './connection-service';
21
21
  import { GlobalErrorHandler } from './global-error-handler';
22
22
 
23
- export {
23
+ export type {
24
24
  ArbitraryData,
25
- bindLog,
26
- ConnectionService,
27
25
  EntryComplete,
28
26
  EntryCompleteError,
29
- GlobalErrorHandler,
30
27
  ILog,
31
- LOG_CONFIG_TOKEN,
32
- Log,
33
28
  LogConfig,
34
- LogConfigProvider,
35
29
  LogEntry,
36
- LogEntryType,
37
30
  LogError,
38
31
  LogInfo,
32
+ LogWarning,
33
+ StorageItem,
34
+ };
35
+
36
+ export {
37
+ bindLog,
38
+ ConnectionService,
39
+ GlobalErrorHandler,
40
+ LOG_CONFIG_TOKEN,
41
+ Log,
42
+ LogConfigProvider,
43
+ LogEntryType,
39
44
  LogSender,
40
45
  LogService,
41
46
  LogStorage,
42
- LogWarning,
43
- StorageItem,
44
47
  };
package/src/log-sender.ts CHANGED
@@ -4,7 +4,8 @@ import { injectable, inject, Store } from '@servicetitan/react-ioc';
4
4
  import { reaction, IReactionDisposer } from 'mobx';
5
5
 
6
6
  import { ConnectionService } from './connection-service';
7
- import { LogConfig, LOG_CONFIG_TOKEN, Log } from './log';
7
+ import type { LogConfig } from './log';
8
+ import { LOG_CONFIG_TOKEN, Log } from './log';
8
9
  import { LogStorage, lastId, StorageItem } from './log-storage';
9
10
 
10
11
  const SECOND = 1000;
@@ -2,7 +2,8 @@ import { inject, injectable, Store } from '@servicetitan/react-ioc';
2
2
  import { observable, action, makeObservable, toJS } from 'mobx';
3
3
 
4
4
  import { EntryComplete, Nullable } from './log';
5
- import { LOG_CONFIG_TOKEN, LogConfig } from './log-config';
5
+ import type { LogConfig } from './log-config';
6
+ import { LOG_CONFIG_TOKEN } from './log-config';
6
7
 
7
8
  export interface StorageItem {
8
9
  id: number;
package/src/log.ts CHANGED
@@ -5,7 +5,8 @@ import { defaultLogConfig } from './log-config';
5
5
  import { LogStorage } from './log-storage';
6
6
  import { serializeWithMetadata } from './serialize-with-metadata';
7
7
 
8
- export { LOG_CONFIG_TOKEN, LogConfig } from './log-config';
8
+ export type { LogConfig } from './log-config';
9
+ export { LOG_CONFIG_TOKEN } from './log-config';
9
10
 
10
11
  export interface ArbitraryData extends Record<string, boolean | number | string | Date> {}
11
12