@wireio/shared 1.0.4 → 1.0.6

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,76 @@
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
+ * Get credentials, fetching them if necessary
24
+ */
25
+ ensureCredentials(): Promise<boolean>;
26
+ /**
27
+ * Force refresh of credentials
28
+ */
29
+ forceRefresh(): void;
30
+ /**
31
+ * Fetch credentials from the endpoint
32
+ */
33
+ private fetchCredentials;
34
+ /**
35
+ * Schedule a credential refresh before expiration
36
+ */
37
+ private scheduleRefresh;
38
+ /**
39
+ * Clean up resources
40
+ */
41
+ destroy(): void;
42
+ }
43
+ /**
44
+ * Appender that pushes log records to a remote endpoint via HTTP PUT.
45
+ * Batches records and sends when queue reaches FLUSH_QUEUE_DEPTH or FLUSH_INTERVAL_MS has elapsed.
46
+ */
47
+ export declare class PushLogRecordsAppender<Record extends LogRecord = LogRecord> implements Appender<Record> {
48
+ readonly endpointUrl: string;
49
+ private pendingRecords;
50
+ private flushDeferred;
51
+ private flushTimer;
52
+ readonly credentialManager: PushLogRecordsCredentialManager;
53
+ constructor(endpointUrl: string);
54
+ /**
55
+ * Append a log record to the queue
56
+ */
57
+ append(record: Record): void;
58
+ /**
59
+ * Schedule a flush after the interval
60
+ */
61
+ private scheduleFlush;
62
+ /**
63
+ * Flush pending records to the endpoint
64
+ */
65
+ private flush;
66
+ /**
67
+ * Force an immediate flush
68
+ */
69
+ forceFlush(): Promise<void>;
70
+ /**
71
+ * Clean up resources
72
+ */
73
+ destroy(): void;
74
+ }
75
+ export default PushLogRecordsAppender;
76
+ //# 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;AAa5C,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;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;IAyDnB;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IASjC;;OAEG;IACH,OAAO,IAAI,IAAI;CAehB;AAED,eAAe,sBAAsB,CAAA"}
@@ -0,0 +1,286 @@
1
+ /* eslint-disable typescript/no-explicit-any */
2
+ import EventEmitter3 from "eventemitter3";
3
+ import { Deferred } from "../../../helpers/index.js";
4
+ import { getInternalLogger } from "../../InternalLogger.js";
5
+ // Constants for tuning (adjustable in development)
6
+ const COOKIE_EXPIRATION_MS = 5 * 60 * 1000; // 30 minutes
7
+ const COOKIE_REFRESH_BUFFER_MS = 2 * 60 * 1000; // Refresh 2 minutes before expiration
8
+ const FLUSH_QUEUE_DEPTH = 1000;
9
+ const FLUSH_INTERVAL_MS = 5 * 1000; // 10 seconds
10
+ const LOG_QUEUE_MAX_RECORDS = 10000;
11
+ const COOKIE_NAME = "wire_logs_id";
12
+ const log = getInternalLogger();
13
+ /**
14
+ * Manages credential cookie for PushLogRecordsAppender.
15
+ * Invokes the endpoint via POST to obtain a session cookie.
16
+ */
17
+ export class PushLogRecordsCredentialManager extends EventEmitter3 {
18
+ endpointUrl;
19
+ refreshTimer = null;
20
+ credentialDeferred = null;
21
+ cookieExpirationTime = null;
22
+ constructor(endpointUrl) {
23
+ super();
24
+ this.endpointUrl = endpointUrl;
25
+ }
26
+ /**
27
+ * Check if valid credentials exist
28
+ */
29
+ hasCredentials() {
30
+ if (!this.cookieExpirationTime) {
31
+ return false;
32
+ }
33
+ if (Date.now() >= this.cookieExpirationTime) {
34
+ this.cookieExpirationTime = null;
35
+ this.emit("expired");
36
+ return false;
37
+ }
38
+ return true;
39
+ }
40
+ /**
41
+ * Get credentials, fetching them if necessary
42
+ */
43
+ async ensureCredentials() {
44
+ // If we have valid credentials, return immediately
45
+ if (this.hasCredentials()) {
46
+ return true;
47
+ }
48
+ // If a fetch is already in progress, wait for it
49
+ if (this.credentialDeferred && !this.credentialDeferred.isSettled()) {
50
+ try {
51
+ await this.credentialDeferred.promise;
52
+ return this.hasCredentials();
53
+ }
54
+ catch {
55
+ return false;
56
+ }
57
+ }
58
+ // Fetch new credentials
59
+ return this.fetchCredentials();
60
+ }
61
+ /**
62
+ * Force refresh of credentials
63
+ */
64
+ forceRefresh() {
65
+ if (this.refreshTimer) {
66
+ clearTimeout(this.refreshTimer);
67
+ this.refreshTimer = null;
68
+ }
69
+ this.cookieExpirationTime = null;
70
+ if (this.credentialDeferred && !this.credentialDeferred.isSettled()) {
71
+ this.credentialDeferred.reject(new Error("Force refresh requested"));
72
+ }
73
+ this.credentialDeferred = null;
74
+ this.fetchCredentials().catch(() => {
75
+ // Ignore errors during force refresh, they'll be handled on next request
76
+ });
77
+ }
78
+ /**
79
+ * Fetch credentials from the endpoint
80
+ */
81
+ async fetchCredentials() {
82
+ const deferred = (this.credentialDeferred = new Deferred());
83
+ try {
84
+ const response = await fetch(this.endpointUrl, {
85
+ method: "POST",
86
+ mode: "cors",
87
+ credentials: "include",
88
+ headers: {
89
+ "Content-Type": "application/json",
90
+ },
91
+ body: JSON.stringify({}),
92
+ });
93
+ if (!response.ok) {
94
+ throw new Error(`Credential request failed with status ${response.status}`);
95
+ }
96
+ // Cookie is set by Set-Cookie header, we just need to track expiration
97
+ this.cookieExpirationTime = Date.now() + COOKIE_EXPIRATION_MS;
98
+ // Schedule refresh before expiration
99
+ this.scheduleRefresh();
100
+ deferred.resolve();
101
+ this.emit("received");
102
+ return true;
103
+ }
104
+ catch (err) {
105
+ log.warn("Failed to fetch push log credentials", err);
106
+ deferred.reject(err);
107
+ this.credentialDeferred = null;
108
+ return false;
109
+ }
110
+ }
111
+ /**
112
+ * Schedule a credential refresh before expiration
113
+ */
114
+ scheduleRefresh() {
115
+ if (this.refreshTimer) {
116
+ clearTimeout(this.refreshTimer);
117
+ }
118
+ const refreshIn = COOKIE_EXPIRATION_MS - COOKIE_REFRESH_BUFFER_MS;
119
+ this.refreshTimer = setTimeout(() => {
120
+ this.credentialDeferred = null;
121
+ this.fetchCredentials().catch(() => {
122
+ // Log but don't throw - will retry on next request
123
+ log.debug("Scheduled credential refresh failed");
124
+ });
125
+ }, refreshIn);
126
+ }
127
+ /**
128
+ * Clean up resources
129
+ */
130
+ destroy() {
131
+ if (this.refreshTimer) {
132
+ clearTimeout(this.refreshTimer);
133
+ this.refreshTimer = null;
134
+ }
135
+ if (this.credentialDeferred && !this.credentialDeferred.isSettled()) {
136
+ this.credentialDeferred.reject(new Error("Credential manager destroyed"));
137
+ }
138
+ this.credentialDeferred = null;
139
+ this.cookieExpirationTime = null;
140
+ }
141
+ }
142
+ /**
143
+ * Appender that pushes log records to a remote endpoint via HTTP PUT.
144
+ * Batches records and sends when queue reaches FLUSH_QUEUE_DEPTH or FLUSH_INTERVAL_MS has elapsed.
145
+ */
146
+ export class PushLogRecordsAppender {
147
+ endpointUrl;
148
+ pendingRecords = [];
149
+ flushDeferred = null;
150
+ flushTimer = null;
151
+ credentialManager;
152
+ constructor(endpointUrl) {
153
+ this.endpointUrl = endpointUrl;
154
+ this.credentialManager = new PushLogRecordsCredentialManager(endpointUrl);
155
+ this.credentialManager.on("received", () => {
156
+ if (!this.pendingRecords.length || this.flushDeferred) {
157
+ return;
158
+ }
159
+ this.flush().catch(() => {
160
+ // Errors handled in flush
161
+ });
162
+ });
163
+ }
164
+ /**
165
+ * Append a log record to the queue
166
+ */
167
+ append(record) {
168
+ // Enforce max queue size by removing oldest records
169
+ const pendingCount = this.pendingRecords.length + 1;
170
+ const removeCount = pendingCount - LOG_QUEUE_MAX_RECORDS;
171
+ if (removeCount > 0) {
172
+ this.pendingRecords.splice(0, removeCount);
173
+ }
174
+ // Add the record with enriched metadata
175
+ this.pendingRecords.push({
176
+ timestamp: Date.now(),
177
+ ...record,
178
+ app: record.app && record.app.length > 0 ? record.app : "UNKNOWN",
179
+ env: record.env && record.env.length > 0 ? record.env : "UNKNOWN",
180
+ url: typeof window === "undefined" ? "local://" : window.location.href,
181
+ });
182
+ // Check if we should flush immediately due to queue depth
183
+ if (this.pendingRecords.length >= FLUSH_QUEUE_DEPTH) {
184
+ this.flush().catch(() => {
185
+ // Errors handled in flush
186
+ });
187
+ }
188
+ else {
189
+ // Schedule a flush if not already scheduled
190
+ this.scheduleFlush();
191
+ }
192
+ }
193
+ /**
194
+ * Schedule a flush after the interval
195
+ */
196
+ scheduleFlush() {
197
+ if (this.flushTimer) {
198
+ return; // Already scheduled
199
+ }
200
+ this.flushTimer = setTimeout(() => {
201
+ this.flushTimer = null;
202
+ this.flush().catch(() => {
203
+ // Errors handled in flush
204
+ });
205
+ }, FLUSH_INTERVAL_MS);
206
+ }
207
+ /**
208
+ * Flush pending records to the endpoint
209
+ */
210
+ async flush() {
211
+ // Prevent concurrent flushes
212
+ if (this.flushDeferred) {
213
+ return this.flushDeferred.promise;
214
+ }
215
+ // Nothing to flush
216
+ if (!this.pendingRecords.length) {
217
+ return;
218
+ }
219
+ // Ensure we have valid credentials
220
+ const hasCredentials = await this.credentialManager.ensureCredentials();
221
+ if (!hasCredentials) {
222
+ log.debug("Failed to push log records", "No valid credentials available");
223
+ return;
224
+ }
225
+ const deferred = (this.flushDeferred = new Deferred());
226
+ try {
227
+ // Take all pending records for this flush
228
+ const records = this.pendingRecords.splice(0, this.pendingRecords.length);
229
+ const payload = { records: records.map(record => JSON.stringify(record)) };
230
+ const response = await fetch(this.endpointUrl, {
231
+ method: "PUT",
232
+ mode: "cors",
233
+ credentials: "include",
234
+ headers: {
235
+ "Content-Type": "application/json"
236
+ },
237
+ body: JSON.stringify(payload),
238
+ });
239
+ if (!response.ok) {
240
+ // Re-queue records on failure
241
+ this.pendingRecords.unshift(...records);
242
+ throw new Error(`Push failed with status ${response.status}`);
243
+ }
244
+ deferred.resolve();
245
+ }
246
+ catch (err) {
247
+ log.debug("Failed to push log records", err);
248
+ deferred.reject(err);
249
+ }
250
+ finally {
251
+ this.flushDeferred = null;
252
+ // If more records accumulated during flush, schedule another
253
+ if (this.pendingRecords.length > 0) {
254
+ this.scheduleFlush();
255
+ }
256
+ }
257
+ return deferred.promise;
258
+ }
259
+ /**
260
+ * Force an immediate flush
261
+ */
262
+ async forceFlush() {
263
+ if (this.flushTimer) {
264
+ clearTimeout(this.flushTimer);
265
+ this.flushTimer = null;
266
+ }
267
+ return this.flush();
268
+ }
269
+ /**
270
+ * Clean up resources
271
+ */
272
+ destroy() {
273
+ if (this.flushTimer) {
274
+ clearTimeout(this.flushTimer);
275
+ this.flushTimer = null;
276
+ }
277
+ this.credentialManager.destroy();
278
+ if (this.flushDeferred && !this.flushDeferred.isSettled()) {
279
+ this.flushDeferred.reject(new Error("Appender destroyed"));
280
+ }
281
+ this.flushDeferred = null;
282
+ this.pendingRecords = [];
283
+ }
284
+ }
285
+ export default PushLogRecordsAppender;
286
+ //# 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;AAGpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAE3D,mDAAmD;AACnD,MAAM,oBAAoB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAA,CAAC,aAAa;AACxD,MAAM,wBAAwB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAA,CAAC,sCAAsC;AACrF,MAAM,iBAAiB,GAAG,IAAI,CAAA;AAC9B,MAAM,iBAAiB,GAAG,CAAC,GAAG,IAAI,CAAA,CAAC,aAAa;AAChD,MAAM,qBAAqB,GAAG,KAAK,CAAA;AACnC,MAAM,WAAW,GAAG,cAAc,CAAA;AAElC,MAAM,GAAG,GAAG,iBAAiB,EAAE,CAAA;AAO/B;;;GAGG;AACH,M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AC;gBACnC,IAAI,CAAC,aAAa,EAAE,CAAA;YACtB,CAAC;QACH,CAAC;QAED,OAAO,QAAQ,CAAC,OAAO,CAAA;IACzB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU;QACd,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;YAC7B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAA;QACxB,CAAC;QAED,OAAO,IAAI,CAAC,KAAK,EAAE,CAAA;IACrB,CAAC;IAED;;OAEG;IACH,OAAO;QACL,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;YAC7B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAA;QACxB,CAAC;QAED,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,CAAA;QAEhC,IAAI,IAAI,CAAC,aAAa,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE,EAAE,CAAC;YAC1D,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC,CAAA;QAC5D,CAAC;QAED,IAAI,CAAC,aAAa,GAAG,IAAI,CAAA;QACzB,IAAI,CAAC,cAAc,GAAG,EAAE,CAAA;IAC1B,CAAC;CACF;AAED,eAAe,sBAAsB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from "./PushLogRecordsAppender.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"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.6",
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":"","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soleAppender, 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;AAEvB,MAAM,WAAW,GAAG,CAAC,EAAqC,EAAE,EAAE;IAC5D,oBAAoB;IACpB,4BAA4B;IAC5B,IAAI;IACJ,EAAE;IACF,qCAAqC;IACrC,OAAO,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAA;AACzB,CAAC,CAAA;AAED,MAAM,QAAQ,GAA6C;IACzD,KAAK,EAAE,WAAW,CA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