Skip to content
Sarj Workspace Sync

org-sync/channel-service

@sarj-ai/workspace-sync/org-sync/channel-service ยท Source

import type { IdentityWriteBudget } from "../identity-provisioning/identity-budget-contracts.ts";
import { type ResourceLeaseRepository } from "../identity-sync/resource-lease.ts";
import type { ChannelMembershipProvenanceRepository, ChannelMembershipRemovalCandidate, ChannelMembershipRemovalPlan } from "./channel-membership-provenance.ts";
import { type AllTeamPolicy, type ChannelMembershipChange, type ChannelRenameChange, type ManagedTeamPolicy, type OrgChannelPlan, type SlackChannelIdentity, type SlackChannelSyncSnapshot, type SlackUserGroupReconciliation, type SlackUserGroupSnapshot } from "./channel-model.ts";
import type { IGoogleDirectoryClient } from "./google-directory-client.ts";
import type { IGoogleGroupsClient } from "./google-groups-client.ts";
import { type GoogleDirectoryUser } from "./model.ts";
import type { IOrgChannelSlackClient } from "./org-channel-slack-client.ts";
import { type ReviewedSlackLifecycleParentContext, type ReviewedSlackLifecycleRemoval } from "./reviewed-lifecycle-removal.ts";
declare const USER_GROUP_SELECTION_POLICY_VERSION = "risk_v12";
export interface OrgChannelSyncConfig {
allowedPublicChannelNames: string[];
allowedPublicChannelPrefixes: string[];
allTeam?: AllTeamPolicy;
assignmentGroupEmails: string[];
automaticMemberRemovalScope: {
readonly kind: "all_managed";
} | {
readonly kind: "immutable_ids";
readonly slackUserGroupIds: readonly string[];
} | {
readonly kind: "none";
};
contractorOnlyMemberRemovals?: boolean;
expectedSlackTeamId: string;
managedTeams: ManagedTeamPolicy[];
maxAutomaticAdditions: number;
maxAutomaticChannelInvites: number;
maxAutomaticChannelMembershipRemovals?: number;
maxAutomaticChannelRenames?: number;
maxAutomaticContractorRemovals?: number;
maxAutomaticGoogleGroupRemovals?: number;
maxAutomaticRemovals: number;
maxAutomaticUserGroupChanges?: number;
minimumActiveGoogleUsers: number;
protectedSlackUserIds?: readonly string[];
requiredPrivateChannelNames?: string[];
requireRemovalPlanHash?: boolean;
}
export interface OrgChannelSyncRunOptions {
allowRemovals: boolean;
expectedPlanHash?: string | undefined;
googleUsers?: readonly GoogleDirectoryUser[] | undefined;
identityBudget?: IdentityWriteBudget | undefined;
mode: "audit" | "live";
requireUnprivilegedIdentity?: boolean;
reviewedLifecycleParent?: ReviewedSlackLifecycleParentContext;
reviewedLifecycleRemoval?: ReviewedSlackLifecycleRemoval;
trigger: "cron" | "http";
}
export interface OrgChannelSyncRunReport {
additions: ChannelMembershipChange[];
channelRenames: ChannelRenameChange[];
durationMs: number;
errors: string[];
lifecycle: OrgChannelPlan["lifecycle"];
managerTargets: OrgChannelPlan["managerTargets"];
planHash: string;
provenanceChannelRemovalCandidates: ChannelMembershipRemovalCandidate[];
removals: ChannelMembershipChange[];
runId: string;
selectedChannelAdditions: ChannelMembershipChange[];
selectedChannelRename: ChannelRenameChange | null;
selectedProvenanceChannelRemovals: ChannelMembershipRemovalPlan[];
selectedUserGroupHandles: string[];
selectedUserGroups: SlackUserGroupReconciliation[];
selectionPolicyVersion: typeof USER_GROUP_SELECTION_POLICY_VERSION;
status: "audit" | "blocked" | "failed" | "success";
userGroups: OrgChannelPlan["userGroups"];
warnings: string[];
writes: number;
}
interface MembershipPlanReadInput {
allowRemovals: boolean;
googleUsers: readonly GoogleDirectoryUser[];
reviewedLifecycleReadback?: ReviewedSlackLifecycleRemoval;
reviewedLifecycleRemoval?: ReviewedSlackLifecycleRemoval;
slackUserId: string;
}
export interface IOrgChannelSyncService {
readChannelIdentity(channelId: string): Promise<SlackChannelIdentity>;
readChannelMemberIds(channelId: string): Promise<readonly string[]>;
readMembershipIdentities(slackUserIds: readonly string[], googleUsers: readonly GoogleDirectoryUser[]): Promise<Map<string, string>>;
readMembershipPlan(input: MembershipPlanReadInput): Promise<{
googleUserId: string;
report: OrgChannelSyncRunReport;
}>;
run(options: OrgChannelSyncRunOptions): Promise<OrgChannelSyncRunReport>;
}
export type OriginalSlackMembershipObservation = Pick<SlackChannelSyncSnapshot, "channels" | "inventory" | "userGroups"> & {
googleUserId: string;
slackUserId: string;
plan: OrgChannelPlan;
};
export interface IOrgChannelMembershipObservationReader {
readOriginalMembershipObservation(input: {
googleUsers: readonly GoogleDirectoryUser[];
googleUserId: string;
slackUserId: string;
}): Promise<OriginalSlackMembershipObservation>;
}
export declare class OrgChannelSyncService implements IOrgChannelSyncService, IOrgChannelMembershipObservationReader {
#private;
constructor(config: OrgChannelSyncConfig, googleDirectory: IGoogleDirectoryClient, googleGroups: IGoogleGroupsClient, slack: IOrgChannelSlackClient, leaseRepository: ResourceLeaseRepository, provenanceRepository?: ChannelMembershipProvenanceRepository);
run(options: OrgChannelSyncRunOptions): Promise<OrgChannelSyncRunReport>;
readChannelIdentity(channelId: string): Promise<SlackChannelIdentity>;
readMembershipIdentities(slackUserIds: readonly string[], googleUsers: readonly GoogleDirectoryUser[]): Promise<Map<string, string>>;
readMembershipPlan(input: MembershipPlanReadInput): Promise<{
googleUserId: string;
report: OrgChannelSyncRunReport;
}>;
readOriginalMembershipObservation(input: {
googleUsers: readonly GoogleDirectoryUser[];
googleUserId: string;
slackUserId: string;
}): Promise<{
googleUserId: string;
slackUserId: string;
userGroups: SlackUserGroupSnapshot[];
channels: import("./channel-model.ts").SlackChannelSnapshot[];
inventory: SlackChannelIdentity[];
plan: OrgChannelPlan;
}>;
readChannelMemberIds(channelId: string): Promise<readonly string[]>;
}
export declare function channelRenameSelectionAllowed(selectedUserGroupHandles: readonly string[], selectedProvenanceChannelRemovals: readonly ChannelMembershipRemovalPlan[]): boolean;
export {};