@webex/internal-plugin-metrics 3.12.0-llmrefactor.1 → 3.12.0-llmrefactor.3

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 (45) hide show
  1. package/README.md +36 -0
  2. package/dist/config.js +3 -0
  3. package/dist/config.js.map +1 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/metrics.js +1 -1
  6. package/dist/metrics.types.js.map +1 -1
  7. package/dist/new-metrics.js +47 -11
  8. package/dist/new-metrics.js.map +1 -1
  9. package/dist/privacy-and-security-permission-enricher/constants.js +18 -0
  10. package/dist/privacy-and-security-permission-enricher/constants.js.map +1 -0
  11. package/dist/privacy-and-security-permission-enricher/index.js +143 -0
  12. package/dist/privacy-and-security-permission-enricher/index.js.map +1 -0
  13. package/dist/privacy-and-security-permission-enricher/types.js +7 -0
  14. package/dist/privacy-and-security-permission-enricher/types.js.map +1 -0
  15. package/dist/privacy-and-security-permission-enricher/utils.js +71 -0
  16. package/dist/privacy-and-security-permission-enricher/utils.js.map +1 -0
  17. package/dist/types/config.d.ts +3 -0
  18. package/dist/types/index.d.ts +2 -2
  19. package/dist/types/metrics.types.d.ts +3 -0
  20. package/dist/types/new-metrics.d.ts +13 -1
  21. package/dist/types/privacy-and-security-permission-enricher/constants.d.ts +6 -0
  22. package/dist/types/privacy-and-security-permission-enricher/index.d.ts +40 -0
  23. package/dist/types/privacy-and-security-permission-enricher/types.d.ts +14 -0
  24. package/dist/types/privacy-and-security-permission-enricher/utils.d.ts +5 -0
  25. package/dist/types/unhandled-exception-telemetry/index.d.ts +60 -0
  26. package/dist/types/unhandled-exception-telemetry/utils.d.ts +6 -0
  27. package/dist/unhandled-exception-telemetry/index.js +330 -0
  28. package/dist/unhandled-exception-telemetry/index.js.map +1 -0
  29. package/dist/unhandled-exception-telemetry/utils.js +105 -0
  30. package/dist/unhandled-exception-telemetry/utils.js.map +1 -0
  31. package/package.json +8 -8
  32. package/src/config.js +3 -0
  33. package/src/index.ts +2 -0
  34. package/src/metrics.types.ts +9 -0
  35. package/src/new-metrics.ts +44 -2
  36. package/src/privacy-and-security-permission-enricher/constants.ts +33 -0
  37. package/src/privacy-and-security-permission-enricher/index.ts +142 -0
  38. package/src/privacy-and-security-permission-enricher/types.ts +21 -0
  39. package/src/privacy-and-security-permission-enricher/utils.ts +82 -0
  40. package/src/unhandled-exception-telemetry/index.ts +403 -0
  41. package/src/unhandled-exception-telemetry/utils.ts +101 -0
  42. package/test/unit/spec/new-metrics.ts +168 -52
  43. package/test/unit/spec/privacy-and-security-permission-enricher.ts +318 -0
  44. package/test/unit/spec/unhandled-exception-telemetry/utils.ts +109 -0
  45. package/test/unit/spec/unhandled-exception-telemetry.ts +688 -0
@@ -0,0 +1,109 @@
1
+ import {assert} from '@webex/test-helper-chai';
2
+
3
+ import {
4
+ createFingerprint,
5
+ removeUrlDetails,
6
+ removeUrlDetailsFromText,
7
+ sanitizeResourceUrl,
8
+ stringifyReason,
9
+ truncate,
10
+ } from '@webex/internal-plugin-metrics/src/unhandled-exception-telemetry/utils';
11
+
12
+ const TEST_USERINFO = ['fixture-user', 'fixture-value'].join(':');
13
+
14
+ describe('Unhandled exception telemetry utilities', () => {
15
+ describe('#truncate()', () => {
16
+ it('truncates strings to the requested length', () => {
17
+ assert.equal(truncate('abcdef', 3), 'abc');
18
+ assert.equal(truncate('abc', 3), 'abc');
19
+ assert.isUndefined(truncate(undefined, 3));
20
+ });
21
+ });
22
+
23
+ describe('#removeUrlDetails()', () => {
24
+ [
25
+ {
26
+ input: `https://${TEST_USERINFO}@example.test/path?secret=x#fragment`,
27
+ expected: 'https://example.test/path',
28
+ },
29
+ {input: `//${TEST_USERINFO}@example.test/path#fragment`, expected: '//example.test/path'},
30
+ {input: '/api/messages?secret=x', expected: '/api/messages'},
31
+ {input: '', expected: undefined},
32
+ {input: 42, expected: undefined},
33
+ ].forEach(({input, expected}) => {
34
+ it(`sanitizes ${JSON.stringify(input)}`, () => {
35
+ assert.strictEqual(removeUrlDetails(input), expected);
36
+ });
37
+ });
38
+ });
39
+
40
+ describe('#sanitizeResourceUrl()', () => {
41
+ [
42
+ {
43
+ input: ` https://${TEST_USERINFO}@example.test/app.js?secret=x `,
44
+ expected: 'https://example.test/app.js',
45
+ },
46
+ {input: '/assets/app.js?secret=x', expected: '/assets/app.js'},
47
+ {input: 'data:text/plain,secret', expected: undefined},
48
+ {input: 'blob:https://example.test/id', expected: undefined},
49
+ {input: undefined, expected: undefined},
50
+ ].forEach(({input, expected}) => {
51
+ it(`sanitizes ${JSON.stringify(input)}`, () => {
52
+ assert.strictEqual(sanitizeResourceUrl(input), expected);
53
+ });
54
+ });
55
+
56
+ it('caps resource URLs at 2048 characters', () => {
57
+ assert.lengthOf(sanitizeResourceUrl(`/${'x'.repeat(3_000)}`) as string, 2_048);
58
+ });
59
+ });
60
+
61
+ describe('#removeUrlDetailsFromText()', () => {
62
+ [
63
+ {
64
+ input: `url=https://${TEST_USERINFO}@example.test/path?secret=x`,
65
+ expected: 'url=https://example.test/path',
66
+ },
67
+ {input: 'payload=data:text/plain,secret', expected: 'payload=[redacted-url]'},
68
+ {input: 'GET /api/messages?secret=x', expected: 'GET /api/messages'},
69
+ {input: 'at load (../app.js#fragment:10:20)', expected: 'at load (../app.js)'},
70
+ {input: 'retry api/messages?secret=x', expected: 'retry api/messages'},
71
+ {input: 'at load (app.js?secret=x:10:20)', expected: 'at load (app.js)'},
72
+ {input: 'GET api?secret=x', expected: 'GET api'},
73
+ ].forEach(({input, expected}) => {
74
+ it(`sanitizes ${input}`, () => {
75
+ assert.equal(removeUrlDetailsFromText(input), expected);
76
+ });
77
+ });
78
+ });
79
+
80
+ describe('#createFingerprint()', () => {
81
+ it('returns a stable eight-character key that changes with its input', () => {
82
+ const fingerprint = createFingerprint('same error');
83
+
84
+ assert.lengthOf(fingerprint, 8);
85
+ assert.equal(createFingerprint('same error'), fingerprint);
86
+ assert.notEqual(createFingerprint('different error'), fingerprint);
87
+ });
88
+ });
89
+
90
+ describe('#stringifyReason()', () => {
91
+ it('serializes strings and objects', () => {
92
+ assert.equal(stringifyReason('failed'), 'failed');
93
+ assert.equal(stringifyReason({message: 'failed'}), '{"message":"failed"}');
94
+ });
95
+
96
+ it('falls back safely when conversion hooks throw', () => {
97
+ const reason = new Proxy(
98
+ {},
99
+ {
100
+ get() {
101
+ throw new Error('unreadable');
102
+ },
103
+ }
104
+ );
105
+
106
+ assert.equal(stringifyReason(reason), 'Unserializable rejection reason');
107
+ });
108
+ });
109
+ });