@elisra-devops/docgen-data-provider 1.140.0 → 1.141.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.
Files changed (44) hide show
  1. package/.github/workflows/ci.yml +2 -0
  2. package/bin/helpers/tfs.js +21 -14
  3. package/bin/helpers/tfs.js.map +1 -1
  4. package/bin/modules/JfrogDataProvider.js +1 -1
  5. package/bin/modules/JfrogDataProvider.js.map +1 -1
  6. package/bin/modules/PipelinesDataProvider.js +1 -1
  7. package/bin/modules/PipelinesDataProvider.js.map +1 -1
  8. package/bin/modules/ResultDataProvider.js +21 -15
  9. package/bin/modules/ResultDataProvider.js.map +1 -1
  10. package/bin/modules/TicketsDataProvider.js +13 -10
  11. package/bin/modules/TicketsDataProvider.js.map +1 -1
  12. package/bin/tests/modules/JfrogDataProvider.test.js +3 -1
  13. package/bin/tests/modules/JfrogDataProvider.test.js.map +1 -1
  14. package/bin/tests/modules/ResultDataProvider.test.js +6 -2
  15. package/bin/tests/modules/ResultDataProvider.test.js.map +1 -1
  16. package/bin/tests/utils/logger.test.d.ts +1 -0
  17. package/bin/tests/utils/logger.test.js +238 -0
  18. package/bin/tests/utils/logger.test.js.map +1 -0
  19. package/bin/tests/utils/runContext.test.d.ts +1 -0
  20. package/bin/tests/utils/runContext.test.js +51 -0
  21. package/bin/tests/utils/runContext.test.js.map +1 -0
  22. package/bin/utils/logSink.d.ts +25 -0
  23. package/bin/utils/logSink.js +16 -0
  24. package/bin/utils/logSink.js.map +1 -0
  25. package/bin/utils/logger.d.ts +6 -0
  26. package/bin/utils/logger.js +219 -27
  27. package/bin/utils/logger.js.map +1 -1
  28. package/bin/utils/runContext.d.ts +8 -0
  29. package/bin/utils/runContext.js +12 -0
  30. package/bin/utils/runContext.js.map +1 -0
  31. package/eslint.config.mjs +40 -0
  32. package/package.json +8 -3
  33. package/src/helpers/tfs.ts +19 -15
  34. package/src/modules/JfrogDataProvider.ts +1 -1
  35. package/src/modules/PipelinesDataProvider.ts +1 -1
  36. package/src/modules/ResultDataProvider.ts +20 -15
  37. package/src/modules/TicketsDataProvider.ts +15 -14
  38. package/src/tests/modules/JfrogDataProvider.test.ts +3 -1
  39. package/src/tests/modules/ResultDataProvider.test.ts +6 -2
  40. package/src/tests/utils/logger.test.ts +270 -0
  41. package/src/tests/utils/runContext.test.ts +48 -0
  42. package/src/utils/logSink.ts +44 -0
  43. package/src/utils/logger.ts +229 -29
  44. package/src/utils/runContext.ts +25 -0
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,238 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const winston = require("winston");
4
+ const Transport = require("winston-transport");
5
+ const logger_1 = require("../../utils/logger");
6
+ const logSink_1 = require("../../utils/logSink");
7
+ const runContext_1 = require("../../utils/runContext");
8
+ const applyRedact = (info) => (0, logger_1.redact)().transform(Object.assign({}, info));
9
+ describe('logger redact format', () => {
10
+ test('scrubs a top-level token/password/secret regardless of key casing', () => {
11
+ const out = applyRedact({ level: 'info', message: 'x', token: 'abc', Password: 'p', SECRET: 's' });
12
+ expect(out.token).toBe('[REDACTED]');
13
+ expect(out.Password).toBe('[REDACTED]');
14
+ expect(out.SECRET).toBe('[REDACTED]');
15
+ });
16
+ test('scrubs nested config.auth.password and config.headers.Authorization — the AxiosError.toJSON() leak', () => {
17
+ // This is the exact shape that was leaking via logger.error(JSON.stringify(error))
18
+ // in TicketsDataProvider.ts on ADO batch work-item failures.
19
+ const axiosLikeError = {
20
+ message: 'Request failed',
21
+ config: {
22
+ auth: { username: '', password: 'super-secret-pat' },
23
+ headers: { Authorization: 'Bearer abc.def.ghi' },
24
+ },
25
+ };
26
+ const out = applyRedact({ level: 'error', message: 'error populating workitems array', err: axiosLikeError });
27
+ expect(out.err.config.auth.password).toBe('[REDACTED]');
28
+ expect(out.err.config.headers.Authorization).toBe('[REDACTED]');
29
+ expect(out.err.message).toBe('Request failed');
30
+ });
31
+ test('leaves non-sensitive fields untouched', () => {
32
+ const out = applyRedact({ level: 'info', message: 'ok', project: 'Cube-ADCS', docType: 'SVD' });
33
+ expect(out.project).toBe('Cube-ADCS');
34
+ expect(out.docType).toBe('SVD');
35
+ });
36
+ test('never throws on a circular object', () => {
37
+ const circular = { name: 'x' };
38
+ circular.self = circular;
39
+ expect(() => applyRedact({ level: 'info', message: 'x', circular })).not.toThrow();
40
+ });
41
+ test('never throws and passes info through on null/undefined meta', () => {
42
+ expect(() => applyRedact({ level: 'info', message: 'x', meta: null })).not.toThrow();
43
+ expect(() => applyRedact({ level: 'info', message: 'x', meta: undefined })).not.toThrow();
44
+ });
45
+ });
46
+ // A capturing transport + the exact JSON format chain logger.ts uses (errors -> timestamp ->
47
+ // redact -> splat -> json), so these tests exercise the real pipeline, not just redact() alone.
48
+ class CaptureTransport extends Transport {
49
+ constructor() {
50
+ super(...arguments);
51
+ this.lines = [];
52
+ }
53
+ log(info, callback) {
54
+ var _a;
55
+ this.lines.push(JSON.parse((_a = info[Symbol.for('message')]) !== null && _a !== void 0 ? _a : JSON.stringify(info)));
56
+ callback();
57
+ }
58
+ }
59
+ function makeTestLogger() {
60
+ const capture = new CaptureTransport();
61
+ const logger = winston.createLogger({
62
+ level: 'silly',
63
+ format: winston.format.combine(winston.format.errors({ stack: true }), winston.format.timestamp(), (0, logger_1.redact)(), winston.format.splat(), winston.format.json()),
64
+ transports: [capture],
65
+ });
66
+ return { logger, capture };
67
+ }
68
+ describe('logger pipeline — errors({stack:true})', () => {
69
+ test('logger.error(err) (single-arg Error) still produces a non-empty message and a stack', () => {
70
+ // This is the regression errors({stack:true}) exists to prevent: without it, winston's
71
+ // single-arg path makes `info` *be* the Error, and message/stack are non-enumerable, so
72
+ // json() would emit {"level":"error","timestamp":"…"} — content-free.
73
+ const { logger, capture } = makeTestLogger();
74
+ logger.error(new Error('boom'));
75
+ expect(capture.lines).toHaveLength(1);
76
+ expect(capture.lines[0].message).toBe('boom');
77
+ expect(typeof capture.lines[0].stack).toBe('string');
78
+ expect(capture.lines[0].stack.length).toBeGreaterThan(0);
79
+ });
80
+ });
81
+ describe('logger pipeline — hostile inputs never throw', () => {
82
+ test.each([
83
+ ['null', null],
84
+ ['undefined', undefined],
85
+ ['NaN', NaN],
86
+ ['a circular object', (() => { const c = { a: 1 }; c.self = c; return c; })()],
87
+ ['an object with a throwing getter', { get boom() { throw new Error('nope'); } }],
88
+ ['a BigInt', BigInt(9007199254740993)],
89
+ ['a Symbol', Symbol('x')],
90
+ ['an Error with no message', new Error()],
91
+ ['a 10MB string', 'x'.repeat(10 * 1024 * 1024)],
92
+ ])('logger.error(%s) does not throw', (_label, value) => {
93
+ const { logger } = makeTestLogger();
94
+ expect(() => logger.error(value)).not.toThrow();
95
+ });
96
+ });
97
+ describe('DiagnosticsTransport (Phase 6a)', () => {
98
+ function makeDiagnosticsLogger() {
99
+ const capture = new CaptureTransport();
100
+ const logger = winston.createLogger({
101
+ level: 'silly',
102
+ format: winston.format.combine(winston.format.errors({ stack: true }), winston.format.timestamp(), (0, logger_1.redact)(), winston.format.splat(), winston.format.json()),
103
+ transports: [capture, new logger_1.DiagnosticsTransport()],
104
+ });
105
+ return { logger, capture };
106
+ }
107
+ test('pushes warn/error records to whatever sink is installed', () => {
108
+ var _a, _b;
109
+ const events = [];
110
+ const sink = { push: (e) => events.push(e) };
111
+ (0, logSink_1.installLogSink)(sink);
112
+ const { logger } = makeDiagnosticsLogger();
113
+ logger.warn('a stable warning');
114
+ logger.error('a stable error', Object.assign(new Error('boom'), { code: 'ECONN' }));
115
+ expect(events).toHaveLength(2);
116
+ expect(events[0].level).toBe('warn');
117
+ expect((_a = events[1].err) === null || _a === void 0 ? void 0 : _a.code).toBe('ECONN');
118
+ expect((_b = events[1].err) === null || _b === void 0 ? void 0 : _b.stack).toEqual(expect.any(String));
119
+ });
120
+ test('does not push info/debug records', () => {
121
+ const events = [];
122
+ (0, logSink_1.installLogSink)({ push: (e) => events.push(e) });
123
+ const { logger } = makeDiagnosticsLogger();
124
+ logger.info('not interesting to the dashboard');
125
+ expect(events).toHaveLength(0);
126
+ });
127
+ test('a throwing sink cannot break the log call', () => {
128
+ (0, logSink_1.installLogSink)({
129
+ push: () => {
130
+ throw new Error('sink is down');
131
+ },
132
+ });
133
+ const { logger } = makeDiagnosticsLogger();
134
+ expect(() => logger.error('still must not throw')).not.toThrow();
135
+ });
136
+ test.each([
137
+ ['null', null],
138
+ ['undefined', undefined],
139
+ ['NaN', NaN],
140
+ ['a circular object', (() => { const c = { a: 1 }; c.self = c; return c; })()],
141
+ ['an object with a throwing getter', { get boom() { throw new Error('nope'); } }],
142
+ ['a BigInt', BigInt(9007199254740993)],
143
+ ['a Symbol', Symbol('x')],
144
+ ['an Error with no message', new Error()],
145
+ ['a 10MB string', 'x'.repeat(10 * 1024 * 1024)],
146
+ ])('logger.error(%s) with a sink installed does not throw', (_label, value) => {
147
+ (0, logSink_1.installLogSink)({ push: () => undefined });
148
+ const { logger } = makeDiagnosticsLogger();
149
+ expect(() => logger.error(value)).not.toThrow();
150
+ });
151
+ });
152
+ describe('textFormat safety (regression)', () => {
153
+ // The hostile-input matrix above exercises makeTestLogger()'s json() pipeline — it never
154
+ // touched the real singleton logger's text-format branch (LOG_FORMAT's default), which is
155
+ // where a Symbol message crashed: a template literal's implicit ToString throws on a Symbol,
156
+ // and this formatter sits with no try/catch around it.
157
+ test('logger.error(Symbol) does not throw through the real default-exported logger', () => {
158
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
159
+ const logger = require('../../utils/logger').default;
160
+ expect(() => logger.error(Symbol('x'))).not.toThrow();
161
+ });
162
+ });
163
+ describe('DiagnosticsTransport capture policy (Phase 6b)', () => {
164
+ function makeDiagnosticsLogger() {
165
+ const capture = new CaptureTransport();
166
+ const logger = winston.createLogger({
167
+ level: 'silly',
168
+ format: winston.format.combine(winston.format.errors({ stack: true }), winston.format.timestamp(), (0, logger_1.redact)(), winston.format.splat(), winston.format.json()),
169
+ transports: [capture, new logger_1.DiagnosticsTransport()],
170
+ });
171
+ return { logger, capture };
172
+ }
173
+ test('normal mode (no captureMode) does not persist debug/info', () => {
174
+ const events = [];
175
+ (0, logSink_1.installLogSink)({ push: (e) => events.push(e) });
176
+ const { logger } = makeDiagnosticsLogger();
177
+ runContext_1.runContextStore.run({ runId: 'run-1' }, () => {
178
+ logger.debug('a debug line');
179
+ logger.info('an info line');
180
+ });
181
+ expect(events).toHaveLength(0);
182
+ });
183
+ test('verbose mode persists debug and info', () => {
184
+ const events = [];
185
+ (0, logSink_1.installLogSink)({ push: (e) => events.push(e) });
186
+ const { logger } = makeDiagnosticsLogger();
187
+ runContext_1.runContextStore.run({ runId: 'run-2', captureMode: 'verbose' }, () => {
188
+ logger.debug('a debug line');
189
+ logger.info('an info line');
190
+ });
191
+ expect(events).toHaveLength(2);
192
+ expect(events[0].retainPending).toBeUndefined();
193
+ });
194
+ test('warn/error persist regardless of capture mode', () => {
195
+ const events = [];
196
+ (0, logSink_1.installLogSink)({ push: (e) => events.push(e) });
197
+ const { logger } = makeDiagnosticsLogger();
198
+ runContext_1.runContextStore.run({ runId: 'run-3' }, () => {
199
+ logger.warn('a warning');
200
+ logger.error('an error');
201
+ });
202
+ expect(events).toHaveLength(2);
203
+ });
204
+ test('retain-on-failure persists debug/info tagged retainPending: true', () => {
205
+ const events = [];
206
+ (0, logSink_1.installLogSink)({ push: (e) => events.push(e) });
207
+ const { logger } = makeDiagnosticsLogger();
208
+ runContext_1.runContextStore.run({ runId: 'run-4', captureMode: 'retain-on-failure' }, () => {
209
+ logger.debug('a debug line');
210
+ });
211
+ expect(events).toHaveLength(1);
212
+ expect(events[0].retainPending).toBe(true);
213
+ });
214
+ test('retain-on-failure does not tag warn/error as retainPending', () => {
215
+ const events = [];
216
+ (0, logSink_1.installLogSink)({ push: (e) => events.push(e) });
217
+ const { logger } = makeDiagnosticsLogger();
218
+ runContext_1.runContextStore.run({ runId: 'run-5', captureMode: 'retain-on-failure' }, () => {
219
+ logger.error('an error');
220
+ });
221
+ expect(events).toHaveLength(1);
222
+ expect(events[0].retainPending).toBeUndefined();
223
+ });
224
+ test('a concurrent normal-mode run is unaffected by a sibling verbose run', () => {
225
+ const events = [];
226
+ (0, logSink_1.installLogSink)({ push: (e) => events.push(e) });
227
+ const { logger } = makeDiagnosticsLogger();
228
+ runContext_1.runContextStore.run({ runId: 'verbose-run', captureMode: 'verbose' }, () => {
229
+ logger.debug('verbose debug');
230
+ });
231
+ runContext_1.runContextStore.run({ runId: 'normal-run' }, () => {
232
+ logger.debug('normal debug');
233
+ });
234
+ expect(events).toHaveLength(1);
235
+ expect(events[0].message).toBe('verbose debug');
236
+ });
237
+ });
238
+ //# sourceMappingURL=logger.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.test.js","sourceRoot":"","sources":["../../../src/tests/utils/logger.test.ts"],"names":[],"mappings":";;AAAA,mCAAmC;AACnC,+CAAgD;AAChD,+CAAkE;AAClE,iDAA+E;AAC/E,uDAAyD;AAEzD,MAAM,WAAW,GAAG,CAAC,IAA6B,EAAE,EAAE,CAAE,IAAA,eAAM,GAAU,CAAC,SAAS,mBAAM,IAAI,EAAG,CAAC;AAEhG,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpC,IAAI,CAAC,mEAAmE,EAAE,GAAG,EAAE;QAC7E,MAAM,GAAG,GAAG,WAAW,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;QACnG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACrC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACxC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACxC,CAAC,C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C,CAAC,CAAC,EAAE,CAAC,CAAC;QAChD,MAAM,EAAE,MAAM,EAAE,GAAG,qBAAqB,EAAE,CAAC;QAC3C,4BAAe,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE;YACzE,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;QACH,4BAAe,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE,GAAG,EAAE;YAChD,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;QAC/B,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const winston = require("winston");
4
+ const Transport = require("winston-transport");
5
+ const logger_1 = require("../../utils/logger");
6
+ const runContext_1 = require("../../utils/runContext");
7
+ class CaptureTransport extends Transport {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.lines = [];
11
+ }
12
+ log(info, callback) {
13
+ var _a;
14
+ this.lines.push(JSON.parse((_a = info[Symbol.for('message')]) !== null && _a !== void 0 ? _a : JSON.stringify(info)));
15
+ callback();
16
+ }
17
+ }
18
+ function makeTestLogger() {
19
+ const capture = new CaptureTransport();
20
+ const logger = winston.createLogger({
21
+ level: 'silly',
22
+ format: winston.format.combine((0, logger_1.withRunContext)(), winston.format.json()),
23
+ transports: [capture],
24
+ });
25
+ return { logger, capture };
26
+ }
27
+ describe('withRunContext', () => {
28
+ test('is a no-op when the store was never populated', () => {
29
+ const { logger, capture } = makeTestLogger();
30
+ logger.info('outside any run');
31
+ expect(capture.lines[0].runId).toBeUndefined();
32
+ });
33
+ test('stamps runId onto every log emitted inside store.run(...)', () => {
34
+ const { logger, capture } = makeTestLogger();
35
+ runContext_1.runContextStore.run({ runId: 'run-123' }, () => {
36
+ logger.info('inside the run');
37
+ });
38
+ logger.info('outside again');
39
+ expect(capture.lines[0].runId).toBe('run-123');
40
+ expect(capture.lines[1].runId).toBeUndefined();
41
+ });
42
+ test('async work started inside the run keeps the runId across the await boundary', async () => {
43
+ const { logger, capture } = makeTestLogger();
44
+ await runContext_1.runContextStore.run({ runId: 'run-async' }, async () => {
45
+ await new Promise((resolve) => setTimeout(resolve, 0));
46
+ logger.info('after await');
47
+ });
48
+ expect(capture.lines[0].runId).toBe('run-async');
49
+ });
50
+ });
51
+ //# sourceMappingURL=runContext.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runContext.test.js","sourceRoot":"","sources":["../../../src/tests/utils/runContext.test.ts"],"names":[],"mappings":";;AAAA,mCAAmC;AACnC,+CAAgD;AAChD,+CAAoD;AACpD,uDAAyD;AAEzD,MAAM,gBAAiB,SAAQ,SAAS;IAAxC;;QACE,UAAK,GAA8B,EAAE,CAAC;IAKxC,CAAC;IAJC,GAAG,CAAC,IAA6B,EAAE,QAAoB;;QACrD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAC,IAAY,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,mCAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC1F,QAAQ,EAAE,CAAC;IACb,CAAC;CACF;AACD,SAAS,cAAc;IACrB,MAAM,OAAO,GAAG,IAAI,gBAAgB,EAAE,CAAC;IACvC,MAAM,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;QAClC,KAAK,EAAE,OAAO;QACd,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,O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AK,EAAE,WAAW,EAAE,EAAE,KAAK,IAAI,EAAE;YAC3D,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;YACvD,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,25 @@
1
+ export interface DiagnosticEvent {
2
+ ts: string;
3
+ level: string;
4
+ service: string;
5
+ version: string;
6
+ runId?: string;
7
+ docType?: string;
8
+ step?: string;
9
+ contentControlType?: string;
10
+ contentControlTitle?: string;
11
+ project?: string;
12
+ userId?: string;
13
+ message: string;
14
+ err?: {
15
+ message: string;
16
+ code?: string;
17
+ stack?: string;
18
+ };
19
+ retainPending?: boolean;
20
+ }
21
+ export interface LogSink {
22
+ push(event: DiagnosticEvent): void;
23
+ }
24
+ export declare function getLogSink(): LogSink | undefined;
25
+ export declare function installLogSink(sink: LogSink): void;
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLogSink = getLogSink;
4
+ exports.installLogSink = installLogSink;
5
+ // Symbol.for so this package's copy converges on the same installed sink as
6
+ // docgen-content-control's (the host process this package runs inside) and
7
+ // docgen-dg-skins-package's, the same reasoning as runContext.ts's AsyncLocalStorage. A
8
+ // never-populated sink is a harmless no-op — this package only reads it, never installs one.
9
+ const KEY = Symbol.for('elisradevops.docgen.logSink');
10
+ function getLogSink() {
11
+ return globalThis[KEY];
12
+ }
13
+ function installLogSink(sink) {
14
+ globalThis[KEY] = sink;
15
+ }
16
+ //# sourceMappingURL=logSink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logSink.js","sourceRoot":"","sources":["../../src/utils/logSink.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAqCb,gCAEC;AAED,wCAEC;AAZD,4EAA4E;AAC5E,2EAA2E;AAC3E,wFAAwF;AACxF,6FAA6F;AAC7F,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;AAEtD,SAAgB,UAAU;IACxB,OAAQ,UAAsC,CAAC,GAAG,CAAwB,CAAC;AAC7E,CAAC;AAED,SAAgB,cAAc,CAAC,IAAa;IACzC,UAAsC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;AACtD,CAAC"}
@@ -1,3 +1,9 @@
1
1
  import * as winston from 'winston';
2
+ import * as Transport from 'winston-transport';
2
3
  declare let logger: winston.Logger;
4
+ export declare const withRunContext: winston.Logform.FormatWrap;
5
+ export declare const redact: winston.Logform.FormatWrap;
6
+ export declare class DiagnosticsTransport extends Transport {
7
+ log(info: Record<string, unknown>, callback: () => void): void;
8
+ }
3
9
  export default logger;
@@ -1,35 +1,227 @@
1
1
  'use strict';
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DiagnosticsTransport = exports.redact = exports.withRunContext = void 0;
3
4
  const winston = require("winston");
5
+ const fs = require("fs");
6
+ const path = require("path");
7
+ const Transport = require("winston-transport");
8
+ const runContext_1 = require("./runContext");
9
+ const logSink_1 = require("./logSink");
4
10
  let logger;
5
- const logFormat = winston.format.printf((info) => `${info.timestamp} - ${info.level}: ${info.message}`);
6
- // if (typeof window === "undefined") {
7
- // let logsPath = process.env.logs_path || "./logs/";
8
- // logger = winston.createLogger({
9
- // format: winston.format.timestamp(),
10
- // level: "silly",
11
- // transports: [
12
- // new winston.transports.File({
13
- // filename: `${logsPath}azure-rest-api-errors.log`,
14
- // level: "error",
15
- // format: logFormat,
16
- // }),
17
- // new winston.transports.File({
18
- // filename: `${logsPath}azure-rest-api-all.log`,
19
- // format: logFormat,
20
- // }),
21
- // new winston.transports.Console({ format: logFormat, level: "debug" }),
22
- // ],
23
- // });
24
- // } else {
11
+ // Merges the ambient runId (set by content-control's request middleware, once Phase 3 lands
12
+ // there) into every log record. A never-populated store is a harmless no-op — this package
13
+ // only reads it, never sets it.
14
+ exports.withRunContext = winston.format((info) => {
15
+ const store = runContext_1.runContextStore.getStore();
16
+ if (store === null || store === void 0 ? void 0 : store.runId)
17
+ info.runId = store.runId;
18
+ // Phase 7b — same ambient, per-run treatment as runId.
19
+ if (store === null || store === void 0 ? void 0 : store.docType)
20
+ info.docType = store.docType;
21
+ // Phase 7c — same read-only treatment; populated by content-control's attachRunContext.
22
+ if (store === null || store === void 0 ? void 0 : store.project)
23
+ info.project = store.project;
24
+ return info;
25
+ });
26
+ // Defense-in-depth: scrubs known-sensitive keys out of any object attached to a log call
27
+ // (meta, splat, an Error's own enumerable props — e.g. AxiosError.toJSON()'s
28
+ // config.auth.password / config.headers.Authorization, which is exactly how a PAT was
29
+ // leaking via `logger.error(JSON.stringify(error))` on ADO REST failures). Does not
30
+ // redact secrets interpolated into a message string — that's the corresponding call-site
31
+ // fixes' job; this is a backstop for structured fields.
32
+ // "accesskey" (not just "minioaccesskey") so this also catches an *AccessKeyId-style field —
33
+ // a real gap found in api-gate's copy during the Phase 5 manifest work: only the *SecretKey
34
+ // sibling was covered before, via "secret". Applied here too to keep the four copies in sync.
35
+ const SENSITIVE_KEY = /token|pat|password|secret|authorization|accesskey|minioaccesskey|miniosecretkey/i;
36
+ // A per-key try/catch on the *read*, not just around the whole loop: a getter that throws
37
+ // (e.g. `{ get boom() { throw ... } }`) would otherwise abort redaction for every remaining
38
+ // key in the same object, or — worse — survive redaction untouched and re-throw later, inside
39
+ // winston's json() formatter, which is not wrapped in anything. redactValue always returns a
40
+ // freshly built plain object/array, never the original reference, so once a value has passed
41
+ // through here nothing downstream can re-trigger a throwing accessor on it.
42
+ function safeRead(obj, key) {
43
+ try {
44
+ return { ok: true, value: obj[key] };
45
+ }
46
+ catch (_a) {
47
+ return { ok: false };
48
+ }
49
+ }
50
+ function redactValue(value, depth = 0, seen = new WeakSet()) {
51
+ if (depth > 6 || value === null || typeof value !== 'object')
52
+ return value;
53
+ if (seen.has(value))
54
+ return '[Circular]';
55
+ seen.add(value);
56
+ if (Array.isArray(value))
57
+ return value.map((v) => redactValue(v, depth + 1, seen));
58
+ const out = {};
59
+ for (const key of Object.keys(value)) {
60
+ const read = safeRead(value, key);
61
+ if (!read.ok) {
62
+ out[key] = '[Unreadable property]';
63
+ continue;
64
+ }
65
+ out[key] = SENSITIVE_KEY.test(key) ? '[REDACTED]' : redactValue(read.value, depth + 1, seen);
66
+ }
67
+ return out;
68
+ }
69
+ exports.redact = winston.format((info) => {
70
+ const target = info;
71
+ for (const key of Object.keys(target)) {
72
+ // level/timestamp are always plain strings winston sets itself — never touched. message is
73
+ // NOT exempt: when logger.error(x) is called with a single non-string/non-Error argument,
74
+ // winston nests the whole thing under info.message (this is exactly the shape hit by a raw
75
+ // object argument), so message can carry a throwing getter or a sensitive key just as much
76
+ // as any other field — redactValue already no-ops on a plain string, so including it here
77
+ // costs nothing for the common case and closes that gap for the uncommon one.
78
+ if (key === 'level' || key === 'timestamp')
79
+ continue;
80
+ const read = safeRead(target, key);
81
+ const value = !read.ok
82
+ ? '[Unreadable property]'
83
+ : // A top-level primitive (e.g. token: "abc") has no children for redactValue to walk into —
84
+ // the key itself has to be checked here too, not just inside the recursive object walk.
85
+ SENSITIVE_KEY.test(key)
86
+ ? '[REDACTED]'
87
+ : redactValue(read.value);
88
+ try {
89
+ target[key] = value;
90
+ }
91
+ catch (_a) {
92
+ // The original property could be a getter-only accessor with no setter, which throws on
93
+ // plain assignment in strict mode — redefine it outright rather than skip it.
94
+ Object.defineProperty(target, key, { value, writable: true, enumerable: true, configurable: true });
95
+ }
96
+ }
97
+ return info;
98
+ });
99
+ // Resolves the package's own version for defaultMeta. Node-only (this package is currently
100
+ // only ever consumed by docgen-content-control at runtime — the browser transport below is
101
+ // unused/commented out), so fs/path are safe here.
102
+ function readOwnVersion() {
103
+ const candidates = [
104
+ path.resolve(__dirname, '../package.json'),
105
+ path.resolve(__dirname, '../../package.json'),
106
+ path.resolve(process.cwd(), 'package.json'),
107
+ ];
108
+ for (const candidate of candidates) {
109
+ try {
110
+ if (!fs.existsSync(candidate))
111
+ continue;
112
+ return JSON.parse(fs.readFileSync(candidate, 'utf8')).version || 'unknown';
113
+ }
114
+ catch (_a) {
115
+ // try next candidate
116
+ }
117
+ }
118
+ return 'unknown';
119
+ }
120
+ // A template literal's implicit ToString throws on a Symbol value (unlike String(), which
121
+ // calls Symbol.prototype.toString() explicitly) — logger.error(Symbol('x')) would otherwise
122
+ // crash inside this formatter itself, the one place in the pipeline with no try/catch around
123
+ // it. Symbol.toString() itself never throws, so this needs no further guarding.
124
+ const safeMessageString = (value) => typeof value === 'symbol' ? value.toString() : String(value);
125
+ const textFormat = winston.format.printf((info) => `${info.timestamp} - ${info.level}: ${safeMessageString(info.message)}`);
126
+ // Bounded so one oversized message/stack can't produce an unbounded LogEvent document.
127
+ const MAX_MESSAGE_LEN = 2000;
128
+ const MAX_STACK_LEN = 4000;
129
+ function clamp(value, max) {
130
+ if (typeof value !== 'string')
131
+ return undefined;
132
+ return value.length > max ? value.slice(0, max) : value;
133
+ }
134
+ // Ships warn/error records to whatever LogSink the host process (docgen-content-control's
135
+ // index.ts) has installed — this package never installs one itself, only reads it. This is
136
+ // the dominant source of real ADO error records (tfs.ts's executeWithRetry is the single
137
+ // static axios instance handling all Azure DevOps traffic), so without this transport most
138
+ // real generation failures either never reach the store or get misattributed to
139
+ // dg-content-control. Reads info *after* the rest of the format chain has already run —
140
+ // redact() has already scrubbed it by the time this transport sees it. Never throws, never
141
+ // blocks the call path, and never logs through `logger` itself (that would recurse back
142
+ // into this same transport) — failures go to console.error only.
143
+ const DIAGNOSTICS_CAPTURE_ENABLED = (process.env.DIAGNOSTICS_CAPTURE_ENABLED || 'true').toLowerCase() !== 'false';
144
+ // Exported for tests, the same treatment as redact()/withRunContext() — so a test pipeline
145
+ // can exercise this transport without going through the real singleton logger's env-gated
146
+ // json()/textFormat branch.
147
+ class DiagnosticsTransport extends Transport {
148
+ log(info, callback) {
149
+ var _a, _b, _c, _d, _e;
150
+ setImmediate(() => this.emit('logged', info));
151
+ try {
152
+ const level = info.level;
153
+ const isWarnOrError = level === 'warn' || level === 'error';
154
+ // Phase 6b — the logger's own level gate is now 'debug' (see createLogger below), so a
155
+ // debug/info call reaches this transport regardless of mode; this is the one place that
156
+ // decides whether it's actually persisted, keyed off the per-run capture mode rather
157
+ // than a process-wide setting — concurrent runs in 'normal' mode are unaffected by a
158
+ // sibling run's 'verbose'/'retain-on-failure' opt-in.
159
+ const captureMode = (_a = runContext_1.runContextStore.getStore()) === null || _a === void 0 ? void 0 : _a.captureMode;
160
+ const isCapturedDebugOrInfo = (level === 'debug' || level === 'info') && (captureMode === 'verbose' || captureMode === 'retain-on-failure');
161
+ if (DIAGNOSTICS_CAPTURE_ENABLED && (isWarnOrError || isCapturedDebugOrInfo)) {
162
+ // winston.errors({stack:true}) merges an Error's own enumerable properties (stack,
163
+ // and anything else the call site set, e.g. `err.code`) directly onto `info` — there
164
+ // is no separate nested info.err. `info.stack`'s presence is the only reliable signal
165
+ // that this record came from `logger.error('...', err)`/`logger.error(err)` rather
166
+ // than a plain string message. When present, info.message is already the
167
+ // stable-message-plus-error-message string winston produced, so err.message reuses it.
168
+ const hasErr = typeof info.stack === 'string';
169
+ const message = (_b = clamp(info.message, MAX_MESSAGE_LEN)) !== null && _b !== void 0 ? _b : '';
170
+ const event = {
171
+ ts: typeof info.timestamp === 'string' ? info.timestamp : new Date().toISOString(),
172
+ level: String(info.level),
173
+ service: String((_c = info.service) !== null && _c !== void 0 ? _c : '@elisra-devops/docgen-data-provider'),
174
+ version: String((_d = info.version) !== null && _d !== void 0 ? _d : 'unknown'),
175
+ runId: typeof info.runId === 'string' ? info.runId : undefined,
176
+ docType: typeof info.docType === 'string' ? info.docType : undefined,
177
+ step: typeof info.step === 'string' ? info.step : undefined,
178
+ contentControlType: typeof info.contentControlType === 'string' ? info.contentControlType : undefined,
179
+ contentControlTitle: typeof info.contentControlTitle === 'string' ? info.contentControlTitle : undefined,
180
+ project: typeof info.project === 'string' ? info.project : undefined,
181
+ userId: typeof info.userId === 'string' ? info.userId : undefined,
182
+ message,
183
+ err: hasErr
184
+ ? {
185
+ message,
186
+ code: typeof info.code === 'string' ? info.code : undefined,
187
+ stack: clamp(info.stack, MAX_STACK_LEN),
188
+ }
189
+ : undefined,
190
+ retainPending: !isWarnOrError && captureMode === 'retain-on-failure' ? true : undefined,
191
+ };
192
+ (_e = (0, logSink_1.getLogSink)()) === null || _e === void 0 ? void 0 : _e.push(event);
193
+ }
194
+ }
195
+ catch (e) {
196
+ // eslint-disable-next-line no-console
197
+ console.error('DiagnosticsTransport failed to push event', e);
198
+ }
199
+ callback();
200
+ }
201
+ }
202
+ exports.DiagnosticsTransport = DiagnosticsTransport;
203
+ // LOG_FORMAT=json is the eventual default (structured stdout a collector can parse), but
204
+ // stays opt-in for one release so switching is a config change, not an image rebuild, if
205
+ // anyone reading raw console output needs to roll back.
206
+ const useJson = (process.env.LOG_FORMAT || 'text').toLowerCase() === 'json';
207
+ // Phase 6b — the Logger's own level gate must be 'debug' (winston's most permissive) so a
208
+ // debug/info call always reaches every transport's log(); a static per-logger level can't
209
+ // depend on the ALS store's per-run capture mode, so DiagnosticsTransport has to be the one
210
+ // deciding what's actually persisted. The Console transport below gets its own explicit
211
+ // level so stdout's default behavior (info/warn/error unless LOG_LEVEL=debug) is unchanged —
212
+ // this only spends the format-chain cost on debug() calls that previously short-circuited
213
+ // for free; info/warn/error volume (Phase 4's focus) is unaffected either way.
214
+ const CONSOLE_LOG_LEVEL = process.env.LOG_LEVEL || 'info';
25
215
  logger = winston.createLogger({
26
- format: winston.format.timestamp(),
27
- level: 'silly',
28
- transports: [
29
- new winston.transports.Console({ format: logFormat, level: 'debug' }),
30
- // new BrowserConsole({ format: logFormat, level: 'debug' }),
31
- ],
216
+ level: 'debug',
217
+ defaultMeta: { service: '@elisra-devops/docgen-data-provider', version: readOwnVersion() },
218
+ format: useJson
219
+ ? winston.format.combine(winston.format.errors({ stack: true }), winston.format.timestamp(), (0, exports.withRunContext)(), (0, exports.redact)(), winston.format.splat(), winston.format.json())
220
+ : winston.format.combine(winston.format.errors({ stack: true }), winston.format.timestamp(), (0, exports.withRunContext)(), (0, exports.redact)(), winston.format.splat(), textFormat),
221
+ // Stdout only — no File transports, consistent with the other DocGen services (no mounted
222
+ // log volume anywhere in this deployment, so a File transport is invisible to `kubectl logs`
223
+ // and can throw at import time under a read-only root filesystem).
224
+ transports: [new winston.transports.Console({ level: CONSOLE_LOG_LEVEL }), new DiagnosticsTransport()],
32
225
  });
33
- // }
34
226
  exports.default = logger;
35
227
  //# sourceMappingURL=logger.js.map