import { ClerkEmailTemplateClaim, JWKPublic } from "@fireproof/core-types-base"; import { FPCloudClaim, ReadWrite, Role, TenantLedger } from "@fireproof/core-types-protocols-cloud"; export type AuthProvider = "github" | "google" | "fp" | "invite-per-email" | "device-id"; export interface Queryable { readonly userId?: string; readonly queryProvider?: AuthProvider; readonly queryEmail?: string; readonly queryNick?: string; } export interface QueryUser { readonly byString?: string; readonly existingUserId?: string; readonly byEmail?: string; readonly byNick?: string; readonly andProvider?: AuthProvider; } export interface Tenant { readonly tenantId: string; readonly name: string; readonly ownerUserId: string; readonly adminUserIds: string[]; readonly memberUserIds: string[]; readonly maxAdminUsers: number; readonly maxMemberUsers: number; readonly maxLedgers: number; readonly createdAt: Date; readonly updatedAt: Date; } export type InviteTicketStatus = "pending" | "accepted" | "rejected" | "expired"; export interface SqlInvitedParams { readonly tenant?: { readonly role: "admin" | "member"; }; readonly ledger?: { readonly role: "admin" | "member"; readonly right: "read" | "write"; }; } export interface InvitedParams { readonly tenant?: SqlInvitedParams["tenant"] & { readonly id: string; }; readonly ledger?: SqlInvitedParams["ledger"] & { readonly id: string; }; } export interface InviteTicket { readonly inviteId: string; readonly sendEmailCount: number; readonly inviterUserId: string; readonly query: QueryUser; readonly status: InviteTicketStatus; readonly statusReason: string; readonly invitedUserId?: string; readonly invitedParams: InvitedParams; readonly expiresAfter: Date; readonly createdAt: Date; readonly updatedAt: Date; } export type UserStatus = "active" | "inactive" | "banned" | "invited"; export interface DashAuthType { readonly type: "ucan" | "clerk" | "device-id"; readonly token: string; } export interface User { readonly userId: string; readonly maxTenants: number; readonly status: UserStatus; readonly statusReason?: string; readonly createdAt: Date; readonly updatedAt: Date; readonly byProviders: UserByProvider[]; } export interface UserByProvider extends Queryable { readonly providerUserId: string; readonly cleanEmail?: string; readonly cleanNick?: string; readonly queryProvider: AuthProvider; readonly queryEmail?: string; readonly queryNick?: string; readonly params: ClerkEmailTemplateClaim; readonly used: Date; readonly createdAt: Date; readonly updatedAt: Date; } export interface ResCreateTenant { readonly type: "resCreateTenant"; readonly tenant: OutTenantParams; } export interface FPApiParameters { cloudPublicKeys: JWKPublic[]; clerkPublishableKey: string; maxTenants: number; maxAdminUsers: number; maxMemberUsers: number; maxInvites: number; maxLedgers: number; maxAppIdBindings: number; } export interface InCreateTenantParams { readonly name?: string; readonly ownerUserId: string; readonly defaultTenant?: boolean; } export interface ReqCreateTenant { readonly type: "reqCreateTenant"; readonly auth: DashAuthType; readonly tenant: Omit; } export interface InUpdateTenantParams { readonly tenantId: string; readonly name?: string; readonly maxAdminUsers?: number; readonly maxMemberUsers?: number; readonly maxInvites?: number; } export interface ResUpdateTenant { readonly type: "resUpdateTenant"; readonly tenant: OutTenantParams; } export interface ReqUpdateTenant { readonly type: "reqUpdateTenant"; readonly auth: DashAuthType; readonly tenant: InUpdateTenantParams; } export interface ResEnsureTenant { readonly type: "resEnsureTenant"; readonly tenant: Tenant; } export interface ReqRedeemInvite { readonly type: "reqRedeemInvite"; readonly auth: DashAuthType; } export interface ResRedeemInvite { readonly type: "resRedeemInvite"; readonly invites?: InviteTicket[]; } export interface ReqListLedgersByUser { readonly type: "reqListLedgersByUser"; readonly auth: DashAuthType; readonly tenantIds?: string[]; } interface LedgerUserRight { readonly userId: string; readonly role: Role; readonly right: ReadWrite; readonly name?: string; readonly default: boolean; readonly createdAt: Date; readonly updatedAt: Date; } export interface LedgerUser { readonly ledgerId: string; readonly tenantId: string; readonly name: string; readonly ownerId: string; readonly maxShares: number; readonly users: LedgerUserRight[]; readonly createdAt: Date; readonly updatedAt: Date; } export interface ResListLedgersByUser { readonly type: "resListLedgersByUser"; readonly userId: string; readonly ledgers: LedgerUser[]; } export interface ReqListTenantsByUser { readonly type: "reqListTenantsByUser"; readonly auth: DashAuthType; } export interface UserTenantCommon { readonly name?: string; readonly status: UserStatus; readonly statusReason: string; readonly createdAt: Date; readonly updatedAt: Date; } export interface TenantLimits { readonly maxAdminUsers: number; readonly maxMemberUsers: number; readonly maxInvites: number; readonly maxLedgers: number; } export interface UserTenant { readonly tenantId: string; readonly role: Role; readonly default: boolean; readonly user: UserTenantCommon & { readonly limits: { readonly maxTenants: number; }; }; readonly tenant: UserTenantCommon & { readonly limits: TenantLimits; }; } export declare function isAdmin(ut: UserTenant): boolean; export interface AdminTenant extends UserTenant { readonly role: "admin"; readonly adminUserIds: string[]; readonly memberUserIds: string[]; readonly maxAdminUsers: number; readonly maxMemberUsers: number; } export interface ResListTenantsByUser { readonly type: "resListTenantsByUser"; readonly userId: string; readonly authUserId: string; readonly tenants: (AdminTenant | UserTenant)[]; } export interface ReqFindUser { readonly type: "reqFindUser"; readonly auth: DashAuthType; readonly query: QueryUser; } export interface ResFindUser { readonly type: "resFindUser"; readonly query: QueryUser; readonly results: User[]; } export interface QueryInviteTicket { readonly incSendEmailCount?: boolean; readonly inviteId?: string; readonly query: QueryUser; readonly invitedParams: InvitedParams; } export interface ReqInviteUser { readonly type: "reqInviteUser"; readonly auth: DashAuthType; readonly ticket: QueryInviteTicket; } export interface ResInviteUser { readonly type: "resInviteUser"; readonly invite: InviteTicket; } export interface ReqDeleteInvite { readonly type: "reqDeleteInvite"; readonly auth: DashAuthType; readonly inviteId: string; } export interface ResDeleteInvite { readonly type: "resDeleteInvite"; readonly inviteId: string; } export interface ReqListInvites { readonly type: "reqListInvites"; readonly auth: DashAuthType; readonly tenantIds?: string[]; readonly ledgerIds?: string[]; } export interface ResListInvites { readonly type: "resListInvites"; readonly tickets: InviteTicket[]; } export interface ReqUpdateUserTenant { readonly type: "reqUpdateUserTenant"; readonly auth: DashAuthType; readonly tenantId: string; readonly userId?: string; readonly role: Role; readonly default?: boolean; readonly name?: string; } export interface ResUpdateUserTenant { readonly type: "resUpdateUserTenant"; readonly tenantId: string; readonly userId: string; readonly role: Role; readonly default: boolean; readonly name?: string; } export interface CreateLedger { readonly tenantId: string; readonly name: string; } export interface ReqCreateLedger { readonly type: "reqCreateLedger"; readonly auth: DashAuthType; readonly ledger: CreateLedger; } export interface ResCreateLedger { readonly type: "resCreateLedger"; readonly ledger: LedgerUser; } export interface UpdateLedger { readonly ledgerId: string; readonly tenantId: string; readonly right?: ReadWrite; readonly role?: Role; readonly name?: string; readonly default?: boolean; } export interface ReqUpdateLedger { readonly type: "reqUpdateLedger"; readonly auth: DashAuthType; readonly ledger: UpdateLedger; } export interface ResUpdateLedger { readonly type: "resUpdateLedger"; readonly ledger: LedgerUser; } export interface DeleteLedger { readonly ledgerId: string; readonly tenantId: string; } export interface ReqDeleteLedger { readonly type: "reqDeleteLedger"; readonly auth: DashAuthType; readonly ledger: DeleteLedger; } export interface ResDeleteLedger { readonly type: "resDeleteLedger"; } export interface ReqCloudSessionToken { readonly type: "reqCloudSessionToken"; readonly auth: DashAuthType; readonly selected?: Partial; readonly resultId?: string; } export interface ResCloudSessionToken { readonly type: "resCloudSessionToken"; readonly token: string; } export interface ReqTokenByResultId { readonly type: "reqTokenByResultId"; readonly resultId: string; } export interface ResTokenByResultId { readonly type: "resTokenByResultId"; readonly status: "found" | "not-found"; readonly resultId: string; readonly token?: string; } export interface ResDeleteTenant { readonly type: "resDeleteTenant"; readonly tenantId: string; } export interface ReqDeleteTenant { readonly type: "reqDeleteTenant"; readonly auth: DashAuthType; readonly tenantId: string; } export interface OutTenantParams { readonly tenantId: string; readonly name: string; readonly ownerUserId: string; readonly maxAdminUsers: number; readonly maxMemberUsers: number; readonly maxInvites: number; readonly maxLedgers: number; readonly status: UserStatus; readonly statusReason: string; readonly createdAt: Date; readonly updatedAt: Date; } export interface ResEnsureUser { readonly type: "resEnsureUser"; readonly user: User; readonly tenants: UserTenant[]; } export interface ReqEnsureUser { readonly type: "reqEnsureUser"; readonly auth: DashAuthType; } interface RoleBase { readonly tenantId?: string; readonly ledgerId?: string; readonly userId: string; readonly role: Role; readonly adminUserIds: string[]; readonly memberUserIds: string[]; } interface TenantRole extends RoleBase { readonly tenantId: string; } interface LedgerRole extends RoleBase { readonly ledgerId: string; readonly right: ReadWrite; } export type RoleType = TenantRole | LedgerRole; export interface ReqInsertTenant { readonly tenantId: string; readonly name?: string; readonly ownerUserId: string; readonly adminUserIds?: string[]; readonly memberUserIds?: string[]; readonly maxAdminUsers?: number; readonly maxMemberUsers?: number; readonly createdAt?: Date; readonly updatedAt?: Date; } export interface ReqExtendToken { readonly type: "reqExtendToken"; readonly token: string; } export interface ResExtendToken { readonly type: "resExtendToken"; readonly token: string; } export interface ReqCertFromCsr { readonly type: "reqCertFromCsr"; readonly auth: DashAuthType; readonly csr: string; } export interface ResCertFromCsr { readonly type: "resCertFromCsr"; readonly certificate: string; } export interface ReqEnsureCloudToken { readonly type: "reqEnsureCloudToken"; readonly auth: DashAuthType; readonly appId: string; readonly env?: string; readonly tenant?: string; readonly ledger?: string; readonly prevCloudToken?: string; } export interface ResEnsureCloudToken { readonly type: "resEnsureCloudToken"; readonly cloudToken: string; readonly appId: string; readonly tenant: string; readonly ledger: string; readonly expiresInSec: number; readonly expiresDate: string; readonly claims: FPCloudClaim; } export {};