217 lines · 7.5 KB
import { env } from "cloudflare:workers";
import { all, first, run } from "../db";
import { decryptSecret, encryptSecret, randomId } from "../crypto";
import { badRequest } from "../errors";
import { assertBelowCap } from "../limits";
import { DEFAULT_FILTERS } from "~/lib/integrations";
import type {
  GithubMirrorDirection,
  IntegrationFilters,
  IntegrationKind,
  LinearStateMapping,
  SlackChannelRoute,
} from "~/lib/integrations";
import type { RepoRow } from "~/lib/types";

export type IntegrationRow = {
  id: string;
  scope_type: "repo" | "org";
  scope_id: string;
  kind: IntegrationKind;
  name: string;
  config: string;
  events: string;
  delivery_mode: "instant" | "digest";
  digest_minutes: number;
  last_digest_at: number;
  credentials_ciphertext: string | null;
  credentials_iv: string | null;
  active: number;
  created_by: string | null;
  created_at: number;
  updated_at: number;
};

export type IntegrationConfig = {
  filters: IntegrationFilters;
  slackChannels?: SlackChannelRoute[];
  slackTeam?: string;
  linearMapping?: LinearStateMapping;
  linearTeamKeys?: string[];