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

feat: check-ins configuration api #1241

Merged
merged 15 commits into from
Nov 14, 2023
5 changes: 3 additions & 2 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export type ProcessStats = {
}

export type TransportOptions = {
method: 'GET' | 'POST',
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE',
headers?: Record<string, number | string | string[] | undefined>,
endpoint: string,
maxObjectDepth?: number,
Expand Down Expand Up @@ -162,7 +162,8 @@ export type NoticeTransportPayload = {
}

export interface Transport {
send(options: TransportOptions, payload?: NoticeTransportPayload | undefined): Promise<{ statusCode: number; body: string; }>
defaultHeaders: () => Record<string, string>
send<T>(options: TransportOptions, payload?: T): Promise<{ statusCode: number; body: string; }>
}

export interface HoneybadgerStore {
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as stackTraceParser from 'stacktrace-parser'
import { Client } from './client'
import {
Logger, BacktraceFrame, Notice, Noticeable, BeforeNotifyHandler, AfterNotifyHandler, Config, BrowserConfig
} from './types'
Expand Down Expand Up @@ -290,7 +289,7 @@ export function sanitize(obj, maxDepth = 8) {
return safeSerialize(obj)
}

export function logger(client: Client): Logger {
export function logger(client: { config: { debug: boolean; logger: Logger; } }): Logger {
Copy link
Member Author

Choose a reason for hiding this comment

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

Support more than one client (CheckinsClient and HoneybadgerClient)

const log = (method: string) => {
return function (...args: unknown[]) {
if (method === 'debug') {
Expand Down
7 changes: 5 additions & 2 deletions packages/core/test/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Client as BaseClient } from '../src/client'
import { Config, Logger, Notice, Noticeable, Transport, TransportOptions, NoticeTransportPayload, UserFeedbackFormOptions } from '../src/types'
import { Config, Logger, Notice, Noticeable, Transport, TransportOptions, UserFeedbackFormOptions } from '../src/types'

export function nullLogger(): Logger {
return {
Expand All @@ -12,7 +12,10 @@ export function nullLogger(): Logger {
}

export class TestTransport implements Transport {
send(_options: TransportOptions, _payload: NoticeTransportPayload): Promise<{ statusCode: number; body: string }> {
defaultHeaders(): Record<string, string> {
return {};
}
send<T>(_options: TransportOptions, _payload: T): Promise<{ statusCode: number; body: string }> {
Copy link
Member Author

Choose a reason for hiding this comment

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

Made the payload to be generic because I didn't want to define the payload for check-ins here (check-ins are not part of the core package)

return Promise.resolve({ body: JSON.stringify({ id: 'uuid' }), statusCode: 201 });
}
}
Expand Down
20 changes: 20 additions & 0 deletions packages/js/examples/checkins-manager/honeybadger.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
personalAuthToken: process.env.HONEYBADGER_PERSONAL_AUTH_TOKEN,
checkins: [
{
name: 'Weekly Exports',
slug: 'weekly-exports-custom-slug',
projectId: process.env.HONEYBADGER_PROJECT_ID,
scheduleType: 'simple',
reportPeriod: '1 week',
gracePeriod: '10 minutes'
},
{
name: 'Hourly Notifications',
projectId: process.env.HONEYBADGER_PROJECT_ID,
scheduleType: 'simple',
reportPeriod: '1 hour',
gracePeriod: '5 minutes'
}
]
}
4 changes: 4 additions & 0 deletions packages/js/examples/checkins-manager/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Honeybadger from '@honeybadger-io/js'

console.log('Hello from checkins-manager')
console.log(Honeybadger.config)
59 changes: 59 additions & 0 deletions packages/js/examples/checkins-manager/package-lock.json

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

15 changes: 15 additions & 0 deletions packages/js/examples/checkins-manager/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "checkins-manager",
"version": "1.0.0",
"description": "an example that demonstrates checkins configuration api",
"main": "index.mjs",
"scripts": {
"start": "node index.mjs",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"@honeybadger-io/js": "file:../.."
},
"author": "",
"license": "ISC"
}
Loading
Loading