Skip to content
Draft
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: 4 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Use Node.js from .nvmrc
uses: actions/setup-node@v3
uses: actions/setup-node@v6
with:
node-version-file: '.nvmrc'
- run: corepack enable
- run: yarn install
- run: yarn lint-test

Expand All @@ -22,8 +23,9 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Use Node.js from .nvmrc
uses: actions/setup-node@v3
uses: actions/setup-node@v6
with:
node-version-file: '.nvmrc'
- run: corepack enable
- run: yarn install
- run: yarn build
3 changes: 2 additions & 1 deletion .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
- uses: actions/setup-node@v6
with:
node-version-file: '.nvmrc'
registry-url: https://registry.npmjs.org/
- run: corepack enable
- run: yarn
- run: yarn lint-test
- run: yarn build
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ typings/
# Output of 'npm pack'
*.tgz

# Yarn Integrity file
# Yarn files
.yarn-integrity
.yarn

# dotenv environment variables file
.env
Expand Down
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
"name": "hawk.javascript",
"type": "module",
"version": "0.0.0",
"packageManager": "yarn@4.12.0",
"workspaces": [
"packages/*"
"packages/core",
"packages/browser",
"packages/sveltekit"
],
"scripts": {
"dev": "yarn workspace @hawk.so/javascript dev",
"build": "yarn workspace @hawk.so/javascript build",
"stats": "yarn workspace @hawk.so/javascript stats",
"dev": "yarn workspace @hawk.so/browser dev",
"build": "yarn workspace @hawk.so/browser build",
"stats": "yarn workspace @hawk.so/browser stats",
"lint": "eslint -c ./.eslintrc.cjs packages/*/src --ext .ts,.js --fix",
"lint-test": "eslint -c ./.eslintrc.cjs packages/*/src --ext .ts,.js"
},
Expand All @@ -23,7 +26,6 @@
"eslint-config-codex": "^1.6.1",
"rollup-plugin-license": "^3.5.3",
"size-limit": "^11.1.6",
"typescript": "^5.6.3",
"vite": "^5.4.9"
"typescript": "^5.9.3"
}
}
17 changes: 6 additions & 11 deletions packages/javascript/README.md → packages/browser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,12 @@ const hawk = new HawkCatcher({

### Breadcrumbs Options

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `maxBreadcrumbs` | `number` | `15` | Maximum number of breadcrumbs to store. When the limit is reached, oldest breadcrumbs are removed (FIFO). |
| `trackFetch` | `boolean` | `true` | Automatically track `fetch()` and `XMLHttpRequest` calls as breadcrumbs. Captures request URL, method, status code, and response time. |
| `trackNavigation` | `boolean` | `true` | Automatically track navigation events (History API: `pushState`, `replaceState`, `popstate`). Captures route changes. |
| `trackClicks` | `boolean` | `true` | Automatically track UI click events. Captures element selector, coordinates, and other click metadata. |
| Option | Type | Default | Description |
|--------------------|------------|-------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `maxBreadcrumbs` | `number` | `15` | Maximum number of breadcrumbs to store. When the limit is reached, oldest breadcrumbs are removed (FIFO). |
| `trackFetch` | `boolean` | `true` | Automatically track `fetch()` and `XMLHttpRequest` calls as breadcrumbs. Captures request URL, method, status code, and response time. |
| `trackNavigation` | `boolean` | `true` | Automatically track navigation events (History API: `pushState`, `replaceState`, `popstate`). Captures route changes. |
| `trackClicks` | `boolean` | `true` | Automatically track UI click events. Captures element selector, coordinates, and other click metadata. |
| `beforeBreadcrumb` | `function` | `undefined` | Hook called before each breadcrumb is stored. Receives `(breadcrumb, hint)` and can return modified breadcrumb, `null` to discard it, or the original breadcrumb. Useful for filtering sensitive data or PII. |

### Manual Breadcrumbs
Expand Down Expand Up @@ -310,8 +310,3 @@ const hawk = new HawkCatcher({
token: 'INTEGRATION_TOKEN'
});
```

## License

This project is licensed under the **GNU Affero General Public License v3.0 (AGPL-3.0)**.
See the [LICENSE](./LICENSE) file for the full text.
18 changes: 10 additions & 8 deletions packages/javascript/package.json → packages/browser/package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"name": "@hawk.so/javascript",
"version": "3.2.14",
"description": "JavaScript errors tracking for Hawk.so",
"name": "@hawk.so/browser",
"version": "1.0.0",
"description": "Browser JavaScript errors tracking for Hawk.so",
"files": [
"dist"
],
"main": "./dist/hawk.umd.js",
"module": "./dist/hawk.mjs",
"main": "./dist/hawk-browser.umd.js",
"module": "./dist/hawk-browser.mjs",
"types": "dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/hawk.mjs",
"require": "./dist/hawk.umd.js"
"import": "./dist/hawk-browser.mjs",
"require": "./dist/hawk-browser.umd.js"
}
},
"scripts": {
Expand All @@ -24,7 +24,7 @@
"repository": {
"type": "git",
"url": "git+https://github.com/codex-team/hawk.javascript.git",
"directory": "packages/javascript"
"directory": "packages/browser"
},
"author": {
"name": "CodeX",
Expand All @@ -36,10 +36,12 @@
},
"homepage": "https://github.com/codex-team/hawk.javascript#readme",
"dependencies": {
"@hawk.so/core": "^1.0.0",
"error-stack-parser": "^2.1.4"
},
"devDependencies": {
"@hawk.so/types": "0.5.2",
"vite": "^7.3.1",
"vite-plugin-dts": "^4.2.4",
"vue": "^2"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
* @file Breadcrumbs module - captures chronological trail of events before an error
*/
import type { Breadcrumb, BreadcrumbLevel, BreadcrumbType, Json, JsonNode } from '@hawk.so/types';
import Sanitizer from '../modules/sanitizer';
import { Sanitizer, log } from '@hawk.so/core';
import { buildElementSelector } from '../utils/selector';
import log from '../utils/log';

/**
* Default maximum number of breadcrumbs to store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file Module for intercepting console logs with stack trace capture
*/
import type { ConsoleLogEvent } from '@hawk.so/types';
import Sanitizer from '../modules/sanitizer';
import { Sanitizer } from '@hawk.so/core';

/**
* Maximum number of console logs to store
Expand Down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this file is bloated and a significant part of it can be reusable as a core module.

  • we can create an abstract class definining base structure of any catcher. type (protected), context, user, getIntegrationId, getRelease, getType, getRawData, etc can be moved there.
  • setUser, setContext - reusable
  • maybe some other utilities. StackParser, etc

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Socket from './modules/socket';
import Sanitizer from './modules/sanitizer';
import log from './utils/log';
import { Sanitizer, isErrorProcessed, markErrorAsProcessed, validateUser, validateContext, log, EventRejectedError } from '@hawk.so/core';
import StackParser from './modules/stackParser';
import type { CatcherMessage, HawkInitialSettings, BreadcrumbsAPI } from './types';
import { VueIntegration } from './integrations/vue';
Expand All @@ -13,12 +12,9 @@ import type {
Json, EncodedIntegrationToken, DecodedIntegrationToken,
} from '@hawk.so/types';
import type { JavaScriptCatcherIntegrations } from './types/integrations';
import { EventRejectedError } from './errors';
import type { HawkJavaScriptEvent } from './types';
import { isErrorProcessed, markErrorAsProcessed } from './utils/event';
import { ConsoleCatcher } from './addons/consoleCatcher';
import { BreadcrumbManager } from './addons/breadcrumbs';
import { validateUser, validateContext } from './utils/validation';

/**
* Allow to use global VERSION, that will be overwritten by Webpack
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import log from '../utils/log';
import { log } from '@hawk.so/core';

/**
* Sends AJAX request and wait for some time.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import log from '../utils/log';
import { log } from '@hawk.so/core';
import type { CatcherMessage } from '@/types';

/**
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default defineConfig(() => {
lib: {
entry: path.resolve(__dirname, 'src', 'index.ts'),
name: 'HawkCatcher',
fileName: 'hawk',
fileName: 'hawk-browser',
},
rollupOptions: {
plugins: [
Expand All @@ -36,8 +36,8 @@ export default defineConfig(() => {
return false;
}

// Allow MIT and Apache-2.0 licenses.
return ['MIT', 'Apache-2.0'].includes(dependency.license);
// Allow MIT, Apache-2.0, and AGPL-3.0-only (for @hawk.so/core) licenses.
return ['MIT', 'Apache-2.0', 'AGPL-3.0-only'].includes(dependency.license);
},
failOnUnlicensed: true,
failOnViolation: true,
Expand Down
40 changes: 40 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "@hawk.so/core",
"version": "1.0.0",
"description": "Core utilities for Hawk.so error tracking SDKs",
"files": [
"dist"
],
"main": "./dist/hawk-core.umd.js",
"module": "./dist/hawk-core.mjs",
"types": "dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/hawk-core.mjs",
"require": "./dist/hawk-core.umd.js"
}
},
"scripts": {
"build": "vite build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/codex-team/hawk.javascript.git",
"directory": "packages/core"
},
"author": {
"name": "CodeX",
"email": "team@codex.so"
},
"license": "AGPL-3.0-only",
"bugs": {
"url": "https://github.com/codex-team/hawk.javascript/issues"
},
"homepage": "https://github.com/codex-team/hawk.javascript#readme",
"devDependencies": {
"@hawk.so/types": "0.5.2",
"vite": "^7.3.1",
"vite-plugin-dts": "^4.2.4"
}
}
File renamed without changes.
12 changes: 12 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @hawk.so/core
*
* Core utilities for Hawk.so error tracking SDKs
* Environment-agnostic code that can be used in browser and server environments
*/

export { EventRejectedError } from './errors';
export { default as Sanitizer } from './modules/sanitizer';
export { isErrorProcessed, markErrorAsProcessed } from './utils/event';
export { validateUser, validateContext } from './utils/validation';
export { default as log } from './utils/log';
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ export default class Sanitizer {
}

/**
* Check if passed variable is an HTML Element
* Check if passed variable is an HTML Element (environment-agnostic)
*
* @param target - variable to check
*/
private static isElement(target: any): boolean {
return target instanceof Element;
return typeof Element !== 'undefined' && target instanceof Element;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* Logger module
* Logger module (environment-agnostic)
*
* @example
* log('We got an error', 'error')
*/

/**
* Allow to use global VERSION, that will be overwritten by Webpack
* Allow to use global VERSION, that will be overwritten by Vite
*/
declare const VERSION: string;

Expand All @@ -20,7 +20,7 @@ declare const VERSION: string;
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export default function log(msg: string, type = 'log', args?: any, style = 'color: inherit'): void {
if (!('console' in window) || !window.console[type]) {
if (typeof console === 'undefined' || typeof console[type] !== 'function') {
return;
}

Expand Down
11 changes: 11 additions & 0 deletions packages/core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"baseUrl": "."
},
"include": [
"src/**/*"
]
}
56 changes: 56 additions & 0 deletions packages/core/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import path from 'path';
import dts from 'vite-plugin-dts';
import { defineConfig } from 'vite';

import license from 'rollup-plugin-license';

import * as pkg from './package.json';

const NODE_ENV = process.argv.mode || 'development';
const VERSION = pkg.version;

export default defineConfig(() => {
return {
build: {
copyPublicDir: false,
lib: {
entry: path.resolve(__dirname, 'src', 'index.ts'),
name: 'HawkCore',
fileName: 'hawk-core',
},
rollupOptions: {
plugins: [
license({
thirdParty: {
allow: {
test: (dependency) => {
// Return false for unlicensed dependencies.
if (!dependency.license) {
return false;
}

// Allow MIT and Apache-2.0 licenses.
return ['MIT', 'Apache-2.0'].includes(dependency.license);
},
failOnUnlicensed: true,
failOnViolation: true,
},
output: path.resolve(__dirname, 'dist', 'vendor.LICENSE.txt'),
},
}),
],
},
},

define: {
'NODE_ENV': JSON.stringify(NODE_ENV),
'VERSION': JSON.stringify(VERSION),
},

plugins: [
dts({
tsconfigPath: './tsconfig.json',
}),
],
};
});
4 changes: 0 additions & 4 deletions packages/javascript/.babelrc

This file was deleted.

Loading