Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(types): improve event type #105

Merged
merged 7 commits into from
Oct 13, 2024
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
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ jobs:
CI_JOB_NUMBER: 1
steps:
- uses: actions/checkout@v1
- name: Use Node.js 12.x
- name: Use Node.js 16.x
uses: actions/setup-node@v1
with:
node-version: 12.x
node-version: 16.x
- run: yarn install
- run: yarn lint-test
# - uses: andresz1/[email protected]
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
# skip_step: build
# skip_step: build
2 changes: 1 addition & 1 deletion .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
node-version: 16
registry-url: https://registry.npmjs.org/
- run: yarn
- run: yarn lint-test
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Initialization settings:
| `token` | string | **required** | Your project's Integration Token |
| `release` | string/number | optional | Unique identifier of the release. Used for source map consuming (see below) |
| `user` | {id: string, name?: string, image?: string, url?: string} | optional | Current authenticated user |
| `context` | object | optional | Any data you want to pass with every message. |
| `context` | object | optional | Any data you want to pass with every message. Has limitation of length. |
| `vue` | Vue constructor | optional | Pass Vue constructor to set up the [Vue integration](#integrate-to-vue-application) |
| `disableGlobalErrorsHandling` | boolean | optional | Do not initialize global errors handling |
| `beforeSend` | function(event) => event | optional | This Method allows you to filter any data you don't want sending to Hawk |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hawk.so/javascript",
"version": "3.0.4",
"version": "3.0.5",
"description": "JavaScript errors tracking for Hawk.so",
"main": "./dist/hawk.js",
"types": "./dist/index.d.ts",
Expand Down
16 changes: 7 additions & 9 deletions src/catcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import { generateRandomId } from './utils';
import {
AffectedUser,
BacktraceFrame,
EventContext,
JavaScriptAddons,
VueIntegrationAddons,
Expand Down Expand Up @@ -183,7 +182,7 @@
*
* @param vue - Vue app
*/
public connectVue(vue): void {

Check warning on line 185 in src/catcher.ts

View workflow job for this annotation

GitHub Actions / main

Argument 'vue' should be typed
// eslint-disable-next-line no-new
new VueIntegration(vue, (error: Error, addons: VueIntegrationAddons) => {
this.formatAndSend(error, {
Expand Down Expand Up @@ -267,8 +266,6 @@
* @param errorFormatted - formatted error to send
*/
private sendErrorFormatted(errorFormatted: CatcherMessage): void {
console.log('send', errorFormatted);

this.transport.send(errorFormatted)
.catch((sendingError) => {
log('WebSocket sending error', 'error', sendingError);
Expand All @@ -290,6 +287,7 @@
user: this.getUser(),
addons: this.getAddons(error),
backtrace: await this.getBacktrace(error),
catcherVersion: this.version,
};

/**
Expand Down Expand Up @@ -338,7 +336,7 @@
*
* @param error - caught error
*/
private getType(error: Error | string): string {
private getType(error: Error | string): HawkJavaScriptEvent['type'] {
const notAnError = !(error instanceof Error);

/**
Expand All @@ -355,7 +353,7 @@
/**
* Release version
*/
private getRelease(): string | null {
private getRelease(): HawkJavaScriptEvent['release'] {
return this.release || null;
}

Expand All @@ -382,7 +380,7 @@
*
* @param context - any additional data passed by user
*/
private getContext(context?: EventContext): EventContext {
private getContext(context?: EventContext): HawkJavaScriptEvent['context'] {
const contextMerged = {};

if (this.context !== undefined) {
Expand All @@ -399,7 +397,7 @@
/**
* Current authenticated user
*/
private getUser(): AffectedUser | null {
private getUser(): HawkJavaScriptEvent['user'] {
return this.user || null;
}

Expand Down Expand Up @@ -432,7 +430,7 @@
*
* @param error - event from which to get backtrace
*/
private async getBacktrace(error: Error | string): Promise<BacktraceFrame[] | null> {
private async getBacktrace(error: Error | string): Promise<HawkJavaScriptEvent['backtrace']> {
const notAnError = !(error instanceof Error);

/**
Expand All @@ -457,7 +455,7 @@
*
* @param {Error|string} error — caught error
*/
private getAddons(error: Error | string): JavaScriptAddons {
private getAddons(error: Error | string): HawkJavaScriptEvent['addons'] {
const { innerWidth, innerHeight } = window;
const userAgent = window.navigator.userAgent;
const location = window.location.href;
Expand Down
10 changes: 2 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import 'regenerator-runtime/runtime';
import Catcher from './catcher';
import { HawkInitialSettings, AffectedUser } from './types/hawk-initial-settings';
import { HawkJavaScriptEvent } from './types/event';
export { AffectedUser } from '@hawk.so/types';
export * from './types';

export default Catcher;

export {
HawkInitialSettings,
AffectedUser,
HawkJavaScriptEvent
};
5 changes: 5 additions & 0 deletions src/modules/sanitizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export default class Sanitizer {
/**
* If object in stringified JSON will reach this length,
* it will be represented as "<big object>"
*
* @todo export this value to the settings
*/
private static readonly maxObjectLen: number = 500;

Expand Down Expand Up @@ -266,6 +268,9 @@ export default class Sanitizer {
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-unused-vars-experimental,no-unused-vars
private static formatBigObject(target: any): string {
/**
* @todo save big object structure, but not the content
*/
return '<big object>';
}
}
46 changes: 45 additions & 1 deletion src/types/event.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,50 @@
import type { EventData, JavaScriptAddons } from '@hawk.so/types';

/**
* Event data with JS specific addons
*/
type JSEventData = EventData<JavaScriptAddons>;

/**
* Event will be sent to Hawk by Hawk JavaScript SDK
*
* The listed EventData properties will always be sent, so we define them as required in the type
*/
export type HawkJavaScriptEvent = EventData<JavaScriptAddons>;
export type HawkJavaScriptEvent = Omit<JSEventData, 'type' | 'release' | 'user' | 'context' | 'addons' | 'backtrace' | 'catcherVersion'> & {
/**
* Event type: TypeError, ReferenceError etc
*/
type: JSEventData['type'];

/**
* Current release (aka version, revision) of an application
*/
release: JSEventData['release'] | null;

/**
* Current authenticated user
*/
user: JSEventData['user'] | null;

/**
* Any other information collected and passed by user
*/
context: JSEventData['context'];

/**
*
* Catcher-specific information
*/
addons: JSEventData['addons'];

/**
* Stack
* From the latest call to the earliest
*/
backtrace: JSEventData['backtrace'] | null;

/**
* Catcher version
*/
catcherVersion: JSEventData['catcherVersion'];
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface HawkInitialSettings {
* Enable debug mode
* Send raw event's data additionally in addons field by key 'RAW_EVENT_DATA'
*/
debug: boolean;
debug?: boolean;

/**
* Current release and bundle version
Expand Down Expand Up @@ -66,7 +66,3 @@ export interface HawkInitialSettings {
*/
beforeSend?(event: HawkJavaScriptEvent): HawkJavaScriptEvent;
}

export {
AffectedUser
};
2 changes: 1 addition & 1 deletion src/types/index.d.ts → src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import CatcherMessage from './catcher-message';
import HawkInitialSettings from './hawk-initial-settings';
import { HawkInitialSettings } from './hawk-initial-settings';
import { HawkJavaScriptEvent } from './event';

export {
Expand Down
2 changes: 1 addition & 1 deletion stats.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

Size: 7.3 KB with all dependencies, minified and gzipped
Size: 7.37 KB with all dependencies, minified and gzipped

Loading