import type { SessionWithLegacyEvents } from './authSession/authSession' import type { ACLContext, AccessMode, AccessSubject, Authorization, PatchPlan } from '@dokieli/web-access-control' import { LiveStore, NamedNode, Statement } from 'rdflib' import type { AccessControlSubject } from './acl/accessControlSubjects' import type { AccessRole, ContainerAccessScope, PublicAccessRole } from './acl/aclLogic' export type AppDetails = { noun: string appPathSegment: string } export type AuthenticationContext = { containers?: Array div?: HTMLElement dom?: HTMLDocument index?: { [key: string]: Array } instances?: Array me?: NamedNode | null noun?: string preferencesFile?: NamedNode preferencesFileError?: string publicProfile?: NamedNode statusArea?: HTMLElement } export interface AuthnLogic { authSession: SessionWithLegacyEvents //this needs to be deprecated in the future. Is only here to allow imports like panes.UI.authn.authSession prior to moving authn from ui to logic currentUser: () => NamedNode | null checkUser: (setUserCallback?: (me: NamedNode | null) => T) => Promise saveUser: (webId: NamedNode | string | null, context?: AuthenticationContext) => NamedNode | null /** * Releases what the implementation registered elsewhere (document and * session listeners). Optional so other implementations stay valid, but a * caller that replaces a logic instance should dispose the old one. */ dispose?: () => void } export interface SolidNamespace { [key: string]: (term: string) => NamedNode } export type TypeIndexScope = { label: string, index: NamedNode, agent: NamedNode } export type ScopedApp = { instance: NamedNode, type: NamedNode, scope: TypeIndexScope } export interface NewPaneOptions { me?: NamedNode; newInstance?: NamedNode; newBase: string; } export interface CreatedPaneOptions { newInstance: NamedNode; } export interface ChatLogic { setAcl: (chatContainer: NamedNode, me: NamedNode, invitee: NamedNode) => Promise, addToPrivateTypeIndex: (chatThing, me) => void | Promise, findChat: (invitee: NamedNode) => Promise, createChatThing: (chatContainer: NamedNode, me: NamedNode) => Promise, mintNew: (newPaneOptions: NewPaneOptions) => Promise, getChat: (invitee: NamedNode, boolean) => Promise, sendInvite: (invitee: NamedNode, chatThing: NamedNode) => void } export interface Chat { me: NamedNode, chatContainer: NamedNode, exists: boolean } export interface ProfileLogic { silencedLoadPreferences: (user: NamedNode) => Promise, loadPreferences: (user: NamedNode) => Promise, loadProfile: (user: NamedNode) => Promise, loadMe: () => Promise, getPodRoot: (user: NamedNode) => NamedNode, getMainInbox: (user: NamedNode) => Promise, findStorage: (me: NamedNode) => Node | null } export interface AclLogic { findAclDocUrl: (url: NamedNode) => Promise, findEffectiveAcl: (resourceURL: string | NamedNode) => Promise, findAccessGrants: (resourceURL: string | NamedNode) => Promise, classifyContainerScope: (context: ACLContext) => ContainerAccessScope, isProtectedResource: (resourceURL: string | NamedNode) => boolean, classifyAccessControlSubject: (principle: string) => Promise, roleFromModes: (modes: Iterable) => AccessRole, modesFromRole: (role: AccessRole) => AccessMode[], publicRoleFromModes: (modes: Iterable) => PublicAccessRole, modesFromPublicRole: (role: PublicAccessRole) => AccessMode[], planGrant: (resourceURL: string | NamedNode, subject: AccessSubject, modes: AccessMode[]) => Promise, planGrantContainer: (containerURL: string | NamedNode, subject: AccessSubject, modes: AccessMode[]) => Promise, planGrantContainerAndContents: (containerURL: string | NamedNode, subject: AccessSubject, modes: AccessMode[]) => Promise, planGrantContainerContents: (containerURL: string | NamedNode, subject: AccessSubject, modes: AccessMode[]) => Promise, planRevokeContainerContents: (containerURL: string | NamedNode, subject: AccessSubject) => Promise, planRevoke: (resourceURL: string | NamedNode, subject: AccessSubject) => Promise, planPublicRead: (resourceURL: string | NamedNode, enabled: boolean) => Promise, resetToDefault: (resourceURL: string | NamedNode) => Promise, applyPlan: (plan: PatchPlan) => Promise, setACLUserPublic: (docURI: string, me: NamedNode, options: { defaultForNew?: boolean, public?: [] } ) => Promise, genACLText: (docURI: string, me: NamedNode, aclURI: string, options: { defaultForNew?: boolean, public?: [] } ) => string | undefined Authenticated: AccessSubject Public: AccessSubject PUBLIC_ACCESS_ROLES: readonly PublicAccessRole[] } export type { ACLContext, AccessMode, AccessSubject, Authorization, PatchPlan } export interface InboxLogic { createInboxFor: (peerWebId: string, nick: string) => Promise, getNewMessages: (user?: NamedNode) => Promise, markAsRead: (url: string, date: Date) => void } export type ResourceDeleteOptions = { deleteTypeIndexes?: boolean, user?: NamedNode | null } export type ResourceAccess = { canEdit: boolean canManageAccess: boolean isPublic: boolean /** False when the server did not provide WAC-Allow metadata. */ isPublicKnown?: boolean } export type ResourceAccessWithDelete = ResourceAccess & { canDelete: boolean } export type ResourceMetadata = { contentType: string | undefined access: ResourceAccess aclUri: string | undefined eTag: string | undefined modified: string | undefined } export type ResourceMetadataWithDelete = ResourceMetadata & { access: ResourceAccessWithDelete } export class ResourceUploadError extends Error { constructor( message: string, public readonly destinationUri?: string, public readonly status?: number ) { super(message) this.name = 'ResourceUploadError' } } export type ResourceUploadResult = | { success: true, file: File, uploadedUri: string } | { success: false, file: File, error: ResourceUploadError } export type ResourceContent = { content: string metadata: ResourceMetadata } export interface ResourceLogic { uploadFiles: ( files: File[], destination: string ) => Promise, recursiveDelete: (resource: NamedNode, options?: ResourceDeleteOptions) => Promise, deleteResourceAndTypeIndexIfExists: (resource: NamedNode, user?: NamedNode | null) => Promise, fetchMetadata: (subject: NamedNode) => Promise, fetchMetadataWithDelete: (subject: NamedNode) => Promise, fetchContentAndMetadata: (subject: NamedNode) => Promise, createContainer: (url: string) => Promise, isContainer: (resource: NamedNode) => boolean, getContainerMembers: (resource: NamedNode) => NamedNode[], getContainerMemberCount: (resource: NamedNode) => number, getContainerIndexThing: (container: NamedNode) => NamedNode, containerHasIndexDocument: (container: NamedNode) => boolean, isStorageRoot: (resource: NamedNode) => boolean, isHiddenFile: (resource: NamedNode) => boolean, isMediaType: (resource: NamedNode, mediaType: string) => boolean, isImage: (resource: NamedNode) => boolean, isAudio: (resource: NamedNode) => boolean, isVideo: (resource: NamedNode) => boolean, isWebId: (resource: string | NamedNode) => boolean } export interface TypeIndexLogic { getRegistrations: (instance, theClass) => Node[], loadTypeIndexesFor: (user: NamedNode) => Promise>, loadCommunityTypeIndexes: (user: NamedNode) => Promise>, loadAllTypeIndexes: (user: NamedNode) => Promise>, getScopedAppInstances: (klass: NamedNode, user: NamedNode) => Promise, getAppInstances: (klass: NamedNode) => Promise, suggestPublicTypeIndex: (me: NamedNode) => NamedNode, suggestPrivateTypeIndex: (preferencesFile: NamedNode) => NamedNode, registerInTypeIndex: (instance: NamedNode, index: NamedNode, theClass: NamedNode) => Promise, deleteTypeIndexRegistration: (item: any) => Promise, deleteTypeIndexRegistrationForResource: (resource: NamedNode, user: NamedNode) => Promise, getScopedAppsFromIndex: (scope: TypeIndexScope, theClass: NamedNode | null) => Promise, } export type DirectorySource = 'contacts' | 'friends' | 'catalog' | 'groups' export type DirectoryRelationshipLabel = 'Friend' | 'People' | 'Contact' | 'Group' export type DirectoryEntry = { kind: 'person' | 'group' uri: string label: string searchableLabels?: string[] subjectType: 'agent' | 'agentGroup' relationshipLabel: DirectoryRelationshipLabel sources: DirectorySource[] } export type DirectorySearchOptions = { query?: string sources?: DirectorySource[] catalogUrl?: string user?: NamedNode | null maxFoafDistance?: number } export interface DirectoryLogic { search: (options?: DirectorySearchOptions) => Promise } export interface SolidLogic { store: LiveStore, authn: AuthnLogic, acl: AclLogic, resource: ResourceLogic, profile: ProfileLogic, inbox: InboxLogic, typeIndex: TypeIndexLogic, chat: ChatLogic, directory: DirectoryLogic, load: (doc: NamedNode | NamedNode[] | string) => void, updatePromise: (del: Array, ins: Array) => Promise, clearStore: () => void }