Skip to content

Commit 83732ff

Browse files
fix: add Breadcrumbs definition to RaygunPayload (#539)
* add Breadcrumb onBeforeSend test and to typescript types * add typescript compilation test * removed unused test
1 parent ae3cbfb commit 83732ff

File tree

5 files changed

+141
-2
lines changed

5 files changed

+141
-2
lines changed

package-lock.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@
3737
"grunt-contrib-watch": "^1.1.0",
3838
"grunt-string-replace": "^1.3.3",
3939
"jasmine": "^5.8.0",
40+
"typescript": "^5.8.3",
4041
"underscore": "^1.13.7"
4142
},
4243
"scripts": {
4344
"test": "npm run jasmine && npm run wdio",
44-
"jasmine": "jasmine --config=jasmine.json",
45+
"jasmine": "jasmine --config=jasmine.json && jasmine tests/specs/typescript-definitions.js",
4546
"wdio": "cross-env node_modules/.bin/wdio wdio.conf.js"
4647
},
4748
"keywords": [
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* globals describe, it, expect */
2+
3+
var { exec } = require('child_process');
4+
var path = require('path');
5+
6+
describe("TypeScript Definitions", function() {
7+
it("should compile without errors", function(done) {
8+
var tsFile = path.join(__dirname, '../types-test.ts');
9+
var cmd = 'npx tsc --noEmit ' + tsFile + ' --strict';
10+
11+
exec(cmd, function(error, stdout, stderr) {
12+
if (error) {
13+
console.error('TypeScript compilation failed:', error);
14+
console.error('stdout:', stdout);
15+
console.error('stderr:', stderr);
16+
expect(error).toBeNull();
17+
} else {
18+
console.log('TypeScript compilation succeeded');
19+
}
20+
done();
21+
});
22+
});
23+
});

tests/types-test.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { RaygunPayload, RaygunStatic } from '../types/index';
2+
3+
// Test RaygunPayload interface
4+
function testPayloadStructure(): void {
5+
const payload: RaygunPayload = {
6+
OccurredOn: new Date(),
7+
Details: {
8+
Error: {
9+
ClassName: 'Error',
10+
Message: 'Test error',
11+
StackTrace: []
12+
},
13+
Environment: {
14+
UtcOffset: 0,
15+
"User-Language": 'en-US',
16+
"Document-Mode": 11,
17+
"Browser-Width": 1920,
18+
"Browser-Height": 1080,
19+
"Screen-Width": 1920,
20+
"Screen-Height": 1080,
21+
"Color-Depth": 24,
22+
Browser: 'Chrome',
23+
"Browser-Name": 'Chrome',
24+
"Browser-Version": '120.0.0',
25+
Platform: 'Linux'
26+
},
27+
Client: {
28+
Name: 'raygun4js',
29+
Version: '3.1.3'
30+
},
31+
UserCustomData: {},
32+
Tags: [],
33+
Request: {
34+
Url: 'https://example.com',
35+
QueryString: '',
36+
Headers: {
37+
"User-Agent": 'Mozilla/5.0',
38+
Referer: 'https://example.com',
39+
Host: 'example.com'
40+
}
41+
},
42+
Version: '1.0.0',
43+
User: {
44+
Identifier: 'test-user',
45+
IsAnonymous: false,
46+
47+
FullName: 'Test User',
48+
FirstName: 'Test',
49+
UUID: 'test-uuid'
50+
},
51+
GroupingKey: 'test-group',
52+
Breadcrumbs: [
53+
{
54+
type: 'manual',
55+
message: 'Test breadcrumb',
56+
level: 'info',
57+
metadata: { test: true }
58+
}
59+
]
60+
}
61+
};
62+
}
63+
64+
// Test that onBeforeSend callback can access and modify breadcrumbs
65+
function testOnBeforeSendBreadcrumbAccess(): void {
66+
// Mock Raygun instance
67+
const raygun = {} as RaygunStatic;
68+
69+
// This should compile without TypeScript errors
70+
raygun.onBeforeSend((payload: RaygunPayload) => {
71+
// Access breadcrumbs
72+
if (payload.Details.Breadcrumbs) {
73+
// Filter out sensitive breadcrumbs
74+
payload.Details.Breadcrumbs = payload.Details.Breadcrumbs.filter(breadcrumb => {
75+
return breadcrumb.message !== 'sensitive-operation';
76+
});
77+
78+
// Sanitize breadcrumb messages
79+
payload.Details.Breadcrumbs = payload.Details.Breadcrumbs.map(breadcrumb => ({
80+
...breadcrumb,
81+
message: breadcrumb.message?.replace(/password|secret|token/gi, '[REDACTED]')
82+
}));
83+
}
84+
85+
return payload;
86+
});
87+
}
88+
89+
export {
90+
testPayloadStructure,
91+
testOnBeforeSendBreadcrumbAccess,
92+
};

types/index.d.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ interface RaygunStackTrace {
2323
MethodName: string;
2424
}
2525

26+
interface RaygunBreadcrumb {
27+
type?: string;
28+
message?: string;
29+
level?: BreadcrumbLevel;
30+
metadata?: any;
31+
}
32+
2633
interface RaygunOptions {
2734
/**
2835
* Posts error payloads over HTTP. This allows IE8 to send JS errors.
@@ -171,6 +178,7 @@ interface RaygunPayload {
171178
UUID?: any;
172179
};
173180
GroupingKey?: string | undefined;
181+
Breadcrumbs?: RaygunBreadcrumb[];
174182
};
175183
}
176184

@@ -432,6 +440,6 @@ interface Window {
432440
Raygun: RaygunStatic;
433441
}
434442

435-
export { BreadcrumbLevel, RaygunOptions, RaygunPayload, RaygunStackTrace, RaygunStatic, RaygunV2, RaygunV2UserDetails };
443+
export { BreadcrumbLevel, RaygunBreadcrumb, RaygunOptions, RaygunPayload, RaygunStackTrace, RaygunStatic, RaygunV2, RaygunV2UserDetails };
436444

437445
export default rg4js;

0 commit comments

Comments
 (0)