Skip to content
Open
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
4 changes: 3 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ jobs:
CI_JOB_NUMBER: 2
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 0
- name: Use Node.js from .nvmrc
uses: actions/setup-node@v6
with:
node-version-file: '.nvmrc'
- run: corepack enable
- run: yarn install
- run: yarn workspace @hawk.so/javascript test
- run: yarn test:modified origin/${{ github.event.pull_request.base.ref }}

build:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"dev": "yarn workspace @hawk.so/javascript dev",
"build:all": "yarn workspaces foreach -Apt run build",
"build:modified": "yarn workspaces foreach --since=\"$@\" -Rpt run build",
"test:all": "yarn workspaces foreach -Apt run test",
"test:modified": "yarn workspaces foreach --since=\"$@\" -Rpt run test",
"stats": "yarn workspace @hawk.so/javascript stats",
"lint": "eslint -c ./.eslintrc.cjs packages/*/src --ext .ts,.js --fix",
"lint-test": "eslint -c ./.eslintrc.cjs packages/*/src --ext .ts,.js"
Expand Down
12 changes: 10 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
}
},
"scripts": {
"build": "vite build"
"build": "vite build",
"test": "vitest run",
"test:coverage": "vitest run --coverage",
"lint": "eslint --fix \"src/**/*.{js,ts}\""
},
"repository": {
"type": "git",
Expand All @@ -33,8 +36,13 @@
"url": "https://github.com/codex-team/hawk.javascript/issues"
},
"homepage": "https://github.com/codex-team/hawk.javascript#readme",
"dependencies": {
"@hawk.so/types": "0.5.8"
},
"devDependencies": {
"@vitest/coverage-v8": "^4.0.18",
"vite": "^7.3.1",
"vite-plugin-dts": "^4.2.4"
"vite-plugin-dts": "^4.2.4",
"vitest": "^4.0.18"
}
}
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
@@ -1 +1,13 @@
export type { HawkStorage } from './storages/hawk-storage';
export type { RandomGenerator } from './utils/random';
export { HawkUserManager } from './users/hawk-user-manager';
export type { Logger, LogType } from './logger/logger';
export { isLoggerSet, setLogger, resetLogger, log } from './logger/logger';
export { Sanitizer } from './modules/sanitizer';
export type { SanitizerTypeHandler } from './modules/sanitizer';
export { StackParser } from './modules/stack-parser';
export { buildElementSelector } from './utils/selector';
export type { Transport } from './transports/transport';
export { EventRejectedError } from './errors';
export { isErrorProcessed, markErrorAsProcessed } from './utils/event';
export { isPlainObject, validateUser, validateContext, isValidEventPayload, isValidBreadcrumb } from './utils/validation';
68 changes: 68 additions & 0 deletions packages/core/src/logger/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Log level type for categorizing log messages.
*
* Includes standard console methods supported in both browser and Node.js:
* - Standard levels: `log`, `warn`, `error`, `info`
* - Performance timing: `time`, `timeEnd`
*/
export type LogType = 'log' | 'warn' | 'error' | 'info' | 'time' | 'timeEnd';

/**
* Logger function interface for environment-specific logging implementations.
*
* Implementations should handle message formatting, output styling,
* and platform-specific logging mechanisms (e.g., console, file, network).
*
* @param msg - The message to log.
* @param type - Log level/severity (default: 'log').
* @param args - Additional data to include with the log message.
*/
export interface Logger {
(msg: string, type?: LogType, args?: unknown): void;
}

/**
* Global logger instance, set by environment-specific packages.
*/
let loggerInstance: Logger | null = null;

/**
* Checks if logger instance has been registered.
*/
export function isLoggerSet(): boolean {
return loggerInstance !== null;
}

/**
* Registers the environment-specific logger implementation.
*
* This should be called once during application initialization
* by the environment-specific package.
*
* @param logger - Logger implementation to use globally.
*/
export function setLogger(logger: Logger): void {
loggerInstance = logger;
}

/**
* Clears the registered logger instance.
*/
export function resetLogger(): void {
loggerInstance = null;
}

/**
* Logs a message using the registered logger implementation.
*
* If no logger has been registered via {@link setLogger}, this is a no-op.
*
* @param msg - Message to log.
* @param type - Log level (default: 'log').
* @param args - Additional arguments to log.
*/
export function log(msg: string, type?: LogType, args?: unknown): void {
if (loggerInstance) {
loggerInstance(msg, type, args);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import log from '../utils/log';
import { log } from '../logger/logger';

/**
* Sends AJAX request and wait for some time.
Expand Down
Loading
Loading