Skip to content

Built for people who want to own their automations. Join the waitlist for an invite.

Package listing

@kody/sentry

src/types.ts

200 lines · 4.1 KB · TypeScript
export type JsonRecord = Record<string, unknown>

export type SentryClientOptions = {
	/** API host. Default `sentry.io`. Also `us.sentry.io`, `de.sentry.io`, or a self-hosted hostname. */
	host?: string
	/** Saved Kody secret name. Default `sentryAuthToken`. Ignored when `integration` is set. */
	secretName?: string
	/** Saved Kody OAuth integration name, for example `sentry` or `sentry-work`. */
	integration?: string
}

export type SentryOrganization = JsonRecord & {
	slug: string
	name?: string
}

export type SentryProject = JsonRecord & {
	slug: string
	name?: string
	id?: string
}

export type SentryIssue = JsonRecord & {
	id: string
	title?: string
	shortId?: string
	status?: string
	permalink?: string
}

export type SentryEvent = JsonRecord & {
	id?: string
	eventID?: string
	title?: string
	message?: string
	entries?: unknown[]
	tags?: unknown
	contexts?: unknown
}

export type SearchIssuesInput = SentryClientOptions & {
	orgSlug: string
	query?: string
	statsPeriod?: string
	limit?: number
	project?: string | number | Array<string | number>
	projectSlug?: string
	cursor?: string
}

export type SearchIssuesWithLatestSummariesInput = SearchIssuesInput & {
	summaryOptions?: SummarizeIssueEventOptions
}

export type ResolveProjectInput = SentryClientOptions & {
	orgSlug: string
	projectSlug?: string
	projectId?: string | number
}

export type ListProjectsInput = SentryClientOptions & {
	orgSlug: string
}

export type ListOrganizationsInput = SentryClientOptions

export type IssueInput = SentryClientOptions & {
	issueId: string | number
}

export type IssueEventsInput = IssueInput & {
	limit?: number
	cursor?: string
}

export type SummarizeIssueEventOptions = {
	maxBreadcrumbs?: number
	maxFramesPerException?: number
}

export type SentryExceptionSummary = {
	type?: string
	value?: string
	module?: string
	mechanism?: unknown
	frameCount: number
	frames: Array<{
		function?: string
		module?: string
		filename?: string
		absPath?: string
		lineNo?: number
		colNo?: number
		inApp?: boolean
		contextLine?: string
	}>
}

export type SentryBreadcrumbSummary = {
	timestamp?: string
	type?: string
	category?: string
	level?: string
	message?: string
	data?: unknown
}

export type SentryEventSummary = {
	id?: string
	eventId?: string
	title?: string
	message?: string
	culprit?: string
	platform?: string
	projectId?: string
	groupId?: string
	release?: string
	environment?: string
	timestamp?: string
	exceptionChain: SentryExceptionSummary[]
	tags: Record<string, unknown>
	breadcrumbs: SentryBreadcrumbSummary[]
	contexts: JsonRecord
	contextKeys: string[]
	user?: unknown
	request?: unknown
}

export type SentryPaginationLink = {
	cursor?: string
	hasResults: boolean
	url?: string
}

export type SentryPage<T> = {
	items: T
	next?: SentryPaginationLink
	previous?: SentryPaginationLink
}

export type IssueWithLatestSummary = {
	issue: SentryIssue
	latestEventSummary: SentryEventSummary | null
	latestEventError?: {
		name?: string
		message: string
		status?: number
	}
}

export type IssueTriageInput = IssueInput & {
	recentEventLimit?: number
	options?: SummarizeIssueEventOptions
}

export type IssueTriage = {
	issue: {
		id: string
		shortId?: string
		title?: string
		status?: string
		level?: string
		permalink?: string
		firstSeen?: string
		lastSeen?: string
		count?: string | number
		userCount?: string | number
		project?: unknown
		assignedTo?: unknown
	}
	latestEventSummary: SentryEventSummary | null
	recentEventSummaries: SentryEventSummary[]
	signals: {
		exceptionTypes: string[]
		likelyCulprit?: string
		topInAppFrames: SentryExceptionSummary['frames']
		tagKeys: string[]
		contextKeys: string[]
		recentBreadcrumbs: SentryBreadcrumbSummary[]
	}
}

export type SentryRequestInput = SentryClientOptions & {
	path: string
	query?: Record<string, string | number | boolean | null | undefined | Array<string | number | boolean | null | undefined>>
	init?: RequestInit
	/** Mutating methods default to dry-run. Pass `false` only after confirmation. */
	dryRun?: boolean
}

export type SentryDryRunResult = {
	dryRun: true
	wouldCall: {
		method: string
		host: string
		path: string
		query?: SentryRequestInput['query']
		body?: unknown
	}
}