@wireio/shared 1.0.4 → 1.0.5

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.
@@ -16,6 +16,8 @@ export function getInternalLogger() {
16
16
  export function setInternalLoggerThresholdLevel(level) {
17
17
  getInternalLogger().setOverrideLevel(level);
18
18
  }
19
- ;
20
- window.setInternalLoggerThresholdLevel = setInternalLoggerThresholdLevel;
19
+ if (typeof window !== "undefined") {
20
+ ;
21
+ window.setInternalLoggerThresholdLevel = setInternalLoggerThresholdLevel;
22
+ }
21
23
  //# sourceMappingURL=InternalLogger.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"InternalLogger.js","sourceRoot":"","sources":["../../src/logging/InternalLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,EAAE,KAAK,EAAa,MAAM,YAAY,CAAA;AAE7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAEvD,MAAM,iBAAiB,GAAG,UAAU,CAAA;AAEpC,IAAI,cAAc,GAAW,IAAI,CAAA;AAEjC,MAAM,UAAU,iBAAiB;IAC/B,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,cAAc,GAAG,iBAAiB,EAAE,CAAC,SAAS,CAAC,iBAAiB,EAAE;YAChE,oBAAoB,EAAE,CACpB,UAAkB,EAClB,OAAuB,EACvB,EAAE,CAAC,iBAAiB;YACtB,iBAAiB,EAAE,CAAC,IAAI,eAAe,EAAE,CAAC;SAC3C,CAAC,CAAA;QACF,cAAc,CAAC,gBAAgB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IAC9C,CAAC;IACD,OAAO,cAAc,CAAA;AACvB,CAAC;AAED,MAAM,UAAU,+BAA+B,CAAC,KAAgB;IAC9D,iBAAiB,EAAE,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAA;AAC7C,CAAC;AAED,CAAC;AAAC,MAAc,CAAC,+BAA+B,GAAG,+BAA+B,CAAA"}
1
+ {"version":3,"file":"InternalLogger.js","sourceRoot":"","sources":["../../src/logging/InternalLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,EAAE,KAAK,EAAa,MAAM,YAAY,CAAA;AAE7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAEvD,MAAM,iBAAiB,GAAG,UAAU,CAAA;AAEpC,IAAI,cAAc,GAAW,IAAI,CAAA;AAEjC,MAAM,UAAU,iBAAiB;IAC/B,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,cAAc,GAAG,iBAAiB,EAAE,CAAC,SAAS,CAAC,iBAAiB,EAAE;YAChE,oBAAoB,EAAE,CACpB,UAAkB,EAClB,OAAuB,EACvB,EAAE,CAAC,iBAAiB;YACtB,iBAAiB,EAAE,CAAC,IAAI,eAAe,EAAE,CAAC;SAC3C,CAAC,CAAA;QACF,cAAc,CAAC,gBAAgB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IAC9C,CAAC;IACD,OAAO,cAAc,CAAA;AACvB,CAAC;AAED,MAAM,UAAU,+BAA+B,CAAC,KAAgB;IAC9D,iBAAiB,EAAE,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAA;AAC7C,CAAC;AAED,IAAI,OAAO,MAAM,KAAK,WAAW,EAAC,CAAC;IACjC,CAAC;IAAC,MAAc,CAAC,+BAA+B,GAAG,+BAA+B,CAAA;AACpF,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { LevelKind } from "./Level";
1
+ import type { LevelKind } from "./Level.js";
2
2
  export interface LogMetadata<Data extends {} = any> {
3
3
  url?: string;
4
4
  env?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"LogRecord.d.ts","sourceRoot":"","sources":["../../src/logging/LogRecord.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAExC,M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I,CAAC,EAAE,MAAM,EAAE,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB"}
@@ -1,4 +1,4 @@
1
1
  export * from "./aws-firehose/AWSFirehoseAppender.js";
2
2
  export * from "./ConsoleAppender.js";
3
- export * from "./DebugAppender.js";
3
+ export * from "./push/PushLogRecordsAppender.js";
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/logging/appenders/index.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAA;AACrD,cAAc,sBAAsB,CAAA;AACpC,cAAc,oBAAoB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/logging/appenders/index.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAA;AACrD,cAAc,sBAAsB,CAAA;AACpC,cAAc,kCAAkC,CAAA"}
@@ -1,4 +1,4 @@
1
1
  export * from "./aws-firehose/AWSFirehoseAppender.js";
2
2
  export * from "./ConsoleAppender.js";
3
- export * from "./DebugAppender.js";
3
+ export * from "./push/PushLogRecordsAppender.js";
4
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/logging/appenders/index.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAA;AACrD,cAAc,sBAAsB,CAAA;AACpC,cAAc,oBAAoB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/logging/appenders/index.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAA;AACrD,cAAc,sBAAsB,CAAA;AACpC,cAAc,kCAAkC,CAAA"}
@@ -0,0 +1,80 @@
1
+ import EventEmitter3 from "eventemitter3";
2
+ import { LogRecord } from "../../LogRecord.js";
3
+ import { Appender } from "../../Appender.js";
4
+ interface PushLogRecordsCredentialManagerEventMap {
5
+ received: () => void;
6
+ expired: () => void;
7
+ }
8
+ /**
9
+ * Manages credential cookie for PushLogRecordsAppender.
10
+ * Invokes the endpoint via POST to obtain a session cookie.
11
+ */
12
+ export declare class PushLogRecordsCredentialManager extends EventEmitter3<PushLogRecordsCredentialManagerEventMap> {
13
+ readonly endpointUrl: string;
14
+ private refreshTimer;
15
+ private credentialDeferred;
16
+ private cookieExpirationTime;
17
+ constructor(endpointUrl: string);
18
+ /**
19
+ * Check if valid credentials exist
20
+ */
21
+ hasCredentials(): boolean;
22
+ /**
23
+ * Check if the cookie exists in the browser
24
+ */
25
+ private hasCookie;
26
+ /**
27
+ * Get credentials, fetching them if necessary
28
+ */
29
+ ensureCredentials(): Promise<boolean>;
30
+ /**
31
+ * Force refresh of credentials
32
+ */
33
+ forceRefresh(): void;
34
+ /**
35
+ * Fetch credentials from the endpoint
36
+ */
37
+ private fetchCredentials;
38
+ /**
39
+ * Schedule a credential refresh before expiration
40
+ */
41
+ private scheduleRefresh;
42
+ /**
43
+ * Clean up resources
44
+ */
45
+ destroy(): void;
46
+ }
47
+ /**
48
+ * Appender that pushes log records to a remote endpoint via HTTP PUT.
49
+ * Batches records and sends when queue reaches FLUSH_QUEUE_DEPTH or FLUSH_INTERVAL_MS has elapsed.
50
+ */
51
+ export declare class PushLogRecordsAppender<Record extends LogRecord = LogRecord> implements Appender<Record> {
52
+ readonly endpointUrl: string;
53
+ private pendingRecords;
54
+ private flushDeferred;
55
+ private flushTimer;
56
+ readonly credentialManager: PushLogRecordsCredentialManager;
57
+ constructor(endpointUrl: string);
58
+ /**
59
+ * Append a log record to the queue
60
+ */
61
+ append(record: Record): void;
62
+ /**
63
+ * Schedule a flush after the interval
64
+ */
65
+ private scheduleFlush;
66
+ /**
67
+ * Flush pending records to the endpoint
68
+ */
69
+ private flush;
70
+ /**
71
+ * Force an immediate flush
72
+ */
73
+ forceFlush(): Promise<void>;
74
+ /**
75
+ * Clean up resources
76
+ */
77
+ destroy(): void;
78
+ }
79
+ export default PushLogRecordsAppender;
80
+ //# sourceMappingURL=PushLogRecordsAppender.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PushLogRecordsAppender.d.ts","sourceRoot":"","sources":["../../../../src/logging/appenders/push/PushLogRecordsAppender.ts"],"names":[],"mappings":"AACA,OAAO,aAAa,MAAM,eAAe,CAAA;AAEzC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAU5C,UAAU,uCAAuC;IAC/C,QAAQ,EAAE,MAAM,IAAI,CAAA;IACpB,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB;AAED;;;GAGG;AACH,qBAAa,+BAAgC,SAAQ,aAAa,CAAC,uCAAuC,CAAC;aAK7E,WAAW,EAAE,MAAM;IAJ/C,OAAO,CAAC,YAAY,CAA6C;IACjE,OAAO,CAAC,kBAAkB,CAA8B;IACxD,OAAO,CAAC,oBAAoB,CAAsB;gBAEtB,WAAW,EAAE,MAAM;IAI/C;;OAEG;IACH,cAAc,IAAI,OAAO;IAczB;;OAEG;IACH,OAAO,CAAC,SAAS;IAQjB;;OAEG;IACG,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC;IAoB3C;;OAEG;IACH,YAAY,IAAI,IAAI;IAkBpB;;OAEG;YACW,gBAAgB;IAoC9B;;OAEG;IACH,OAAO,CAAC,eAAe;IAevB;;OAEG;IACH,OAAO,IAAI,IAAI;CAahB;AAED;;;GAGG;AACH,qBAAa,sBAAsB,CAAC,MAAM,SAAS,SAAS,GAAG,SAAS,CAAE,YAAW,QAAQ,CAAC,MAAM,CAAC;aAOvE,WAAW,EAAE,MAAM;IAN/C,OAAO,CAAC,cAAc,CAAkB;IACxC,OAAO,CAAC,aAAa,CAA8B;IACnD,OAAO,CAAC,UAAU,CAA6C;IAE/D,SAAgB,iBAAiB,EAAE,+BAA+B,CAAA;gBAEtC,WAAW,EAAE,MAAM;IAa/C;;OAEG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IA6B5B;;OAEG;IACH,OAAO,CAAC,aAAa;IAarB;;OAEG;YACW,KAAK;IAwDnB;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IASjC;;OAEG;IACH,OAAO,IAAI,IAAI;CAehB;AAED,eAAe,sBAAsB,CAAA"}
@@ -0,0 +1,292 @@
1
+ /* eslint-disable typescript/no-explicit-any */
2
+ import EventEmitter3 from "eventemitter3";
3
+ import { Deferred } from "../../../helpers/index.js";
4
+ // Constants for tuning (adjustable in development)
5
+ const COOKIE_EXPIRATION_MS = 30 * 60 * 1000; // 30 minutes
6
+ const COOKIE_REFRESH_BUFFER_MS = 2 * 60 * 1000; // Refresh 2 minutes before expiration
7
+ const FLUSH_QUEUE_DEPTH = 100;
8
+ const FLUSH_INTERVAL_MS = 10 * 1000; // 10 seconds
9
+ const LOG_QUEUE_MAX_RECORDS = 10000;
10
+ const COOKIE_NAME = "wire_logs_id";
11
+ /**
12
+ * Manages credential cookie for PushLogRecordsAppender.
13
+ * Invokes the endpoint via POST to obtain a session cookie.
14
+ */
15
+ export class PushLogRecordsCredentialManager extends EventEmitter3 {
16
+ endpointUrl;
17
+ refreshTimer = null;
18
+ credentialDeferred = null;
19
+ cookieExpirationTime = null;
20
+ constructor(endpointUrl) {
21
+ super();
22
+ this.endpointUrl = endpointUrl;
23
+ }
24
+ /**
25
+ * Check if valid credentials exist
26
+ */
27
+ hasCredentials() {
28
+ if (!this.cookieExpirationTime) {
29
+ return false;
30
+ }
31
+ if (Date.now() >= this.cookieExpirationTime) {
32
+ this.cookieExpirationTime = null;
33
+ this.emit("expired");
34
+ return false;
35
+ }
36
+ return this.hasCookie();
37
+ }
38
+ /**
39
+ * Check if the cookie exists in the browser
40
+ */
41
+ hasCookie() {
42
+ if (typeof document === "undefined") {
43
+ return false;
44
+ }
45
+ return document.cookie.split(";").some((item) => item.trim().startsWith(`${COOKIE_NAME}=`));
46
+ }
47
+ /**
48
+ * Get credentials, fetching them if necessary
49
+ */
50
+ async ensureCredentials() {
51
+ // If we have valid credentials, return immediately
52
+ if (this.hasCredentials()) {
53
+ return true;
54
+ }
55
+ // If a fetch is already in progress, wait for it
56
+ if (this.credentialDeferred && !this.credentialDeferred.isSettled()) {
57
+ try {
58
+ await this.credentialDeferred.promise;
59
+ return this.hasCredentials();
60
+ }
61
+ catch {
62
+ return false;
63
+ }
64
+ }
65
+ // Fetch new credentials
66
+ return this.fetchCredentials();
67
+ }
68
+ /**
69
+ * Force refresh of credentials
70
+ */
71
+ forceRefresh() {
72
+ if (this.refreshTimer) {
73
+ clearTimeout(this.refreshTimer);
74
+ this.refreshTimer = null;
75
+ }
76
+ this.cookieExpirationTime = null;
77
+ if (this.credentialDeferred && !this.credentialDeferred.isSettled()) {
78
+ this.credentialDeferred.reject(new Error("Force refresh requested"));
79
+ }
80
+ this.credentialDeferred = null;
81
+ this.fetchCredentials().catch(() => {
82
+ // Ignore errors during force refresh, they'll be handled on next request
83
+ });
84
+ }
85
+ /**
86
+ * Fetch credentials from the endpoint
87
+ */
88
+ async fetchCredentials() {
89
+ const deferred = (this.credentialDeferred = new Deferred());
90
+ try {
91
+ const response = await fetch(this.endpointUrl, {
92
+ method: "POST",
93
+ mode: "cors",
94
+ credentials: "include",
95
+ headers: {
96
+ "Content-Type": "application/json",
97
+ },
98
+ body: JSON.stringify({}),
99
+ });
100
+ if (!response.ok) {
101
+ throw new Error(`Credential request failed with status ${response.status}`);
102
+ }
103
+ // Cookie is set by Set-Cookie header, we just need to track expiration
104
+ this.cookieExpirationTime = Date.now() + COOKIE_EXPIRATION_MS;
105
+ // Schedule refresh before expiration
106
+ this.scheduleRefresh();
107
+ deferred.resolve();
108
+ this.emit("received");
109
+ return true;
110
+ }
111
+ catch (err) {
112
+ console.debug("Failed to fetch push log credentials", err);
113
+ deferred.reject(err);
114
+ this.credentialDeferred = null;
115
+ return false;
116
+ }
117
+ }
118
+ /**
119
+ * Schedule a credential refresh before expiration
120
+ */
121
+ scheduleRefresh() {
122
+ if (this.refreshTimer) {
123
+ clearTimeout(this.refreshTimer);
124
+ }
125
+ const refreshIn = COOKIE_EXPIRATION_MS - COOKIE_REFRESH_BUFFER_MS;
126
+ this.refreshTimer = setTimeout(() => {
127
+ this.credentialDeferred = null;
128
+ this.fetchCredentials().catch(() => {
129
+ // Log but don't throw - will retry on next request
130
+ console.debug("Scheduled credential refresh failed");
131
+ });
132
+ }, refreshIn);
133
+ }
134
+ /**
135
+ * Clean up resources
136
+ */
137
+ destroy() {
138
+ if (this.refreshTimer) {
139
+ clearTimeout(this.refreshTimer);
140
+ this.refreshTimer = null;
141
+ }
142
+ if (this.credentialDeferred && !this.credentialDeferred.isSettled()) {
143
+ this.credentialDeferred.reject(new Error("Credential manager destroyed"));
144
+ }
145
+ this.credentialDeferred = null;
146
+ this.cookieExpirationTime = null;
147
+ }
148
+ }
149
+ /**
150
+ * Appender that pushes log records to a remote endpoint via HTTP PUT.
151
+ * Batches records and sends when queue reaches FLUSH_QUEUE_DEPTH or FLUSH_INTERVAL_MS has elapsed.
152
+ */
153
+ export class PushLogRecordsAppender {
154
+ endpointUrl;
155
+ pendingRecords = [];
156
+ flushDeferred = null;
157
+ flushTimer = null;
158
+ credentialManager;
159
+ constructor(endpointUrl) {
160
+ this.endpointUrl = endpointUrl;
161
+ this.credentialManager = new PushLogRecordsCredentialManager(endpointUrl);
162
+ this.credentialManager.on("received", () => {
163
+ if (!this.pendingRecords.length || this.flushDeferred) {
164
+ return;
165
+ }
166
+ this.flush().catch(() => {
167
+ // Errors handled in flush
168
+ });
169
+ });
170
+ }
171
+ /**
172
+ * Append a log record to the queue
173
+ */
174
+ append(record) {
175
+ // Enforce max queue size by removing oldest records
176
+ const pendingCount = this.pendingRecords.length + 1;
177
+ const removeCount = pendingCount - LOG_QUEUE_MAX_RECORDS;
178
+ if (removeCount > 0) {
179
+ this.pendingRecords.splice(0, removeCount);
180
+ }
181
+ // Add the record with enriched metadata
182
+ this.pendingRecords.push({
183
+ timestamp: Date.now(),
184
+ ...record,
185
+ app: record.app && record.app.length > 0 ? record.app : "UNKNOWN",
186
+ env: record.env && record.env.length > 0 ? record.env : "UNKNOWN",
187
+ url: typeof window === "undefined" ? "local://" : window.location.href,
188
+ });
189
+ // Check if we should flush immediately due to queue depth
190
+ if (this.pendingRecords.length >= FLUSH_QUEUE_DEPTH) {
191
+ this.flush().catch(() => {
192
+ // Errors handled in flush
193
+ });
194
+ }
195
+ else {
196
+ // Schedule a flush if not already scheduled
197
+ this.scheduleFlush();
198
+ }
199
+ }
200
+ /**
201
+ * Schedule a flush after the interval
202
+ */
203
+ scheduleFlush() {
204
+ if (this.flushTimer) {
205
+ return; // Already scheduled
206
+ }
207
+ this.flushTimer = setTimeout(() => {
208
+ this.flushTimer = null;
209
+ this.flush().catch(() => {
210
+ // Errors handled in flush
211
+ });
212
+ }, FLUSH_INTERVAL_MS);
213
+ }
214
+ /**
215
+ * Flush pending records to the endpoint
216
+ */
217
+ async flush() {
218
+ // Prevent concurrent flushes
219
+ if (this.flushDeferred) {
220
+ return this.flushDeferred.promise;
221
+ }
222
+ // Nothing to flush
223
+ if (!this.pendingRecords.length) {
224
+ return;
225
+ }
226
+ // Ensure we have valid credentials
227
+ const hasCredentials = await this.credentialManager.ensureCredentials();
228
+ if (!hasCredentials) {
229
+ console.debug("Failed to push log records", "No valid credentials available");
230
+ return;
231
+ }
232
+ const deferred = (this.flushDeferred = new Deferred());
233
+ try {
234
+ // Take all pending records for this flush
235
+ const records = this.pendingRecords.splice(0, this.pendingRecords.length);
236
+ const response = await fetch(this.endpointUrl, {
237
+ method: "PUT",
238
+ mode: "cors",
239
+ credentials: "include",
240
+ headers: {
241
+ "Content-Type": "application/json",
242
+ },
243
+ body: JSON.stringify(records),
244
+ });
245
+ if (!response.ok) {
246
+ // Re-queue records on failure
247
+ this.pendingRecords.unshift(...records);
248
+ throw new Error(`Push failed with status ${response.status}`);
249
+ }
250
+ deferred.resolve();
251
+ }
252
+ catch (err) {
253
+ console.debug("Failed to push log records", err);
254
+ deferred.reject(err);
255
+ }
256
+ finally {
257
+ this.flushDeferred = null;
258
+ // If more records accumulated during flush, schedule another
259
+ if (this.pendingRecords.length > 0) {
260
+ this.scheduleFlush();
261
+ }
262
+ }
263
+ return deferred.promise;
264
+ }
265
+ /**
266
+ * Force an immediate flush
267
+ */
268
+ async forceFlush() {
269
+ if (this.flushTimer) {
270
+ clearTimeout(this.flushTimer);
271
+ this.flushTimer = null;
272
+ }
273
+ return this.flush();
274
+ }
275
+ /**
276
+ * Clean up resources
277
+ */
278
+ destroy() {
279
+ if (this.flushTimer) {
280
+ clearTimeout(this.flushTimer);
281
+ this.flushTimer = null;
282
+ }
283
+ this.credentialManager.destroy();
284
+ if (this.flushDeferred && !this.flushDeferred.isSettled()) {
285
+ this.flushDeferred.reject(new Error("Appender destroyed"));
286
+ }
287
+ this.flushDeferred = null;
288
+ this.pendingRecords = [];
289
+ }
290
+ }
291
+ export default PushLogRecordsAppender;
292
+ //# sourceMappingURL=PushLogRecordsAppender.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PushLogRecordsAppender.js","sourceRoot":"","sources":["../../../../src/logging/appenders/push/PushLogRecordsAppender.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,aAAa,MAAM,eAAe,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAA;AAIpD,mDAAmD;AACnD,MAAM,oBAAoB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA,CAAC,aAAa;AACzD,MAAM,wBAAwB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAA,CAAC,sCAAsC;AACrF,MAAM,iBAAiB,GAAG,GAAG,CAAA;AAC7B,MAAM,iBAAiB,GAAG,EAAE,GAAG,IAAI,CAAA,CAAC,aAAa;AACjD,MAAM,qBAAqB,GAAG,KAAK,CA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file":"index.d.ts","sourceRoot":"","sources":["../../../../src/logging/appenders/push/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from "./PushLogRecordsAppender.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/logging/appenders/push/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wireio/shared",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1,53 +0,0 @@
1
- import type { LogRecord } from "../LogRecord";
2
- import type { Appender } from "../Appender";
3
- import Debug from "debug";
4
- import { ConsoleAppender, ConsoleAppenderConfig } from "./ConsoleAppender.js";
5
- import type { Formatter } from "../Formatter";
6
- /**
7
- * DebugAppender Configuration
8
- */
9
- export interface DebugAppenderConfig extends ConsoleAppenderConfig {
10
- hideDate: boolean;
11
- timeOnly: boolean;
12
- useConsole: boolean;
13
- useStdout: boolean;
14
- categoryPrefix: string;
15
- }
16
- /**
17
- * Partial of config, used for shortening instead of Partial<...>
18
- */
19
- export type DebugAppenderOptions = Partial<DebugAppenderConfig>;
20
- /**
21
- * Context for using `debugFormatter`
22
- */
23
- export type DebugFormatterContext = {
24
- debugConfig: DebugAppenderConfig;
25
- debug: Debug.Debugger;
26
- };
27
- /**
28
- * Uses `debug` package for logging, very useful
29
- *
30
- * @param {LogRecord} record to format
31
- * @param {DebugFormatterContext} context for this formatter
32
- * @returns
33
- */
34
- export declare const debugFormatter: Formatter<Array<any>, DebugFormatterContext>;
35
- /**
36
- * Debug appender, the simple default appender used
37
- * everywhere OOB
38
- */
39
- export declare class DebugAppender<Record extends LogRecord> extends ConsoleAppender<Record> implements Appender<Record> {
40
- readonly debugConfig: DebugAppenderConfig;
41
- /**
42
- * Handle log records, transform, push to ES
43
- *
44
- * @param record
45
- */
46
- append(record: Record): void;
47
- /**
48
- *
49
- * @param {Partial<DebugAppenderOptions>} options
50
- */
51
- constructor(options?: Partial<Omit<DebugAppenderOptions, "formatter">>);
52
- }
53
- //# sourceMappingURL=DebugAppender.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DebugAppender.d.ts","sourceRoot":"","sources":["../../../src/logging/appenders/DebugAppender.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAE3C,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EACL,eAAe,EAAE,qBAAqB,EACvC,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAiC7C;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,qBAAqB;IAChE,QAAQ,EAAE,OAAO,CAAA;IACjB,QAAQ,EAAE,OAAO,CAAA;IACjB,UAAU,EAAE,OAAO,CAAA;IACnB,SAAS,EAAE,OAAO,CAAA;IAClB,cAAc,EAAE,MAAM,CAAA;CACvB;AAED;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAA;AAsE/D;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,WAAW,EAAE,mBAAmB,CAAA;IAChC,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAA;CACtB,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,qBAAqB,CAqCvE,CAAA;AAmBD;;;GAGG;AACH,qBAAa,aAAa,CAAC,MAAM,SAAS,SAAS,CACjD,SAAQ,eAAe,CAAC,MAAM,CAC9B,YAAW,QAAQ,CAAC,MAAM,CAAC;IAE3B,QAAQ,CAAC,WAAW,EAAE,mBAAmB,CAAA;IAGzC;;;;OAIG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IA6B5B;;;OAGG;gBACS,OAAO,GAAE,OAAO,CAAC,IAAI,CAAC,oBAAoB,EAAE,WAAW,CAAC,CAAM;CAS3E"}
@@ -1,183 +0,0 @@
1
- import Debug from "debug";
2
- import { ConsoleAppender, kDefaultConsoleAppenderConfig } from "./ConsoleAppender.js";
3
- import { isEmpty, negate } from "lodash";
4
- // let chalk: any = null
5
- // if (
6
- // typeof process !== "undefined" &&
7
- // (process as any).type !== "renderer" &&
8
- // (process as any).browser !== true
9
- // ) {
10
- // chalk = require("chalk")
11
- // }
12
- const useColors = false;
13
- const makeColorFn = (fn) => {
14
- // if (!useColors) {
15
- // return (s: string) => s
16
- // }
17
- //
18
- // return (s: string) => fn(chalk, s)
19
- return (s) => s;
20
- };
21
- const colorFns = {
22
- debug: makeColorFn((c, s) => c.green(s)),
23
- error: makeColorFn((c, s) => c.red(s)),
24
- fatal: makeColorFn((c, s) => c.bgRed.black(s)),
25
- info: makeColorFn((c, s) => c.blue(s)),
26
- trace: makeColorFn((c, s) => c.gray(s)),
27
- warn: makeColorFn((c, s) => c.yellow(s))
28
- };
29
- const debuggers = new Map();
30
- //const debugAppPrefix = "app"
31
- function getDebug({ categoryPrefix }, cat) {
32
- let debug = debuggers.get(cat);
33
- if (!debug) {
34
- debug = Debug([categoryPrefix, cat].filter(negate(isEmpty)).join(":"));
35
- debuggers.set(cat, debug);
36
- }
37
- return debug;
38
- }
39
- // const timeFormatter = new Intl.DateTimeFormat('en-US', {
40
- // timeStyle: "short"
41
- // })
42
- /**
43
- *
44
- * Get ISO date if `hideDate !== true`
45
- *
46
- * @param {DebugFormatterContext}
47
- * @returns
48
- */
49
- function getDate({ debugConfig: config }) {
50
- if (config.hideDate) {
51
- return "";
52
- }
53
- const date = new Date();
54
- return config.timeOnly
55
- ? date.toLocaleTimeString("default", {
56
- hour12: false
57
- })
58
- : date.toISOString();
59
- }
60
- /**
61
- *
62
- * Formats args for output, directly based on Debug.formatArgs
63
- *
64
- * @param {DebugFormatterContext} context
65
- * @param {any[]} args
66
- */
67
- function formatArgs(context, record, args) {
68
- const { debug } = context;
69
- const { namespace: name } = debug;
70
- const prefix = colorFns[record.level]([
71
- getDate(context),
72
- Debug.humanize(debug.diff),
73
- `(` + record.level.toUpperCase() + `)`,
74
- `[${name}]`
75
- ]
76
- .filter(negate(isEmpty))
77
- .join(" "));
78
- const msg = [prefix, args[0]].filter(negate(isEmpty)).join(" ");
79
- args[0] = msg;
80
- }
81
- /**
82
- * Uses `debug` package for logging, very useful
83
- *
84
- * @param {LogRecord} record to format
85
- * @param {DebugFormatterContext} context for this formatter
86
- * @returns
87
- */
88
- export const debugFormatter = (record, { debug, debugConfig: config }) => {
89
- const { level, message, data, args: argsIn, category, timestamp } = record;
90
- const args = [message, ...argsIn];
91
- args[0] = Debug.coerce(args[0]);
92
- if (typeof args[0] !== "string") {
93
- // Anything else let's inspect with %O
94
- args.unshift("%O");
95
- }
96
- // Apply any `formatters` transformations
97
- let index = 0;
98
- args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
99
- // If we encounter an escaped % then don't increase the array index
100
- if (match === "%%") {
101
- return "%";
102
- }
103
- index++;
104
- const formatter = Debug.formatters[format];
105
- if (typeof formatter === "function") {
106
- const val = args[index];
107
- match = formatter.call(debug, val);
108
- // Now we need to remove `args[index]` since it's inlined in the `format`
109
- args.splice(index, 1);
110
- index--;
111
- }
112
- return match;
113
- });
114
- // Apply env-specific formatting (colors, etc.)
115
- formatArgs({ debug, debugConfig: config }, record, args);
116
- return args;
117
- };
118
- // [
119
- // `[${category}] (${level}) ${message}`,
120
- // ...(Array.isArray(args) ? args : [args])
121
- // ]
122
- /**
123
- * Default console config
124
- * @type {DebugAppenderConfig}
125
- */
126
- const defaultConfig = {
127
- hideDate: false,
128
- timeOnly: true,
129
- useConsole: false,
130
- useStdout: true,
131
- categoryPrefix: null,
132
- ...kDefaultConsoleAppenderConfig,
133
- formatter: debugFormatter
134
- };
135
- /**
136
- * Debug appender, the simple default appender used
137
- * everywhere OOB
138
- */
139
- export class DebugAppender extends ConsoleAppender {
140
- debugConfig;
141
- /**
142
- * Handle log records, transform, push to ES
143
- *
144
- * @param record
145
- */
146
- append(record) {
147
- const { level, message, args: argsIn, category } = record;
148
- // if (!this.levels.includes(level)) {
149
- // super.append(record)
150
- // return
151
- // }
152
- const debug = getDebug(this.debugConfig, category);
153
- let prevTime = debug.prevTime;
154
- // Set `diff` timestamp
155
- const curr = Number(new Date());
156
- const ms = curr - (prevTime || curr);
157
- debug.diff = ms;
158
- debug.prev = prevTime;
159
- debug.curr = curr;
160
- debug.prevTime = curr;
161
- const logFn = debug.log || Debug.log;
162
- const args = debugFormatter(record, { debug, debugConfig: this.debugConfig });
163
- if (this.debugConfig.useConsole) {
164
- super.write(level, ...args);
165
- }
166
- if (this.debugConfig.useStdout) {
167
- logFn.apply(debug, args);
168
- }
169
- }
170
- /**
171
- *
172
- * @param {Partial<DebugAppenderOptions>} options
173
- */
174
- constructor(options = {}) {
175
- super({
176
- ...defaultConfig,
177
- ...options,
178
- formatter: debugFormatter
179
- });
180
- this.debugConfig = this.config;
181
- }
182
- }
183
- //# sourceMappingURL=DebugAppender.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DebugAppender.js","sourceRoot":"","sources":["../../../src/logging/appenders/DebugAppender.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EACL,eAAe,EAAyB,6BAA6B,EACtE,MAAM,sBAAsB,CAAA;AAE7B,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAGxC,wBAAwB;AACxB,OAAO;AACP,sCAAsC;AACtC,4CAA4C;AAC5C,sCAAsC;AACtC,MAAM;AACN,6BAA6B;AAC7B,IAAI;AAEJ,MAAM,SAAS,GAAG,KAAK,CAAA;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