import type { Base58, Graph, Hash, KeyMetadata, Keyring, Keyset, KeysetWithSecrets, Link, LinkBody, Payload, ROOT, Sequence } from '@localfirst/crdx'; import type { Client, LocalContext } from 'team/context.js'; import type { Device } from 'device/index.js'; import type { Invitation, InvitationState } from 'invitation/types.js'; import type { Lockbox } from 'lockbox/index.js'; import type { PermissionsMap, Role } from 'role/index.js'; import type { Host, Server } from 'server/index.js'; import type { ValidationResult } from 'util/index.js'; /** A member is a user that belongs to a team. */ export type Member = { /** Unique ID populated on creation. */ userId: string; /** Username (or email). Must be unique but is not used for lookups. Only provided to connect * human identities with other systems. */ userName: string; /** The member's public keys */ keys: Keyset; /** Array of role names that the member belongs to */ roles: string[]; /** Devices that the member has added, along with their public */ devices?: Device[]; }; /** Properties required when creating a new team */ export type NewTeamOptions = { /** The team's human-facing name */ teamName: string; /** The team keys need to be provided for encryption and decryption. It's up to the application to persist these somewhere. */ teamKeys: KeysetWithSecrets; }; /** Properties required when rehydrating from an existing graph */ export type ExistingTeamOptions = { /** The `TeamGraph` representing the team's state, to be rehydrated. * Can be serialized or not. */ source: Uint8Array | TeamGraph; /** The team keys need to be provided for encryption and decryption. It's up to the application to persist these somewhere. */ teamKeyring: Keyring; }; type NewOrExisting = NewTeamOptions | ExistingTeamOptions; /** Options passed to the `Team` constructor */ export type TeamOptions = NewOrExisting & { /** A seed for generating keys. This is typically only used for testing, to ensure predictable data. */ seed?: string; /** Object containing the current user and device (and optionally information about the client & version). */ context: LocalContext; }; /** Type guard for NewTeamOptions vs ExistingTeamOptions */ export declare const isNewTeam: (options: NewOrExisting) => options is NewTeamOptions; type BasePayload = { lockboxes?: Lockbox[]; }; export type RootAction = { type: typeof ROOT; payload: BasePayload & { name: string; rootMember: Member; rootDevice: Device; }; }; export type AddMemberAction = { type: 'ADD_MEMBER'; payload: BasePayload & { member: Member; roles?: string[]; }; }; export type RemoveMemberAction = { type: 'REMOVE_MEMBER'; payload: BasePayload & { userId: string; }; }; export type AddRoleAction = { type: 'ADD_ROLE'; payload: BasePayload & Role; }; export type RemoveRoleAction = { type: 'REMOVE_ROLE'; payload: BasePayload & { roleName: string; }; }; export type AddMemberRoleAction = { type: 'ADD_MEMBER_ROLE'; payload: BasePayload & { userId: string; roleName: string; permissions?: PermissionsMap; }; }; export type RemoveMemberRoleAction = { type: 'REMOVE_MEMBER_ROLE'; payload: BasePayload & { userId: string; roleName: string; }; }; export type AddDeviceAction = { type: 'ADD_DEVICE'; payload: BasePayload & { device: Device; }; }; export type RemoveDeviceAction = { type: 'REMOVE_DEVICE'; payload: BasePayload & { deviceId: string; }; }; export type InviteMemberAction = { type: 'INVITE_MEMBER'; payload: BasePayload & { invitation: Invitation; }; }; export type InviteDeviceAction = { type: 'INVITE_DEVICE'; payload: BasePayload & { invitation: Invitation; }; }; export type RevokeInvitationAction = { type: 'REVOKE_INVITATION'; payload: BasePayload & { id: string; }; }; export type AdmitMemberAction = { type: 'ADMIT_MEMBER'; payload: BasePayload & { id: Base58; userName: string; memberKeys: Keyset; }; }; export type AdmitDeviceAction = { type: 'ADMIT_DEVICE'; payload: BasePayload & { id: Base58; device: Device; }; }; export type ChangeMemberKeysAction = { type: 'CHANGE_MEMBER_KEYS'; payload: BasePayload & { keys: Keyset; }; }; export type RotateKeysAction = { type: 'ROTATE_KEYS'; payload: BasePayload & { userId: string; }; }; export type AddServerAction = { type: 'ADD_SERVER'; payload: BasePayload & { server: Server; }; }; export type RemoveServerAction = { type: 'REMOVE_SERVER'; payload: BasePayload & { host: Host; }; }; export type ChangeServerKeysAction = { type: 'CHANGE_SERVER_KEYS'; payload: BasePayload & { keys: Keyset; }; }; export type MessageAction = { type: 'MESSAGE'; payload: BasePayload & { message: unknown; }; }; export type SetTeamNameAction = { type: 'SET_TEAM_NAME'; payload: BasePayload & { teamName: string; }; }; export type TeamAction = RootAction | AddMemberAction | AddDeviceAction | AddRoleAction | AddMemberRoleAction | RemoveMemberAction | RemoveDeviceAction | RemoveRoleAction | RemoveMemberRoleAction | InviteMemberAction | InviteDeviceAction | RevokeInvitationAction | AdmitMemberAction | AdmitDeviceAction | ChangeMemberKeysAction | RotateKeysAction | AddServerAction | RemoveServerAction | ChangeServerKeysAction | MessageAction | SetTeamNameAction; export type TeamContext = { deviceId: string; client?: Client; }; export type TeamLinkBody = LinkBody; export type TeamLink = Link & { isInvalid?: boolean; }; export type TeamLinkMap = Record; export type TeamGraph = Graph; export type Branch = Sequence; export type TwoBranches = [Branch, Branch]; export type MembershipRuleEnforcer = (links: TeamLink[], graph: TeamGraph) => TeamLink[]; export type TeamState = { head: Hash[]; teamName: string; rootContext?: TeamContext; members: Member[]; roles: Role[]; servers: Server[]; lockboxes: Lockbox[]; invitations: InvitationMap; messages: unknown[]; removedMembers: Member[]; removedDevices: Device[]; removedServers: Server[]; pendingKeyRotations: string[]; }; export type InvitationMap = Record; export type TeamStateValidator = (previousState: TeamState, link: TeamLink) => ValidationResult; export type TeamStateValidatorSet = Record; export type ValidationArgs = [TeamState, TeamLink]; export type EncryptedEnvelope = { contents: Uint8Array; recipient: KeyMetadata; }; export type SignedEnvelope = { contents: Payload; signature: Base58; author: KeyMetadata; }; export type Transform = (state: TeamState) => TeamState; export type InviteResult = { /** The unique identifier for this invitation. */ id: Base58; /** The secret invitation key. (Returned in case it was generated randomly.) */ seed: string; }; export type LookupIdentityResult = 'VALID_DEVICE' | 'MEMBER_REMOVED' | 'DEVICE_UNKNOWN' | 'DEVICE_REMOVED'; export {}; //# sourceMappingURL=types.d.ts.map