Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@
"grunt-contrib-watch": "^1.1.0",
"grunt-string-replace": "^1.3.3",
"jasmine": "^5.8.0",
"typescript": "^5.8.3",
"underscore": "^1.13.7"
},
"scripts": {
"test": "npm run jasmine && npm run wdio",
"jasmine": "jasmine --config=jasmine.json",
"jasmine": "jasmine --config=jasmine.json && jasmine tests/specs/typescript-definitions.js",
"wdio": "cross-env node_modules/.bin/wdio wdio.conf.js"
},
"keywords": [
Expand Down
23 changes: 23 additions & 0 deletions tests/specs/typescript-definitions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* globals describe, it, expect */

var { exec } = require('child_process');
var path = require('path');

describe("TypeScript Definitions", function() {
it("should compile without errors", function(done) {
var tsFile = path.join(__dirname, '../types-test.ts');
var cmd = 'npx tsc --noEmit ' + tsFile + ' --strict';

exec(cmd, function(error, stdout, stderr) {
if (error) {
console.error('TypeScript compilation failed:', error);
console.error('stdout:', stdout);
console.error('stderr:', stderr);
expect(error).toBeNull();
} else {
console.log('TypeScript compilation succeeded');
}
done();
});
});
});
92 changes: 92 additions & 0 deletions tests/types-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { RaygunPayload, RaygunStatic } from '../types/index';

// Test RaygunPayload interface
function testPayloadStructure(): void {
const payload: RaygunPayload = {
OccurredOn: new Date(),
Details: {
Error: {
ClassName: 'Error',
Message: 'Test error',
StackTrace: []
},
Environment: {
UtcOffset: 0,
"User-Language": 'en-US',
"Document-Mode": 11,
"Browser-Width": 1920,
"Browser-Height": 1080,
"Screen-Width": 1920,
"Screen-Height": 1080,
"Color-Depth": 24,
Browser: 'Chrome',
"Browser-Name": 'Chrome',
"Browser-Version": '120.0.0',
Platform: 'Linux'
},
Client: {
Name: 'raygun4js',
Version: '3.1.3'
},
UserCustomData: {},
Tags: [],
Request: {
Url: 'https://example.com',
QueryString: '',
Headers: {
"User-Agent": 'Mozilla/5.0',
Referer: 'https://example.com',
Host: 'example.com'
}
},
Version: '1.0.0',
User: {
Identifier: 'test-user',
IsAnonymous: false,
Email: '[email protected]',
FullName: 'Test User',
FirstName: 'Test',
UUID: 'test-uuid'
},
GroupingKey: 'test-group',
Breadcrumbs: [
{
type: 'manual',
message: 'Test breadcrumb',
level: 'info',
metadata: { test: true }
}
]
}
};
}

// Test that onBeforeSend callback can access and modify breadcrumbs
function testOnBeforeSendBreadcrumbAccess(): void {
// Mock Raygun instance
const raygun = {} as RaygunStatic;

// This should compile without TypeScript errors
raygun.onBeforeSend((payload: RaygunPayload) => {
// Access breadcrumbs
if (payload.Details.Breadcrumbs) {
// Filter out sensitive breadcrumbs
payload.Details.Breadcrumbs = payload.Details.Breadcrumbs.filter(breadcrumb => {
return breadcrumb.message !== 'sensitive-operation';
});

// Sanitize breadcrumb messages
payload.Details.Breadcrumbs = payload.Details.Breadcrumbs.map(breadcrumb => ({
...breadcrumb,
message: breadcrumb.message?.replace(/password|secret|token/gi, '[REDACTED]')
}));
}

return payload;
});
}

export {
testPayloadStructure,
testOnBeforeSendBreadcrumbAccess,
};
10 changes: 9 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ interface RaygunStackTrace {
MethodName: string;
}

interface RaygunBreadcrumb {
type?: string;
message?: string;
level?: BreadcrumbLevel;
metadata?: any;
}

interface RaygunOptions {
/**
* Posts error payloads over HTTP. This allows IE8 to send JS errors.
Expand Down Expand Up @@ -171,6 +178,7 @@ interface RaygunPayload {
UUID?: any;
};
GroupingKey?: string | undefined;
Breadcrumbs?: RaygunBreadcrumb[];
};
}

Expand Down Expand Up @@ -432,6 +440,6 @@ interface Window {
Raygun: RaygunStatic;
}

export { BreadcrumbLevel, RaygunOptions, RaygunPayload, RaygunStackTrace, RaygunStatic, RaygunV2, RaygunV2UserDetails };
export { BreadcrumbLevel, RaygunBreadcrumb, RaygunOptions, RaygunPayload, RaygunStackTrace, RaygunStatic, RaygunV2, RaygunV2UserDetails };

export default rg4js;