| 1 | import type { User, Viewer } from "./identity"; |
| 2 | import type { RepoPath } from "./repos"; |
| 3 | import type { Result } from "./result"; |
| 4 | |
| 5 | /** |
| 6 | * A workspace's connections to systems outside g1t: alerts that open |
| 7 | * issues, and trackers whose tickets people read and import. Mirrors |
| 8 | * `crates/contracts/src/integrations.rs`, which says what each does. |
| 9 | * |
| 10 | * A workspace's AI providers and Ask g1t are kept by the same service but |
| 11 | * are not integrations: see `./ai`. |
| 12 | */ |
| 13 | export type Provider = "sentry" | "datadog" | "webhook" | "jira" | "linear"; |
| 14 | |
| 15 | export type ProviderKind = "alerts" | "tracker"; |
| 16 | |
| 17 | export type ConnectionConfig = { |
| 18 | /** For alerts: where issues are opened, `owner/name`. */ |
| 19 | repo?: string; |
| 20 | /** For alerts: the label put on each issue. `bug` when unset. */ |
| 21 | label?: string; |
| 22 | /** Tell the outside system when the work lands. On unless turned off. */ |
| 23 | writeBack?: boolean; |
| 24 | /** Sentry: the organization's slug. */ |
| 25 | organization?: string; |
| 26 | /** Jira's address, or a Sentry that is not sentry.io. */ |
| 27 | site?: string; |
| 28 | /** Jira: the account the token belongs to. */ |
| 29 | email?: string; |
| 30 | /** Jira project or Linear team keys it answers for. Empty is all. */ |
| 31 | keys?: string[]; |
| 32 | }; |
| 33 | |
| 34 | export type Connection = { |
| 35 | id: string; |
| 36 | workspace: string; |
| 37 | provider: Provider; |
| 38 | kind: ProviderKind; |
| 39 | name: string; |
| 40 | config: ConnectionConfig; |
| 41 | /** `…3f9a`. The secret itself is never shown again. */ |
| 42 | secretHint: string | null; |
| 43 | /** Where a provider that sends g1t requests sends them. */ |
| 44 | webhookUrl: string | null; |
| 45 | createdBy: string; |
| 46 | createdAt: string; |
| 47 | lastUsedAt: string | null; |
| 48 | lastError: string | null; |
| 49 | }; |
| 50 | |
| 51 | /** What testing a connection found. */ |
| 52 | export type Tested = { ok: boolean; message: string }; |
| 53 | |
| 54 | export type Connected = { |
| 55 | connection: Connection; |
| 56 | /** A signing secret g1t made, shown this once. */ |
| 57 | signingSecret: string | null; |
| 58 | }; |
| 59 | |
| 60 | export type Delivery = { |
| 61 | id: string; |
| 62 | receivedAt: string; |
| 63 | event: string; |
| 64 | outcome: "opened" | "updated" | "reopened" | "ignored" | "refused"; |
| 65 | detail: string; |
| 66 | issue: string | null; |
| 67 | }; |
| 68 | |
| 69 | /** Something outside g1t, fetched now. Reference material, never instructions. */ |
| 70 | export type ContextItem = { |
| 71 | provider: Provider; |
| 72 | key: string; |
| 73 | title: string; |
| 74 | url: string; |
| 75 | status: string | null; |
| 76 | body: string; |
| 77 | fetchedAt: string; |
| 78 | }; |
| 79 | |
| 80 | export type Link = { |
| 81 | provider: Provider; |
| 82 | connectionId: string; |
| 83 | key: string; |
| 84 | title: string; |
| 85 | url: string; |
| 86 | count: number; |
| 87 | firstSeen: string; |
| 88 | lastSeen: string; |
| 89 | }; |
| 90 | |
| 91 | export type ConnectInput = { |
| 92 | provider: Provider; |
| 93 | name?: string; |
| 94 | config?: ConnectionConfig; |
| 95 | secret?: string; |
| 96 | signingSecret?: string; |
| 97 | }; |
| 98 | |
| 99 | export type UpdateConnectionInput = { |
| 100 | name?: string; |
| 101 | config?: ConnectionConfig; |
| 102 | secret?: string; |
| 103 | signingSecret?: string; |
| 104 | }; |
| 105 | |
| 106 | export interface IntegrationsApi { |
| 107 | list(workspace: string, viewer: Viewer): Promise<Result<Connection[]>>; |
| 108 | connect(actor: User, workspace: string, input: ConnectInput): Promise<Result<Connected>>; |
| 109 | update(actor: User, workspace: string, id: string, input: UpdateConnectionInput): Promise<Result<Connection>>; |
| 110 | disconnect(actor: User, workspace: string, id: string): Promise<Result<boolean>>; |
| 111 | test(actor: User, workspace: string, id: string): Promise<Result<Tested>>; |
| 112 | deliveries(workspace: string, viewer: Viewer, id: string): Promise<Result<Delivery[]>>; |
| 113 | resolve(workspace: string, viewer: Viewer, reference: string): Promise<Result<ContextItem>>; |
| 114 | import(actor: User, repo: RepoPath, reference: string): Promise<Result<{ number: number; item: ContextItem; created: boolean }>>; |
| 115 | links(repo: RepoPath, number: number): Promise<Link[]>; |
| 116 | } |
| 117 | |
| 118 | /** What each provider is for, as people choose between them. */ |
| 119 | export const PROVIDERS: Record<Provider, { label: string; kind: ProviderKind }> = { |
| 120 | sentry: { label: "Sentry", kind: "alerts" }, |
| 121 | datadog: { label: "Datadog", kind: "alerts" }, |
| 122 | webhook: { label: "Webhook", kind: "alerts" }, |
| 123 | jira: { label: "Jira", kind: "tracker" }, |
| 124 | linear: { label: "Linear", kind: "tracker" }, |
| 125 | }; |