// SPDX-License-Identifier: AGPL-3.0-or-later // Code generated by tool/generate_api.dart from api/openapi.yaml. DO NOT EDIT. // ignore_for_file: constant_identifier_names class ApiError { const ApiError({ required this.error, this.message, this.fields, this.mfaId, this.challenge, }); factory ApiError.fromJson(Map json) => ApiError( error: json['error'] as String, message: json['message'] == null ? null : json['message'] as String, fields: json['fields'] == null ? null : (json['fields'] as Map).map( (k, e) => MapEntry(k, e as String), ), mfaId: json['mfaId'] == null ? null : json['mfaId'] as String, challenge: json['challenge'] == null ? null : json['challenge'] as String, ); /// invalid_json, validation, invalid_credentials, mfa_required, totp_required (with challenge), invalid_code, unauthorized, forbidden, account_disabled, signup_disabled, domain_not_allowed, invalid_token, invalid, not_found, conflict, internal final String error; /// Human-readable explanation final String? message; final Map? fields; final String? mfaId; /// With totp_required; send it to /api/v1/auth/totp/verify final String? challenge; Map toJson() => { 'error': error, 'message': ?message, 'fields': ?fields, 'mfaId': ?mfaId, 'challenge': ?challenge, }; } /// Instance role. admin manages their own organization; superadmin manages everything. enum Role { user('user'), admin('admin'), superadmin('superadmin'); const Role(this.value); final String value; static Role fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown Role', value), ); String toJson() => value; } enum WorkspaceRole { owner('owner'), admin('admin'), member('member'), guest('guest'); const WorkspaceRole(this.value); final String value; static WorkspaceRole fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown WorkspaceRole', value), ); String toJson() => value; } enum UserStatus { active('active'), invited('invited'), disabled('disabled'); const UserStatus(this.value); final String value; static UserStatus fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown UserStatus', value), ); String toJson() => value; } class User { const User({ required this.id, required this.email, required this.name, required this.avatar, required this.locale, required this.theme, required this.status, required this.verified, required this.created, required this.role, required this.organization, required this.organizationName, this.totp, }); factory User.fromJson(Map json) => User( id: json['id'] as String, email: json['email'] as String, name: json['name'] as String, avatar: json['avatar'] as String, locale: json['locale'] as String, theme: json['theme'] as String, status: UserStatus.fromJson(json['status'] as String), verified: json['verified'] as bool, created: json['created'] as String, role: Role.fromJson(json['role'] as String), organization: json['organization'] as String, organizationName: json['organizationName'] as String, totp: json['totp'] == null ? null : json['totp'] as bool, ); final String id; final String email; final String name; final String avatar; final String locale; final String theme; final UserStatus status; final bool verified; final String created; final Role role; /// Organization id final String organization; final String organizationName; /// Signs in with an authenticator app too final bool? totp; Map toJson() => { 'id': id, 'email': email, 'name': name, 'avatar': avatar, 'locale': locale, 'theme': theme, 'status': status.toJson(), 'verified': verified, 'created': created, 'role': role.toJson(), 'organization': organization, 'organizationName': organizationName, 'totp': ?totp, }; } class CreateUserRequest { const CreateUserRequest({ required this.email, required this.password, required this.name, this.role, this.organization, }); factory CreateUserRequest.fromJson(Map json) => CreateUserRequest( email: json['email'] as String, password: json['password'] as String, name: json['name'] as String, role: json['role'] == null ? null : Role.fromJson(json['role'] as String), organization: json['organization'] == null ? null : json['organization'] as String, ); final String email; final String password; final String name; final Role? role; /// Superadmins only; admins always create in their own final String? organization; Map toJson() => { 'email': email, 'password': password, 'name': name, 'role': ?role?.toJson(), 'organization': ?organization, }; } enum UpdateUserRequestStatus { active('active'), invited('invited'), disabled('disabled'); const UpdateUserRequestStatus(this.value); final String value; static UpdateUserRequestStatus fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown UpdateUserRequestStatus', value), ); String toJson() => value; } class UpdateUserRequest { const UpdateUserRequest({ this.email, this.name, this.role, this.password, this.status, this.verified, this.organization, }); factory UpdateUserRequest.fromJson(Map json) => UpdateUserRequest( email: json['email'] == null ? null : json['email'] as String, name: json['name'] == null ? null : json['name'] as String, role: json['role'] == null ? null : Role.fromJson(json['role'] as String), password: json['password'] == null ? null : json['password'] as String, status: json['status'] == null ? null : UpdateUserRequestStatus.fromJson(json['status'] as String), verified: json['verified'] == null ? null : json['verified'] as bool, organization: json['organization'] == null ? null : json['organization'] as String, ); final String? email; final String? name; final Role? role; final String? password; final UpdateUserRequestStatus? status; final bool? verified; /// Superadmins only; empty string detaches final String? organization; Map toJson() => { 'email': ?email, 'name': ?name, 'role': ?role?.toJson(), 'password': ?password, 'status': ?status?.toJson(), 'verified': ?verified, 'organization': ?organization, }; } class NameRequest { const NameRequest({required this.name}); factory NameRequest.fromJson(Map json) => NameRequest(name: json['name'] as String); final String name; Map toJson() => {'name': name}; } class Organization { const Organization({ required this.id, required this.name, required this.created, required this.members, required this.workspaces, }); factory Organization.fromJson(Map json) => Organization( id: json['id'] as String, name: json['name'] as String, created: json['created'] as String, members: (json['members'] as num).toInt(), workspaces: (json['workspaces'] as num).toInt(), ); final String id; final String name; final String created; final int members; final int workspaces; Map toJson() => { 'id': id, 'name': name, 'created': created, 'members': members, 'workspaces': workspaces, }; } class Workspace { const Workspace({ required this.id, required this.name, required this.slug, required this.organization, required this.organizationName, required this.role, required this.created, required this.defaultPageMode, required this.allowSharing, required this.urlPreview, }); factory Workspace.fromJson(Map json) => Workspace( id: json['id'] as String, name: json['name'] as String, slug: json['slug'] as String, organization: json['organization'] as String, organizationName: json['organizationName'] as String, role: WorkspaceRole.fromJson(json['role'] as String), created: json['created'] as String, defaultPageMode: PageMode.fromJson(json['defaultPageMode'] as String), allowSharing: json['allowSharing'] as bool, urlPreview: json['urlPreview'] as bool, ); final String id; final String name; final String slug; final String organization; final String organizationName; final WorkspaceRole role; final String created; /// The view new pages of the workspace open in final PageMode defaultPageMode; /// False when public share links are off for the whole workspace final bool allowSharing; /// Chat apps may show private pages' titles in link previews final bool urlPreview; Map toJson() => { 'id': id, 'name': name, 'slug': slug, 'organization': organization, 'organizationName': organizationName, 'role': role.toJson(), 'created': created, 'defaultPageMode': defaultPageMode.toJson(), 'allowSharing': allowSharing, 'urlPreview': urlPreview, }; } class WorkspaceMemberUser { const WorkspaceMemberUser({ required this.id, required this.email, required this.name, }); factory WorkspaceMemberUser.fromJson(Map json) => WorkspaceMemberUser( id: json['id'] as String, email: json['email'] as String, name: json['name'] as String, ); final String id; final String email; final String name; Map toJson() => {'id': id, 'email': email, 'name': name}; } class WorkspaceMember { const WorkspaceMember({required this.user, required this.role}); factory WorkspaceMember.fromJson(Map json) => WorkspaceMember( user: WorkspaceMemberUser.fromJson( json['user'] as Map, ), role: WorkspaceRole.fromJson(json['role'] as String), ); final WorkspaceMemberUser user; final WorkspaceRole role; Map toJson() => { 'user': user.toJson(), 'role': role.toJson(), }; } enum SpaceRole { admin('admin'), editor('editor'), commenter('commenter'), viewer('viewer'); const SpaceRole(this.value); final String value; static SpaceRole fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown SpaceRole', value), ); String toJson() => value; } /// Role that workspace members (not guests) get in an open space without an explicit role. enum SpaceDefaultRole { editor('editor'), commenter('commenter'), viewer('viewer'); const SpaceDefaultRole(this.value); final String value; static SpaceDefaultRole fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown SpaceDefaultRole', value), ); String toJson() => value; } /// open - every workspace member gets the default role; private - explicit members only. enum SpaceVisibility { open('open'), private('private'); const SpaceVisibility(this.value); final String value; static SpaceVisibility fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown SpaceVisibility', value), ); String toJson() => value; } class Space { const Space({ required this.id, required this.workspace, required this.name, required this.slug, required this.icon, required this.description, required this.visibility, required this.defaultRole, required this.role, required this.limited, required this.journal, required this.created, }); factory Space.fromJson(Map json) => Space( id: json['id'] as String, workspace: json['workspace'] as String, name: json['name'] as String, slug: json['slug'] as String, icon: json['icon'] as String, description: json['description'] as String, visibility: SpaceVisibility.fromJson(json['visibility'] as String), defaultRole: SpaceDefaultRole.fromJson(json['defaultRole'] as String), role: SpaceCallerRole.fromJson(json['role'] as String), limited: json['limited'] as bool, journal: json['journal'] as bool, created: json['created'] as String, ); final String id; final String workspace; final String name; final String slug; final String icon; final String description; final SpaceVisibility visibility; final SpaceDefaultRole defaultRole; final SpaceCallerRole role; /// The caller cannot open the space itself and sees only pages shared with them final bool limited; /// A journal space: one person's daily pages, private to them final bool journal; final String created; Map toJson() => { 'id': id, 'workspace': workspace, 'name': name, 'slug': slug, 'icon': icon, 'description': description, 'visibility': visibility.toJson(), 'defaultRole': defaultRole.toJson(), 'role': role.toJson(), 'limited': limited, 'journal': journal, 'created': created, }; } class SpaceMemberUser { const SpaceMemberUser({ required this.id, required this.email, required this.name, }); factory SpaceMemberUser.fromJson(Map json) => SpaceMemberUser( id: json['id'] as String, email: json['email'] as String, name: json['name'] as String, ); final String id; final String email; final String name; Map toJson() => {'id': id, 'email': email, 'name': name}; } class SpaceMember { const SpaceMember({required this.user, required this.role}); factory SpaceMember.fromJson(Map json) => SpaceMember( user: SpaceMemberUser.fromJson(json['user'] as Map), role: SpaceRole.fromJson(json['role'] as String), ); final SpaceMemberUser user; final SpaceRole role; Map toJson() => { 'user': user.toJson(), 'role': role.toJson(), }; } class PageNode { const PageNode({ required this.id, required this.parent, required this.title, required this.icon, required this.position, required this.restricted, required this.updated, }); factory PageNode.fromJson(Map json) => PageNode( id: json['id'] as String, parent: json['parent'] as String, title: json['title'] as String, icon: json['icon'] as String, position: json['position'] as String, restricted: json['restricted'] as bool, updated: json['updated'] as String, ); final String id; /// Parent page id; empty at the top level. In a page tree, a page whose parent the caller cannot open hangs from its nearest visible ancestor. final String parent; final String title; final String icon; /// Fractional sort key among siblings final String position; /// This page itself is restricted final bool restricted; final String updated; Map toJson() => { 'id': id, 'parent': parent, 'title': title, 'icon': icon, 'position': position, 'restricted': restricted, 'updated': updated, }; } class PageRef { const PageRef({required this.id, required this.title, required this.icon}); factory PageRef.fromJson(Map json) => PageRef( id: json['id'] as String, title: json['title'] as String, icon: json['icon'] as String, ); final String id; final String title; final String icon; Map toJson() => {'id': id, 'title': title, 'icon': icon}; } class Page { const Page({ required this.id, required this.workspace, required this.space, required this.parent, required this.title, required this.icon, required this.created, required this.updated, required this.deletedAt, required this.inTrash, required this.archivedAt, required this.archived, required this.ancestors, required this.role, required this.restricted, required this.isTemplate, required this.favorite, required this.pinnedAt, required this.fullWidth, required this.font, required this.defaultMode, required this.tags, required this.properties, required this.journalDate, required this.createdBy, required this.lastEditedBy, required this.verification, }); factory Page.fromJson(Map json) => Page( id: json['id'] as String, workspace: json['workspace'] as String, space: json['space'] as String, parent: json['parent'] as String, title: json['title'] as String, icon: json['icon'] as String, created: json['created'] as String, updated: json['updated'] as String, deletedAt: json['deletedAt'] as String, inTrash: json['inTrash'] as bool, archivedAt: json['archivedAt'] as String, archived: json['archived'] as bool, ancestors: (json['ancestors'] as List) .map((e) => PageRef.fromJson(e as Map)) .toList(), role: SpaceRole.fromJson(json['role'] as String), restricted: json['restricted'] as bool, isTemplate: json['isTemplate'] as bool, favorite: json['favorite'] as bool, pinnedAt: json['pinnedAt'] as String, fullWidth: json['fullWidth'] as bool, font: PageFont.fromJson(json['font'] as String), defaultMode: PageMode.fromJson(json['defaultMode'] as String), tags: (json['tags'] as List).map((e) => e as String).toList(), properties: json['properties'] as Map, journalDate: json['journalDate'] as String, createdBy: PageUser.fromJson(json['createdBy'] as Map), lastEditedBy: PageUser.fromJson( json['lastEditedBy'] as Map, ), verification: PageVerification.fromJson( json['verification'] as Map, ), ); final String id; final String workspace; final String space; final String parent; final String title; final String icon; final String created; final String updated; /// When the page itself was trashed; empty otherwise final String deletedAt; /// The page or one of its ancestors is in the trash final bool inTrash; /// When the page itself was archived; empty otherwise final String archivedAt; /// The page or one of its ancestors is archived (read-only) final bool archived; /// Root first; pages the caller cannot open are left out final List ancestors; /// The caller's role on this page final SpaceRole role; /// The page or one of its ancestors is restricted final bool restricted; /// Offered as a template for new pages final bool isTemplate; /// In the caller's favorites final bool favorite; /// When the page was pinned to its space's home; empty if not final String pinnedAt; /// Shown across the whole window instead of the reading column final bool fullWidth; final PageFont font; final PageMode defaultMode; /// Tag ids final List tags; /// Custom property values by property id (see Property for their shapes) final Map properties; /// The day (YYYY-MM-DD) of a journal page; empty otherwise final String journalDate; final PageUser createdBy; final PageUser lastEditedBy; final PageVerification verification; Map toJson() => { 'id': id, 'workspace': workspace, 'space': space, 'parent': parent, 'title': title, 'icon': icon, 'created': created, 'updated': updated, 'deletedAt': deletedAt, 'inTrash': inTrash, 'archivedAt': archivedAt, 'archived': archived, 'ancestors': ancestors.map((e) => e.toJson()).toList(), 'role': role.toJson(), 'restricted': restricted, 'isTemplate': isTemplate, 'favorite': favorite, 'pinnedAt': pinnedAt, 'fullWidth': fullWidth, 'font': font.toJson(), 'defaultMode': defaultMode.toJson(), 'tags': tags.map((e) => e).toList(), 'properties': properties, 'journalDate': journalDate, 'createdBy': createdBy.toJson(), 'lastEditedBy': lastEditedBy.toJson(), 'verification': verification.toJson(), }; } /// Whether someone vouched for the page; at is empty when nobody has class PageVerification { const PageVerification({ required this.by, required this.at, required this.until, required this.expired, }); factory PageVerification.fromJson(Map json) => PageVerification( by: PageUser.fromJson(json['by'] as Map), at: json['at'] as String, until: json['until'] as String, expired: json['expired'] as bool, ); final PageUser by; /// When the page was verified; empty if it is not final String at; /// When the verification runs out; empty when it does not final String until; /// The verification ran out (until has passed) final bool expired; Map toJson() => { 'by': by.toJson(), 'at': at, 'until': until, 'expired': expired, }; } class VerifyPage { const VerifyPage({required this.days}); factory VerifyPage.fromJson(Map json) => VerifyPage(days: (json['days'] as num).toInt()); /// How many days the verification lasts; 0 for one that does not run out final int days; Map toJson() => {'days': days}; } /// The view a page opens in for everyone, its text or the edgeless canvas; "?mode=" in an address overrides it enum PageMode { page('page'), edgeless('edgeless'); const PageMode(this.value); final String value; static PageMode fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown PageMode', value), ); String toJson() => value; } /// The body font for everyone reading the page; empty is the default sans enum PageFont { none(''), serif('serif'), mono('mono'); const PageFont(this.value); final String value; static PageFont fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown PageFont', value), ); String toJson() => value; } enum PageGrantRole { editor('editor'), commenter('commenter'), viewer('viewer'); const PageGrantRole(this.value); final String value; static PageGrantRole fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown PageGrantRole', value), ); String toJson() => value; } /// The caller's space role; empty when they see only pages shared with them enum SpaceCallerRole { admin('admin'), editor('editor'), commenter('commenter'), viewer('viewer'), none(''); const SpaceCallerRole(this.value); final String value; static SpaceCallerRole fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown SpaceCallerRole', value), ); String toJson() => value; } enum PageGrantType { user('user'), group('group'); const PageGrantType(this.value); final String value; static PageGrantType fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown PageGrantType', value), ); String toJson() => value; } class PageGrant { const PageGrant({ required this.type, required this.id, required this.name, required this.email, required this.role, required this.page, required this.inherited, }); factory PageGrant.fromJson(Map json) => PageGrant( type: PageGrantType.fromJson(json['type'] as String), id: json['id'] as String, name: json['name'] as String, email: json['email'] as String, role: PageGrantRole.fromJson(json['role'] as String), page: PageRef.fromJson(json['page'] as Map), inherited: json['inherited'] as bool, ); final PageGrantType type; final String id; final String name; /// Empty for groups final String email; final PageGrantRole role; /// Where the grant was made final PageRef page; /// Granted on an ancestor final bool inherited; Map toJson() => { 'type': type.toJson(), 'id': id, 'name': name, 'email': email, 'role': role.toJson(), 'page': page.toJson(), 'inherited': inherited, }; } class PageInvite { const PageInvite({ required this.id, required this.email, required this.role, required this.expires, }); factory PageInvite.fromJson(Map json) => PageInvite( id: json['id'] as String, email: json['email'] as String, role: PageGrantRole.fromJson(json['role'] as String), expires: json['expires'] as String, ); final String id; final String email; final PageGrantRole role; final String expires; Map toJson() => { 'id': id, 'email': email, 'role': role.toJson(), 'expires': expires, }; } class PageAccess { const PageAccess({ required this.restricted, required this.inheritedFrom, required this.grants, required this.invites, required this.role, required this.canManage, required this.canInvite, }); factory PageAccess.fromJson(Map json) => PageAccess( restricted: json['restricted'] as bool, inheritedFrom: json['inheritedFrom'] == null ? null : PageRef.fromJson(json['inheritedFrom'] as Map), grants: (json['grants'] as List) .map((e) => PageGrant.fromJson(e as Map)) .toList(), invites: (json['invites'] as List) .map((e) => PageInvite.fromJson(e as Map)) .toList(), role: SpaceRole.fromJson(json['role'] as String), canManage: json['canManage'] as bool, canInvite: json['canInvite'] as bool, ); /// The page or an ancestor is restricted; space members then see it only through grants final bool restricted; /// The restricted ancestor, when the restriction comes from one final PageRef? inheritedFrom; /// This page's grants first final List grants; /// Pending guest invites for this page (editors only) final List invites; /// The caller's role on this page final SpaceRole role; final bool canManage; /// May share with people outside the workspace final bool canInvite; Map toJson() => { 'restricted': restricted, 'inheritedFrom': inheritedFrom?.toJson(), 'grants': grants.map((e) => e.toJson()).toList(), 'invites': invites.map((e) => e.toJson()).toList(), 'role': role.toJson(), 'canManage': canManage, 'canInvite': canInvite, }; } class SharePageResult { const SharePageResult({required this.access, required this.invite}); factory SharePageResult.fromJson(Map json) => SharePageResult( access: PageAccess.fromJson(json['access'] as Map), invite: json['invite'] == null ? null : Invite.fromJson(json['invite'] as Map), ); final PageAccess access; /// Set when the person was invited as a guest; the grant is made when they accept final Invite? invite; Map toJson() => { 'access': access.toJson(), 'invite': invite?.toJson(), }; } class PageContent { const PageContent({required this.content, required this.updated}); factory PageContent.fromJson(Map json) => PageContent( content: json['content'] == null ? null : json['content'] as Map, updated: json['updated'] as String, ); /// Tiptap JSON with type "doc"; null for a page that was never edited final Map? content; final String updated; Map toJson() => {'content': content, 'updated': updated}; } class PageVersion { const PageVersion({ required this.id, required this.author, required this.label, required this.created, }); factory PageVersion.fromJson(Map json) => PageVersion( id: json['id'] as String, author: json['author'] as String, label: json['label'] as String, created: json['created'] as String, ); final String id; /// Name (or email) of the last person who edited before it was taken final String author; final String label; final String created; Map toJson() => { 'id': id, 'author': author, 'label': label, 'created': created, }; } class TrashedPage { const TrashedPage({ required this.id, required this.title, required this.icon, required this.deletedAt, }); factory TrashedPage.fromJson(Map json) => TrashedPage( id: json['id'] as String, title: json['title'] as String, icon: json['icon'] as String, deletedAt: json['deletedAt'] as String, ); final String id; final String title; final String icon; final String deletedAt; Map toJson() => { 'id': id, 'title': title, 'icon': icon, 'deletedAt': deletedAt, }; } class PushDevice { const PushDevice({ required this.id, required this.name, required this.created, }); factory PushDevice.fromJson(Map json) => PushDevice( id: json['id'] as String, name: json['name'] as String, created: json['created'] as String, ); final String id; final String name; final String created; Map toJson() => {'id': id, 'name': name, 'created': created}; } /// The JSON body docwell-server POSTs to a phone's push endpoint class PushMessage { const PushMessage({ required this.title, required this.body, required this.route, }); factory PushMessage.fromJson(Map json) => PushMessage( title: json['title'] as String, body: json['body'] as String, route: json['route'] as String, ); /// The page's icon and title final String title; /// For example "Ann mentioned you: …" final String body; /// The app route to open, for example /p/``?comment=`` final String route; Map toJson() => { 'title': title, 'body': body, 'route': route, }; } class ArchivedPage { const ArchivedPage({ required this.id, required this.title, required this.icon, required this.archivedAt, }); factory ArchivedPage.fromJson(Map json) => ArchivedPage( id: json['id'] as String, title: json['title'] as String, icon: json['icon'] as String, archivedAt: json['archivedAt'] as String, ); final String id; final String title; final String icon; final String archivedAt; Map toJson() => { 'id': id, 'title': title, 'icon': icon, 'archivedAt': archivedAt, }; } class PinnedPage { const PinnedPage({ required this.id, required this.title, required this.icon, required this.updated, required this.pinnedAt, }); factory PinnedPage.fromJson(Map json) => PinnedPage( id: json['id'] as String, title: json['title'] as String, icon: json['icon'] as String, updated: json['updated'] as String, pinnedAt: json['pinnedAt'] as String, ); final String id; final String title; final String icon; final String updated; final String pinnedAt; Map toJson() => { 'id': id, 'title': title, 'icon': icon, 'updated': updated, 'pinnedAt': pinnedAt, }; } /// The state for its colour enum LinkPreviewState { open('open'), started('started'), draft('draft'), merged('merged'), done('done'), closed('closed'), canceled('canceled'); const LinkPreviewState(this.value); final String value; static LinkPreviewState fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown LinkPreviewState', value), ); String toJson() => value; } class LinkPreview { const LinkPreview({ required this.url, required this.title, required this.description, required this.image, required this.site, this.kind, this.status, this.state, this.meta, }); factory LinkPreview.fromJson(Map json) => LinkPreview( url: json['url'] as String, title: json['title'] as String, description: json['description'] as String, image: json['image'] as String, site: json['site'] as String, kind: json['kind'] == null ? null : json['kind'] as String, status: json['status'] == null ? null : json['status'] as String, state: json['state'] == null ? null : LinkPreviewState.fromJson(json['state'] as String), meta: json['meta'] == null ? null : json['meta'] as String, ); final String url; final String title; final String description; /// Address of the page's picture on its own site; empty when it has none final String image; final String site; /// For links read through a service's API (github.issue, github.pull, github.repo, linear.issue, figma.file) final String? kind; /// The service's word for the item's state (Open, Merged, In Progress) final String? status; /// The state for its colour final LinkPreviewState? state; /// A line of details (acme/app #12 · alice) final String? meta; Map toJson() => { 'url': url, 'title': title, 'description': description, 'image': image, 'site': site, 'kind': ?kind, 'status': ?status, 'state': ?state?.toJson(), 'meta': ?meta, }; } class WorkspaceIntegrations { const WorkspaceIntegrations({ required this.github, required this.linear, required this.figma, required this.slack, }); factory WorkspaceIntegrations.fromJson( Map json, ) => WorkspaceIntegrations( github: IntegrationToken.fromJson(json['github'] as Map), linear: IntegrationToken.fromJson(json['linear'] as Map), figma: IntegrationToken.fromJson(json['figma'] as Map), slack: SlackIntegration.fromJson(json['slack'] as Map), ); final IntegrationToken github; final IntegrationToken linear; final IntegrationToken figma; final SlackIntegration slack; Map toJson() => { 'github': github.toJson(), 'linear': linear.toJson(), 'figma': figma.toJson(), 'slack': slack.toJson(), }; } class IntegrationToken { const IntegrationToken({required this.set}); factory IntegrationToken.fromJson(Map json) => IntegrationToken(set: json['set'] as bool); /// A token is stored (it is never sent back) final bool set; Map toJson() => {'set': set}; } class SlackIntegration { const SlackIntegration({ required this.connected, required this.hasSigningSecret, required this.team, required this.teamName, required this.channel, required this.channelName, required this.events, required this.unfurl, required this.search, required this.lastError, required this.eventsUrl, required this.commandsUrl, required this.manifest, }); factory SlackIntegration.fromJson(Map json) => SlackIntegration( connected: json['connected'] as bool, hasSigningSecret: json['hasSigningSecret'] as bool, team: json['team'] as String, teamName: json['teamName'] as String, channel: json['channel'] as String, channelName: json['channelName'] as String, events: (json['events'] as List).map((e) => e as String).toList(), unfurl: json['unfurl'] as bool, search: json['search'] as bool, lastError: json['lastError'] as String, eventsUrl: json['eventsUrl'] as String, commandsUrl: json['commandsUrl'] as String, manifest: json['manifest'] as String, ); /// A bot token is stored final bool connected; final bool hasSigningSecret; /// The Slack workspace id the bot belongs to final String team; final String teamName; /// The channel id posts go to; empty for none final String channel; final String channelName; /// Events posted to the channel final List events; /// Docwell links posted in Slack get a preview final bool unfurl; /// /docwell searches Docwell final bool search; /// The last post that failed; empty when the last one worked final String lastError; /// Request URL for the Slack app's Event Subscriptions final String eventsUrl; /// Request URL for the /docwell slash command final String commandsUrl; /// A Slack app manifest (JSON) with those URLs and the scopes Docwell needs final String manifest; Map toJson() => { 'connected': connected, 'hasSigningSecret': hasSigningSecret, 'team': team, 'teamName': teamName, 'channel': channel, 'channelName': channelName, 'events': events.map((e) => e).toList(), 'unfurl': unfurl, 'search': search, 'lastError': lastError, 'eventsUrl': eventsUrl, 'commandsUrl': commandsUrl, 'manifest': manifest, }; } enum SlackIntegrationInputEvents { pageCreated('page.created'), pageUpdated('page.updated'), pageMoved('page.moved'), pageArchived('page.archived'), pageUnarchived('page.unarchived'), pageRestored('page.restored'), commentCreated('comment.created'), commentResolved('comment.resolved'); const SlackIntegrationInputEvents(this.value); final String value; static SlackIntegrationInputEvents fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown SlackIntegrationInputEvents', value), ); String toJson() => value; } class SlackIntegrationInput { const SlackIntegrationInput({ this.botToken, this.signingSecret, this.channel, this.events, this.unfurl, this.search, }); factory SlackIntegrationInput.fromJson(Map json) => SlackIntegrationInput( botToken: json['botToken'] == null ? null : json['botToken'] as String, signingSecret: json['signingSecret'] == null ? null : json['signingSecret'] as String, channel: json['channel'] == null ? null : json['channel'] as String, events: json['events'] == null ? null : (json['events'] as List) .map((e) => SlackIntegrationInputEvents.fromJson(e as String)) .toList(), unfurl: json['unfurl'] == null ? null : json['unfurl'] as bool, search: json['search'] == null ? null : json['search'] as bool, ); /// The app's Bot User OAuth Token (xoxb-…); checked with Slack final String? botToken; /// The app's Signing Secret final String? signingSecret; /// A public channel id or name (#news); empty for none final String? channel; final List? events; final bool? unfurl; final bool? search; Map toJson() => { 'botToken': ?botToken, 'signingSecret': ?signingSecret, 'channel': ?channel, 'events': ?events?.map((e) => e.toJson()).toList(), 'unfurl': ?unfurl, 'search': ?search, }; } class Session { const Session({required this.token, required this.user}); factory Session.fromJson(Map json) => Session( token: json['token'] as String, user: User.fromJson(json['user'] as Map), ); final String token; final User user; Map toJson() => {'token': token, 'user': user.toJson()}; } class UserList { const UserList({ required this.items, required this.page, required this.perPage, required this.totalItems, }); factory UserList.fromJson(Map json) => UserList( items: (json['items'] as List) .map((e) => User.fromJson(e as Map)) .toList(), page: (json['page'] as num).toInt(), perPage: (json['perPage'] as num).toInt(), totalItems: (json['totalItems'] as num).toInt(), ); final List items; final int page; final int perPage; final int totalItems; Map toJson() => { 'items': items.map((e) => e.toJson()).toList(), 'page': page, 'perPage': perPage, 'totalItems': totalItems, }; } class AuthMethodsProviders { const AuthMethodsProviders({required this.name, required this.displayName}); factory AuthMethodsProviders.fromJson(Map json) => AuthMethodsProviders( name: json['name'] as String, displayName: json['displayName'] as String, ); final String name; final String displayName; Map toJson() => {'name': name, 'displayName': displayName}; } class AuthMethods { const AuthMethods({ required this.password, required this.otp, required this.mfa, required this.oauth2, required this.providers, required this.signup, }); factory AuthMethods.fromJson(Map json) => AuthMethods( password: json['password'] as bool, otp: json['otp'] as bool, mfa: json['mfa'] as bool, oauth2: (json['oauth2'] as List).map((e) => e as String).toList(), providers: (json['providers'] as List) .map((e) => AuthMethodsProviders.fromJson(e as Map)) .toList(), signup: json['signup'] as bool, ); final bool password; final bool otp; final bool mfa; final List oauth2; final List providers; final bool signup; Map toJson() => { 'password': password, 'otp': otp, 'mfa': mfa, 'oauth2': oauth2.map((e) => e).toList(), 'providers': providers.map((e) => e.toJson()).toList(), 'signup': signup, }; } class SignupRequest { const SignupRequest({ required this.email, required this.password, required this.name, }); factory SignupRequest.fromJson(Map json) => SignupRequest( email: json['email'] as String, password: json['password'] as String, name: json['name'] as String, ); final String email; final String password; final String name; Map toJson() => { 'email': email, 'password': password, 'name': name, }; } class LoginRequest { const LoginRequest({required this.email, required this.password, this.mfaId}); factory LoginRequest.fromJson(Map json) => LoginRequest( email: json['email'] as String, password: json['password'] as String, mfaId: json['mfaId'] == null ? null : json['mfaId'] as String, ); final String email; final String password; final String? mfaId; Map toJson() => { 'email': email, 'password': password, 'mfaId': ?mfaId, }; } class EmailRequest { const EmailRequest({required this.email}); factory EmailRequest.fromJson(Map json) => EmailRequest(email: json['email'] as String); final String email; Map toJson() => {'email': email}; } enum StatusStatus { ok('ok'), unavailable('unavailable'); const StatusStatus(this.value); final String value; static StatusStatus fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown StatusStatus', value), ); String toJson() => value; } class Status { const Status({required this.status, this.db}); factory Status.fromJson(Map json) => Status( status: StatusStatus.fromJson(json['status'] as String), db: json['db'] == null ? null : json['db'] as String, ); final StatusStatus status; final String? db; Map toJson() => {'status': status.toJson(), 'db': ?db}; } class Version { const Version({required this.name, required this.version}); factory Version.fromJson(Map json) => Version(name: json['name'] as String, version: json['version'] as String); final String name; final String version; Map toJson() => {'name': name, 'version': version}; } class PublicSettings { const PublicSettings({ required this.appName, required this.accentColor, required this.logo, required this.signup, required this.magicLink, }); factory PublicSettings.fromJson(Map json) => PublicSettings( appName: json['appName'] as String, accentColor: json['accentColor'] as String, logo: json['logo'] as String, signup: json['signup'] as bool, magicLink: json['magicLink'] as bool, ); final String appName; /// #rrggbb, or empty for the default final String accentColor; /// A data URL final String logo; /// Self-service signup is open final bool signup; /// Sign-in links by email are enabled final bool magicLink; Map toJson() => { 'appName': appName, 'accentColor': accentColor, 'logo': logo, 'signup': signup, 'magicLink': magicLink, }; } class SignupSettings { const SignupSettings({required this.enabled, required this.domains}); factory SignupSettings.fromJson(Map json) => SignupSettings( enabled: json['enabled'] as bool, domains: (json['domains'] as List).map((e) => e as String).toList(), ); final bool enabled; /// Allowed email domains; empty allows all final List domains; Map toJson() => { 'enabled': enabled, 'domains': domains.map((e) => e).toList(), }; } class BrandingSettings { const BrandingSettings({ required this.appName, required this.accentColor, required this.logo, }); factory BrandingSettings.fromJson(Map json) => BrandingSettings( appName: json['appName'] as String, accentColor: json['accentColor'] as String, logo: json['logo'] as String, ); final String appName; final String accentColor; /// data:image/(png|jpeg|webp|svg+xml);base64,..., at most 256 KB final String logo; Map toJson() => { 'appName': appName, 'accentColor': accentColor, 'logo': logo, }; } class SmtpSettings { const SmtpSettings({ required this.enabled, required this.host, required this.port, required this.username, this.password, required this.passwordSet, required this.tls, required this.senderName, required this.senderAddress, }); factory SmtpSettings.fromJson(Map json) => SmtpSettings( enabled: json['enabled'] as bool, host: json['host'] as String, port: (json['port'] as num).toInt(), username: json['username'] as String, password: json['password'] == null ? null : json['password'] as String, passwordSet: json['passwordSet'] as bool, tls: json['tls'] as bool, senderName: json['senderName'] as String, senderAddress: json['senderAddress'] as String, ); final bool enabled; final String host; final int port; final String username; /// Leave out to keep the stored password final String? password; final bool passwordSet; final bool tls; final String senderName; final String senderAddress; Map toJson() => { 'enabled': enabled, 'host': host, 'port': port, 'username': username, 'password': ?password, 'passwordSet': passwordSet, 'tls': tls, 'senderName': senderName, 'senderAddress': senderAddress, }; } class StorageSettings { const StorageSettings({ required this.s3, required this.bucket, required this.region, required this.endpoint, required this.accessKey, this.secret, required this.secretSet, required this.forcePathStyle, }); factory StorageSettings.fromJson(Map json) => StorageSettings( s3: json['s3'] as bool, bucket: json['bucket'] as String, region: json['region'] as String, endpoint: json['endpoint'] as String, accessKey: json['accessKey'] as String, secret: json['secret'] == null ? null : json['secret'] as String, secretSet: json['secretSet'] as bool, forcePathStyle: json['forcePathStyle'] as bool, ); /// false stores files on docwell-db's disk final bool s3; final String bucket; final String region; final String endpoint; final String accessKey; /// Leave out to keep the stored secret final String? secret; final bool secretSet; final bool forcePathStyle; Map toJson() => { 's3': s3, 'bucket': bucket, 'region': region, 'endpoint': endpoint, 'accessKey': accessKey, 'secret': ?secret, 'secretSet': secretSet, 'forcePathStyle': forcePathStyle, }; } class InstanceSettings { const InstanceSettings({ required this.signup, required this.auth, required this.branding, required this.smtp, required this.storage, }); factory InstanceSettings.fromJson(Map json) => InstanceSettings( signup: SignupSettings.fromJson(json['signup'] as Map), auth: AuthSettings.fromJson(json['auth'] as Map), branding: BrandingSettings.fromJson( json['branding'] as Map, ), smtp: SmtpSettings.fromJson(json['smtp'] as Map), storage: StorageSettings.fromJson( json['storage'] as Map, ), ); final SignupSettings signup; final AuthSettings auth; final BrandingSettings branding; final SmtpSettings smtp; final StorageSettings storage; Map toJson() => { 'signup': signup.toJson(), 'auth': auth.toJson(), 'branding': branding.toJson(), 'smtp': smtp.toJson(), 'storage': storage.toJson(), }; } class InstanceSettingsUpdate { const InstanceSettingsUpdate({ this.signup, this.auth, this.branding, this.smtp, this.storage, }); factory InstanceSettingsUpdate.fromJson(Map json) => InstanceSettingsUpdate( signup: json['signup'] == null ? null : SignupSettings.fromJson(json['signup'] as Map), auth: json['auth'] == null ? null : AuthSettings.fromJson(json['auth'] as Map), branding: json['branding'] == null ? null : BrandingSettings.fromJson( json['branding'] as Map, ), smtp: json['smtp'] == null ? null : SmtpSettings.fromJson(json['smtp'] as Map), storage: json['storage'] == null ? null : StorageSettings.fromJson(json['storage'] as Map), ); final SignupSettings? signup; final AuthSettings? auth; final BrandingSettings? branding; final SmtpSettings? smtp; final StorageSettings? storage; Map toJson() => { 'signup': ?signup?.toJson(), 'auth': ?auth?.toJson(), 'branding': ?branding?.toJson(), 'smtp': ?smtp?.toJson(), 'storage': ?storage?.toJson(), }; } class OAuthStart { const OAuthStart({required this.url, required this.state}); factory OAuthStart.fromJson(Map json) => OAuthStart(url: json['url'] as String, state: json['state'] as String); final String url; final String state; Map toJson() => {'url': url, 'state': state}; } class TotpStatus { const TotpStatus({required this.enabled, required this.recoveryCodesLeft}); factory TotpStatus.fromJson(Map json) => TotpStatus( enabled: json['enabled'] as bool, recoveryCodesLeft: (json['recoveryCodesLeft'] as num).toInt(), ); final bool enabled; final int recoveryCodesLeft; Map toJson() => { 'enabled': enabled, 'recoveryCodesLeft': recoveryCodesLeft, }; } class TotpSetup { const TotpSetup({required this.secret, required this.url, required this.qr}); factory TotpSetup.fromJson(Map json) => TotpSetup( secret: json['secret'] as String, url: json['url'] as String, qr: json['qr'] as String, ); /// For typing into the app by hand final String secret; /// The otpauth:// address final String url; /// PNG data URL of the QR code final String qr; Map toJson() => {'secret': secret, 'url': url, 'qr': qr}; } enum ApiTokenScope { read('read'), write('write'); const ApiTokenScope(this.value); final String value; static ApiTokenScope fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown ApiTokenScope', value), ); String toJson() => value; } /// In admin listings class ApiTokenUser { const ApiTokenUser({ required this.id, required this.email, required this.name, }); factory ApiTokenUser.fromJson(Map json) => ApiTokenUser( id: json['id'] as String, email: json['email'] as String, name: json['name'] as String, ); final String id; final String email; final String name; Map toJson() => {'id': id, 'email': email, 'name': name}; } class ApiToken { const ApiToken({ required this.id, required this.name, required this.prefix, required this.scope, required this.lastUsed, required this.expires, required this.created, this.user, }); factory ApiToken.fromJson(Map json) => ApiToken( id: json['id'] as String, name: json['name'] as String, prefix: json['prefix'] as String, scope: ApiTokenScope.fromJson(json['scope'] as String), lastUsed: json['lastUsed'] as String, expires: json['expires'] as String, created: json['created'] as String, user: json['user'] == null ? null : ApiTokenUser.fromJson(json['user'] as Map), ); final String id; final String name; /// The token's first characters final String prefix; final ApiTokenScope scope; final String lastUsed; /// Empty when it never expires final String expires; final String created; /// In admin listings final ApiTokenUser? user; Map toJson() => { 'id': id, 'name': name, 'prefix': prefix, 'scope': scope.toJson(), 'lastUsed': lastUsed, 'expires': expires, 'created': created, 'user': ?user?.toJson(), }; } class NewApiToken { const NewApiToken({ required this.id, required this.name, required this.prefix, required this.scope, required this.lastUsed, required this.expires, required this.created, this.user, required this.token, }); factory NewApiToken.fromJson(Map json) => NewApiToken( id: json['id'] as String, name: json['name'] as String, prefix: json['prefix'] as String, scope: ApiTokenScope.fromJson(json['scope'] as String), lastUsed: json['lastUsed'] as String, expires: json['expires'] as String, created: json['created'] as String, user: json['user'] == null ? null : ApiTokenUser.fromJson(json['user'] as Map), token: json['token'] as String, ); final String id; final String name; /// The token's first characters final String prefix; final ApiTokenScope scope; final String lastUsed; /// Empty when it never expires final String expires; final String created; /// In admin listings final ApiTokenUser? user; /// The token; it is not shown again final String token; Map toJson() => { 'id': id, 'name': name, 'prefix': prefix, 'scope': scope.toJson(), 'lastUsed': lastUsed, 'expires': expires, 'created': created, 'user': ?user?.toJson(), 'token': token, }; } class AuditEntry { const AuditEntry({ required this.id, required this.created, required this.action, required this.actorId, required this.actorEmail, required this.targetType, required this.targetId, required this.status, required this.ip, required this.userAgent, required this.meta, }); factory AuditEntry.fromJson(Map json) => AuditEntry( id: json['id'] as String, created: json['created'] as String, action: json['action'] as String, actorId: json['actorId'] as String, actorEmail: json['actorEmail'] as String, targetType: json['targetType'] as String, targetId: json['targetId'] as String, status: (json['status'] as num).toInt(), ip: json['ip'] as String, userAgent: json['userAgent'] as String, meta: json['meta'] == null ? null : json['meta'] as Map, ); final String id; final String created; /// A sign-in step ("auth.login", "auth.login.failed") or the route of a change ("PATCH /pages/{id}") final String action; final String actorId; final String actorEmail; final String targetType; final String targetId; final int status; final String ip; final String userAgent; final Map? meta; Map toJson() => { 'id': id, 'created': created, 'action': action, 'actorId': actorId, 'actorEmail': actorEmail, 'targetType': targetType, 'targetId': targetId, 'status': status, 'ip': ip, 'userAgent': userAgent, 'meta': meta, }; } class AuditPage { const AuditPage({ required this.items, required this.total, required this.page, }); factory AuditPage.fromJson(Map json) => AuditPage( items: (json['items'] as List) .map((e) => AuditEntry.fromJson(e as Map)) .toList(), total: (json['total'] as num).toInt(), page: (json['page'] as num).toInt(), ); final List items; final int total; final int page; Map toJson() => { 'items': items.map((e) => e.toJson()).toList(), 'total': total, 'page': page, }; } enum WebhookEvent { all('*'), pageCreated('page.created'), pageUpdated('page.updated'), pageMoved('page.moved'), pageTrashed('page.trashed'), pageRestored('page.restored'), pageDeleted('page.deleted'), pageArchived('page.archived'), pageUnarchived('page.unarchived'), commentCreated('comment.created'), commentResolved('comment.resolved'), spaceCreated('space.created'), spaceDeleted('space.deleted'); const WebhookEvent(this.value); final String value; static WebhookEvent fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown WebhookEvent', value), ); String toJson() => value; } class Webhook { const Webhook({ required this.id, required this.name, required this.url, required this.events, required this.active, this.secret, required this.created, }); factory Webhook.fromJson(Map json) => Webhook( id: json['id'] as String, name: json['name'] as String, url: json['url'] as String, events: (json['events'] as List) .map((e) => WebhookEvent.fromJson(e as String)) .toList(), active: json['active'] as bool, secret: json['secret'] == null ? null : json['secret'] as String, created: json['created'] as String, ); final String id; final String name; final String url; final List events; final bool active; /// Only when just created final String? secret; final String created; Map toJson() => { 'id': id, 'name': name, 'url': url, 'events': events.map((e) => e.toJson()).toList(), 'active': active, 'secret': ?secret, 'created': created, }; } class WebhookInput { const WebhookInput({this.name, this.url, this.events, this.active}); factory WebhookInput.fromJson(Map json) => WebhookInput( name: json['name'] == null ? null : json['name'] as String, url: json['url'] == null ? null : json['url'] as String, events: json['events'] == null ? null : (json['events'] as List) .map((e) => WebhookEvent.fromJson(e as String)) .toList(), active: json['active'] == null ? null : json['active'] as bool, ); final String? name; final String? url; /// Defaults to all ("*") final List? events; final bool? active; Map toJson() => { 'name': ?name, 'url': ?url, 'events': ?events?.map((e) => e.toJson()).toList(), 'active': ?active, }; } enum WebhookDeliveryStatus { pending('pending'), success('success'), failed('failed'); const WebhookDeliveryStatus(this.value); final String value; static WebhookDeliveryStatus fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown WebhookDeliveryStatus', value), ); String toJson() => value; } class WebhookDelivery { const WebhookDelivery({ required this.id, required this.event, required this.deliveryId, required this.status, required this.attempts, required this.responseCode, required this.error, required this.durationMs, required this.created, }); factory WebhookDelivery.fromJson(Map json) => WebhookDelivery( id: json['id'] as String, event: json['event'] as String, deliveryId: json['deliveryId'] as String, status: WebhookDeliveryStatus.fromJson(json['status'] as String), attempts: (json['attempts'] as num).toInt(), responseCode: (json['responseCode'] as num).toInt(), error: json['error'] as String, durationMs: (json['durationMs'] as num).toInt(), created: json['created'] as String, ); final String id; final String event; /// The payload's id (X-Docwell-Delivery) final String deliveryId; final WebhookDeliveryStatus status; final int attempts; final int responseCode; final String error; final int durationMs; final String created; Map toJson() => { 'id': id, 'event': event, 'deliveryId': deliveryId, 'status': status.toJson(), 'attempts': attempts, 'responseCode': responseCode, 'error': error, 'durationMs': durationMs, 'created': created, }; } enum OAuthProviderSettingsName { google('google'), github('github'), microsoft('microsoft'), oidc('oidc'); const OAuthProviderSettingsName(this.value); final String value; static OAuthProviderSettingsName fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown OAuthProviderSettingsName', value), ); String toJson() => value; } class OAuthProviderSettings { const OAuthProviderSettings({ required this.name, required this.clientId, this.clientSecret, required this.displayName, required this.authUrl, required this.tokenUrl, required this.userInfoUrl, }); factory OAuthProviderSettings.fromJson(Map json) => OAuthProviderSettings( name: OAuthProviderSettingsName.fromJson(json['name'] as String), clientId: json['clientId'] as String, clientSecret: json['clientSecret'] == null ? null : json['clientSecret'] as String, displayName: json['displayName'] as String, authUrl: json['authUrl'] as String, tokenUrl: json['tokenUrl'] as String, userInfoUrl: json['userInfoUrl'] as String, ); final OAuthProviderSettingsName name; final String clientId; /// Write-only; leave out to keep the stored one final String? clientSecret; final String displayName; /// OpenID Connect only final String authUrl; /// OpenID Connect only final String tokenUrl; /// OpenID Connect only final String userInfoUrl; Map toJson() => { 'name': name.toJson(), 'clientId': clientId, 'clientSecret': ?clientSecret, 'displayName': displayName, 'authUrl': authUrl, 'tokenUrl': tokenUrl, 'userInfoUrl': userInfoUrl, }; } class AuthSettings { const AuthSettings({ required this.magicLink, required this.oauth2, this.callbackUrl, }); factory AuthSettings.fromJson(Map json) => AuthSettings( magicLink: json['magicLink'] as bool, oauth2: (json['oauth2'] as List) .map((e) => OAuthProviderSettings.fromJson(e as Map)) .toList(), callbackUrl: json['callbackUrl'] == null ? null : json['callbackUrl'] as String, ); /// Email a one-time sign-in link and code final bool magicLink; /// Sign-in providers; saving replaces the list (leave it out to keep it) final List oauth2; /// Read-only: the address to register with each provider final String? callbackUrl; Map toJson() => { 'magicLink': magicLink, 'oauth2': oauth2.map((e) => e.toJson()).toList(), 'callbackUrl': ?callbackUrl, }; } enum InviteStatus { pending('pending'), expired('expired'), added('added'); const InviteStatus(this.value); final String value; static InviteStatus fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown InviteStatus', value), ); String toJson() => value; } class Invite { const Invite({ required this.id, required this.email, required this.organization, required this.organizationName, required this.role, required this.workspace, required this.workspaceName, required this.workspaceRole, required this.invitedBy, required this.expires, required this.created, required this.status, this.link, required this.mailed, }); factory Invite.fromJson(Map json) => Invite( id: json['id'] as String, email: json['email'] as String, organization: json['organization'] as String, organizationName: json['organizationName'] as String, role: Role.fromJson(json['role'] as String), workspace: json['workspace'] as String, workspaceName: json['workspaceName'] as String, workspaceRole: json['workspaceRole'] as String, invitedBy: json['invitedBy'] as String, expires: json['expires'] as String, created: json['created'] as String, status: InviteStatus.fromJson(json['status'] as String), link: json['link'] == null ? null : json['link'] as String, mailed: json['mailed'] as bool, ); /// Empty when status is added final String id; final String email; final String organization; final String organizationName; final Role role; final String workspace; final String workspaceName; /// A workspace role final String workspaceRole; /// Inviter's name final String invitedBy; final String expires; final String created; final InviteStatus status; /// Only when just created or resent final String? link; /// The email was handed to the mail server final bool mailed; Map toJson() => { 'id': id, 'email': email, 'organization': organization, 'organizationName': organizationName, 'role': role.toJson(), 'workspace': workspace, 'workspaceName': workspaceName, 'workspaceRole': workspaceRole, 'invitedBy': invitedBy, 'expires': expires, 'created': created, 'status': status.toJson(), 'link': ?link, 'mailed': mailed, }; } class CreateInviteRequest { const CreateInviteRequest({ required this.email, this.role, this.organization, this.workspace, this.workspaceRole, }); factory CreateInviteRequest.fromJson( Map json, ) => CreateInviteRequest( email: json['email'] as String, role: json['role'] == null ? null : Role.fromJson(json['role'] as String), organization: json['organization'] == null ? null : json['organization'] as String, workspace: json['workspace'] == null ? null : json['workspace'] as String, workspaceRole: json['workspaceRole'] == null ? null : WorkspaceRole.fromJson(json['workspaceRole'] as String), ); final String email; final Role? role; /// Superadmins only; admins always invite into their own final String? organization; /// Makes this a workspace invite final String? workspace; final WorkspaceRole? workspaceRole; Map toJson() => { 'email': email, 'role': ?role?.toJson(), 'organization': ?organization, 'workspace': ?workspace, 'workspaceRole': ?workspaceRole?.toJson(), }; } class InviteInfo { const InviteInfo({ required this.email, required this.organizationName, required this.workspaceName, required this.invitedBy, required this.expires, required this.hasAccount, }); factory InviteInfo.fromJson(Map json) => InviteInfo( email: json['email'] as String, organizationName: json['organizationName'] as String, workspaceName: json['workspaceName'] as String, invitedBy: json['invitedBy'] as String, expires: json['expires'] as String, hasAccount: json['hasAccount'] as bool, ); final String email; final String organizationName; final String workspaceName; final String invitedBy; final String expires; /// Sign in to accept instead of signing up final bool hasAccount; Map toJson() => { 'email': email, 'organizationName': organizationName, 'workspaceName': workspaceName, 'invitedBy': invitedBy, 'expires': expires, 'hasAccount': hasAccount, }; } class MemberUser { const MemberUser({required this.id, required this.email, required this.name}); factory MemberUser.fromJson(Map json) => MemberUser( id: json['id'] as String, email: json['email'] as String, name: json['name'] as String, ); final String id; final String email; final String name; Map toJson() => {'id': id, 'email': email, 'name': name}; } class Group { const Group({ required this.id, required this.workspace, required this.name, required this.description, required this.members, required this.created, }); factory Group.fromJson(Map json) => Group( id: json['id'] as String, workspace: json['workspace'] as String, name: json['name'] as String, description: json['description'] as String, members: (json['members'] as num).toInt(), created: json['created'] as String, ); final String id; final String workspace; final String name; final String description; final int members; final String created; Map toJson() => { 'id': id, 'workspace': workspace, 'name': name, 'description': description, 'members': members, 'created': created, }; } class GroupRequest { const GroupRequest({this.name, this.description}); factory GroupRequest.fromJson(Map json) => GroupRequest( name: json['name'] == null ? null : json['name'] as String, description: json['description'] == null ? null : json['description'] as String, ); final String? name; final String? description; Map toJson() => {'name': ?name, 'description': ?description}; } class SpaceGroupGroup { const SpaceGroupGroup({required this.id, required this.name}); factory SpaceGroupGroup.fromJson(Map json) => SpaceGroupGroup(id: json['id'] as String, name: json['name'] as String); final String id; final String name; Map toJson() => {'id': id, 'name': name}; } class SpaceGroup { const SpaceGroup({required this.group, required this.role}); factory SpaceGroup.fromJson(Map json) => SpaceGroup( group: SpaceGroupGroup.fromJson(json['group'] as Map), role: SpaceRole.fromJson(json['role'] as String), ); final SpaceGroupGroup group; final SpaceRole role; Map toJson() => { 'group': group.toJson(), 'role': role.toJson(), }; } class PageItem { const PageItem({ required this.id, required this.title, required this.icon, required this.space, required this.spaceName, required this.at, }); factory PageItem.fromJson(Map json) => PageItem( id: json['id'] as String, title: json['title'] as String, icon: json['icon'] as String, space: json['space'] as String, spaceName: json['spaceName'] as String, at: json['at'] as String, ); final String id; final String title; final String icon; final String space; final String spaceName; /// When it was favorited final String at; Map toJson() => { 'id': id, 'title': title, 'icon': icon, 'space': space, 'spaceName': spaceName, 'at': at, }; } class Attachment { const Attachment({ required this.id, required this.page, required this.name, required this.mime, required this.size, required this.url, required this.created, }); factory Attachment.fromJson(Map json) => Attachment( id: json['id'] as String, page: json['page'] as String, name: json['name'] as String, mime: json['mime'] as String, size: (json['size'] as num).toInt(), url: json['url'] as String, created: json['created'] as String, ); final String id; final String page; final String name; /// Detected from the content final String mime; /// Bytes final int size; /// API path, e.g. /api/v1/files/abc final String url; final String created; Map toJson() => { 'id': id, 'page': page, 'name': name, 'mime': mime, 'size': size, 'url': url, 'created': created, }; } enum InviteLinkRole { member('member'), guest('guest'); const InviteLinkRole(this.value); final String value; static InviteLinkRole fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown InviteLinkRole', value), ); String toJson() => value; } class InviteLink { const InviteLink({ required this.token, required this.url, required this.role, required this.approval, required this.expires, required this.created, required this.pending, }); factory InviteLink.fromJson(Map json) => InviteLink( token: json['token'] as String, url: json['url'] as String, role: InviteLinkRole.fromJson(json['role'] as String), approval: json['approval'] as bool, expires: json['expires'] as String, created: json['created'] as String, pending: (json['pending'] as num).toInt(), ); final String token; /// The link on docwell-web (DOCWELL_WEB_URL/join?token=...) final String url; final InviteLinkRole role; /// Joining needs an admin's approval final bool approval; /// Empty when the link does not expire final String expires; final String created; /// Requests waiting for a decision final int pending; Map toJson() => { 'token': token, 'url': url, 'role': role.toJson(), 'approval': approval, 'expires': expires, 'created': created, 'pending': pending, }; } enum JoinRequestRole { member('member'), guest('guest'); const JoinRequestRole(this.value); final String value; static JoinRequestRole fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown JoinRequestRole', value), ); String toJson() => value; } class JoinRequest { const JoinRequest({ required this.id, required this.user, required this.role, required this.created, }); factory JoinRequest.fromJson(Map json) => JoinRequest( id: json['id'] as String, user: MemberUser.fromJson(json['user'] as Map), role: JoinRequestRole.fromJson(json['role'] as String), created: json['created'] as String, ); final String id; final MemberUser user; final JoinRequestRole role; final String created; Map toJson() => { 'id': id, 'user': user.toJson(), 'role': role.toJson(), 'created': created, }; } enum JoinInfoRole { member('member'), guest('guest'); const JoinInfoRole(this.value); final String value; static JoinInfoRole fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown JoinInfoRole', value), ); String toJson() => value; } /// The caller's standing; empty when signed out or not asked yet enum JoinInfoStatus { none(''), member('member'), pending('pending'), declined('declined'); const JoinInfoStatus(this.value); final String value; static JoinInfoStatus fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown JoinInfoStatus', value), ); String toJson() => value; } class JoinInfo { const JoinInfo({ required this.workspace, required this.workspaceName, required this.organizationName, required this.role, required this.approval, required this.status, }); factory JoinInfo.fromJson(Map json) => JoinInfo( workspace: json['workspace'] as String, workspaceName: json['workspaceName'] as String, organizationName: json['organizationName'] as String, role: JoinInfoRole.fromJson(json['role'] as String), approval: json['approval'] as bool, status: JoinInfoStatus.fromJson(json['status'] as String), ); final String workspace; final String workspaceName; final String organizationName; final JoinInfoRole role; final bool approval; /// The caller's standing; empty when signed out or not asked yet final JoinInfoStatus status; Map toJson() => { 'workspace': workspace, 'workspaceName': workspaceName, 'organizationName': organizationName, 'role': role.toJson(), 'approval': approval, 'status': status.toJson(), }; } enum JoinResultStatus { member('member'), pending('pending'); const JoinResultStatus(this.value); final String value; static JoinResultStatus fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown JoinResultStatus', value), ); String toJson() => value; } class JoinResult { const JoinResult({required this.status, required this.workspace}); factory JoinResult.fromJson(Map json) => JoinResult( status: JoinResultStatus.fromJson(json['status'] as String), workspace: json['workspace'] as String, ); final JoinResultStatus status; final String workspace; Map toJson() => { 'status': status.toJson(), 'workspace': workspace, }; } class PageAnalytics { const PageAnalytics({ required this.days, required this.views, required this.viewers, required this.linkViews, required this.daily, required this.recent, }); factory PageAnalytics.fromJson(Map json) => PageAnalytics( days: (json['days'] as num).toInt(), views: (json['views'] as num).toInt(), viewers: (json['viewers'] as num).toInt(), linkViews: (json['linkViews'] as num).toInt(), daily: (json['daily'] as List) .map((e) => AnalyticsDay.fromJson(e as Map)) .toList(), recent: (json['recent'] as List) .map((e) => PageViewer.fromJson(e as Map)) .toList(), ); final int days; /// Opens in the period (repeat opens within 30 minutes count once) final int views; /// Different signed-in people final int viewers; /// Opens through a share link final int linkViews; /// One entry per day (UTC), oldest first final List daily; /// Who opened the page, most recent first (at most 20) final List recent; Map toJson() => { 'days': days, 'views': views, 'viewers': viewers, 'linkViews': linkViews, 'daily': daily.map((e) => e.toJson()).toList(), 'recent': recent.map((e) => e.toJson()).toList(), }; } class AnalyticsDay { const AnalyticsDay({ required this.date, required this.views, required this.viewers, }); factory AnalyticsDay.fromJson(Map json) => AnalyticsDay( date: json['date'] as String, views: (json['views'] as num).toInt(), viewers: (json['viewers'] as num).toInt(), ); /// YYYY-MM-DD (UTC) final String date; final int views; final int viewers; Map toJson() => { 'date': date, 'views': views, 'viewers': viewers, }; } class PageViewer { const PageViewer({ required this.user, required this.views, required this.lastViewed, }); factory PageViewer.fromJson(Map json) => PageViewer( user: MemberUser.fromJson(json['user'] as Map), views: (json['views'] as num).toInt(), lastViewed: json['lastViewed'] as String, ); final MemberUser user; final int views; final String lastViewed; Map toJson() => { 'user': user.toJson(), 'views': views, 'lastViewed': lastViewed, }; } class UnusedFile { const UnusedFile({ required this.id, required this.page, required this.name, required this.mime, required this.size, required this.url, required this.created, required this.pageTitle, }); factory UnusedFile.fromJson(Map json) => UnusedFile( id: json['id'] as String, page: json['page'] as String, name: json['name'] as String, mime: json['mime'] as String, size: (json['size'] as num).toInt(), url: json['url'] as String, created: json['created'] as String, pageTitle: json['pageTitle'] as String, ); final String id; final String page; final String name; final String mime; /// Bytes final int size; final String url; final String created; /// The page it was uploaded to; empty when the caller cannot open it final String pageTitle; Map toJson() => { 'id': id, 'page': page, 'name': name, 'mime': mime, 'size': size, 'url': url, 'created': created, 'pageTitle': pageTitle, }; } class UnusedFiles { const UnusedFiles({required this.files, required this.size}); factory UnusedFiles.fromJson(Map json) => UnusedFiles( files: (json['files'] as List) .map((e) => UnusedFile.fromJson(e as Map)) .toList(), size: (json['size'] as num).toInt(), ); final List files; /// Total bytes final int size; Map toJson() => { 'files': files.map((e) => e.toJson()).toList(), 'size': size, }; } class PagePreview { const PagePreview({ required this.title, required this.description, required this.site, }); factory PagePreview.fromJson(Map json) => PagePreview( title: json['title'] as String, description: json['description'] as String, site: json['site'] as String, ); final String title; final String description; /// The workspace's name final String site; Map toJson() => { 'title': title, 'description': description, 'site': site, }; } /// Set when the hit is a database record; open it with the page link plus "#r-``-``" class SearchHitRecord { const SearchHitRecord({ required this.database, required this.row, required this.title, }); factory SearchHitRecord.fromJson(Map json) => SearchHitRecord( database: json['database'] as String, row: json['row'] as String, title: json['title'] as String, ); final String database; final String row; final String title; Map toJson() => { 'database': database, 'row': row, 'title': title, }; } /// Set when the match is in a file attached to the page (the text of PDFs, Word, HTML and text files is searchable); snippet is from the file class SearchHitFile { const SearchHitFile({required this.id, required this.name}); factory SearchHitFile.fromJson(Map json) => SearchHitFile(id: json['id'] as String, name: json['name'] as String); /// The attachment (its address is /api/v1/files/``) final String id; final String name; Map toJson() => {'id': id, 'name': name}; } class SearchHit { const SearchHit({ required this.id, required this.title, this.record, this.file, required this.icon, required this.space, required this.spaceName, required this.snippet, required this.highlights, required this.updated, }); factory SearchHit.fromJson(Map json) => SearchHit( id: json['id'] as String, title: json['title'] as String, record: json['record'] == null ? null : SearchHitRecord.fromJson(json['record'] as Map), file: json['file'] == null ? null : SearchHitFile.fromJson(json['file'] as Map), icon: json['icon'] as String, space: json['space'] as String, spaceName: json['spaceName'] as String, snippet: json['snippet'] as String, highlights: (json['highlights'] as List) .map((e) => (e as List).map((e) => (e as num).toInt()).toList()) .toList(), updated: json['updated'] as String, ); /// The page (also for a record: the page that holds it) final String id; /// The page's title final String title; /// Set when the hit is a database record; open it with the page link plus "#r-``-``" final SearchHitRecord? record; /// Set when the match is in a file attached to the page (the text of PDFs, Word, HTML and text files is searchable); snippet is from the file final SearchHitFile? file; final String icon; final String space; final String spaceName; /// Plain text around the first match final String snippet; /// [start, end) character offsets of matches in snippet final List> highlights; final String updated; Map toJson() => { 'id': id, 'title': title, 'record': ?record?.toJson(), 'file': ?file?.toJson(), 'icon': icon, 'space': space, 'spaceName': spaceName, 'snippet': snippet, 'highlights': highlights.map((e) => e.map((e) => e).toList()).toList(), 'updated': updated, }; } class SearchResult { const SearchResult({required this.items, required this.total}); factory SearchResult.fromJson(Map json) => SearchResult( items: (json['items'] as List) .map((e) => SearchHit.fromJson(e as Map)) .toList(), total: (json['total'] as num).toInt(), ); final List items; final int total; Map toJson() => { 'items': items.map((e) => e.toJson()).toList(), 'total': total, }; } class ShareLink { const ShareLink({ required this.token, required this.url, required this.includeSubpages, required this.created, }); factory ShareLink.fromJson(Map json) => ShareLink( token: json['token'] as String, url: json['url'] as String, includeSubpages: json['includeSubpages'] as bool, created: json['created'] as String, ); final String token; /// The link on docwell-web (DOCWELL_WEB_URL/share/``) final String url; final bool includeSubpages; final String created; Map toJson() => { 'token': token, 'url': url, 'includeSubpages': includeSubpages, 'created': created, }; } class SharedPage { const SharedPage({ required this.id, required this.title, required this.icon, required this.updated, required this.content, required this.mode, required this.root, required this.pages, }); factory SharedPage.fromJson(Map json) => SharedPage( id: json['id'] as String, title: json['title'] as String, icon: json['icon'] as String, updated: json['updated'] as String, content: json['content'] == null ? null : json['content'] as Map, mode: PageMode.fromJson(json['mode'] as String), root: PageRef.fromJson(json['root'] as Map), pages: (json['pages'] as List) .map((e) => PageNode.fromJson(e as Map)) .toList(), ); final String id; final String title; final String icon; final String updated; /// Tiptap JSON (with "surface", the edgeless canvas, when it has one); files load from /api/v1/share/{token}/files/{fileId} final Map? content; final PageMode mode; final PageRef root; /// Pages under the shared page final List pages; Map toJson() => { 'id': id, 'title': title, 'icon': icon, 'updated': updated, 'content': content, 'mode': mode.toJson(), 'root': root.toJson(), 'pages': pages.map((e) => e.toJson()).toList(), }; } class Comment { const Comment({ required this.id, required this.parent, required this.page, required this.author, required this.body, required this.quote, required this.anchor, required this.created, required this.editedAt, required this.resolvedAt, required this.resolvedBy, required this.reactions, required this.canEdit, required this.canDelete, required this.canResolve, }); factory Comment.fromJson(Map json) => Comment( id: json['id'] as String, parent: json['parent'] as String, page: json['page'] as String, author: MemberUser.fromJson(json['author'] as Map), body: json['body'] as String, quote: json['quote'] as String, anchor: json['anchor'] == null ? null : json['anchor'] as Map, created: json['created'] as String, editedAt: json['editedAt'] as String, resolvedAt: json['resolvedAt'] as String, resolvedBy: json['resolvedBy'] == null ? null : MemberUser.fromJson(json['resolvedBy'] as Map), reactions: (json['reactions'] as List) .map((e) => Reaction.fromJson(e as Map)) .toList(), canEdit: json['canEdit'] as bool, canDelete: json['canDelete'] as bool, canResolve: json['canResolve'] as bool, ); final String id; /// The thread's first comment for a reply; empty for a thread final String parent; final String page; final MemberUser author; final String body; final String quote; /// As sent when the comment was created; null when there was none final Map? anchor; final String created; /// Empty when never edited final String editedAt; /// Empty unless the thread is resolved final String resolvedAt; final MemberUser? resolvedBy; /// Most used first final List reactions; final bool canEdit; final bool canDelete; /// A thread the caller may resolve or reopen final bool canResolve; Map toJson() => { 'id': id, 'parent': parent, 'page': page, 'author': author.toJson(), 'body': body, 'quote': quote, 'anchor': anchor, 'created': created, 'editedAt': editedAt, 'resolvedAt': resolvedAt, 'resolvedBy': resolvedBy?.toJson(), 'reactions': reactions.map((e) => e.toJson()).toList(), 'canEdit': canEdit, 'canDelete': canDelete, 'canResolve': canResolve, }; } class Reaction { const Reaction({ required this.emoji, required this.count, required this.mine, required this.people, }); factory Reaction.fromJson(Map json) => Reaction( emoji: json['emoji'] as String, count: (json['count'] as num).toInt(), mine: json['mine'] as bool, people: (json['people'] as List).map((e) => e as String).toList(), ); final String emoji; final int count; final bool mine; /// Names of the people who reacted final List people; Map toJson() => { 'emoji': emoji, 'count': count, 'mine': mine, 'people': people.map((e) => e).toList(), }; } class Template { const Template({ required this.id, required this.title, required this.icon, required this.space, required this.spaceName, }); factory Template.fromJson(Map json) => Template( id: json['id'] as String, title: json['title'] as String, icon: json['icon'] as String, space: json['space'] as String, spaceName: json['spaceName'] as String, ); final String id; final String title; final String icon; final String space; final String spaceName; Map toJson() => { 'id': id, 'title': title, 'icon': icon, 'space': space, 'spaceName': spaceName, }; } class WatchState { const WatchState({required this.watching}); factory WatchState.fromJson(Map json) => WatchState(watching: json['watching'] as bool); final bool watching; Map toJson() => {'watching': watching}; } /// The join_* types are about a workspace and have no page; verify_expired tells the person who verified a page that it ran out enum NotificationType { comment('comment'), reply('reply'), mention('mention'), share('share'), resolved('resolved'), reminder('reminder'), joinRequest('join_request'), joinApproved('join_approved'), joinDeclined('join_declined'), verifyExpired('verify_expired'); const NotificationType(this.value); final String value; static NotificationType fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown NotificationType', value), ); String toJson() => value; } class Notification { const Notification({ required this.id, required this.type, required this.workspace, required this.page, required this.comment, required this.actor, required this.excerpt, required this.created, required this.read, }); factory Notification.fromJson(Map json) => Notification( id: json['id'] as String, type: NotificationType.fromJson(json['type'] as String), workspace: json['workspace'] as String, page: json['page'] == null ? null : PageRef.fromJson(json['page'] as Map), comment: json['comment'] as String, actor: json['actor'] == null ? null : MemberUser.fromJson(json['actor'] as Map), excerpt: json['excerpt'] as String, created: json['created'] as String, read: json['read'] as bool, ); final String id; final NotificationType type; final String workspace; /// Null when the page is gone or the caller lost access to it final PageRef? page; /// The comment it is about final String comment; final MemberUser? actor; final String excerpt; final String created; final bool read; Map toJson() => { 'id': id, 'type': type.toJson(), 'workspace': workspace, 'page': page?.toJson(), 'comment': comment, 'actor': actor?.toJson(), 'excerpt': excerpt, 'created': created, 'read': read, }; } class NotificationList { const NotificationList({required this.items, required this.unread}); factory NotificationList.fromJson(Map json) => NotificationList( items: (json['items'] as List) .map((e) => Notification.fromJson(e as Map)) .toList(), unread: (json['unread'] as num).toInt(), ); final List items; final int unread; Map toJson() => { 'items': items.map((e) => e.toJson()).toList(), 'unread': unread, }; } /// Unread notifications by email every few minutes enum NotificationSettingsEmail { digest('digest'), off('off'); const NotificationSettingsEmail(this.value); final String value; static NotificationSettingsEmail fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown NotificationSettingsEmail', value), ); String toJson() => value; } class NotificationSettings { const NotificationSettings({required this.email, this.emailTypes}); factory NotificationSettings.fromJson(Map json) => NotificationSettings( email: NotificationSettingsEmail.fromJson(json['email'] as String), emailTypes: json['emailTypes'] == null ? null : (json['emailTypes'] as List) .map((e) => NotificationType.fromJson(e as String)) .toList(), ); /// Unread notifications by email every few minutes final NotificationSettingsEmail email; /// The notification types the email digest includes (the others only reach the inbox). Always sent back; leave it out when saving to keep it as it is. final List? emailTypes; Map toJson() => { 'email': email.toJson(), 'emailTypes': ?emailTypes?.map((e) => e.toJson()).toList(), }; } enum AdminStatsScope { instance('instance'), organization('organization'); const AdminStatsScope(this.value); final String value; static AdminStatsScope fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown AdminStatsScope', value), ); String toJson() => value; } class AdminStats { const AdminStats({ required this.scope, required this.users, required this.organizations, required this.workspaces, required this.spaces, required this.pages, required this.attachments, required this.storageBytes, required this.rooms, required this.editors, required this.indexed, }); factory AdminStats.fromJson(Map json) => AdminStats( scope: AdminStatsScope.fromJson(json['scope'] as String), users: (json['users'] as num).toInt(), organizations: (json['organizations'] as num).toInt(), workspaces: (json['workspaces'] as num).toInt(), spaces: (json['spaces'] as num).toInt(), pages: (json['pages'] as num).toInt(), attachments: (json['attachments'] as num).toInt(), storageBytes: (json['storageBytes'] as num).toInt(), rooms: (json['rooms'] as num).toInt(), editors: (json['editors'] as num).toInt(), indexed: (json['indexed'] as num).toInt(), ); final AdminStatsScope scope; final int users; final int organizations; final int workspaces; final int spaces; /// Pages outside the trash final int pages; final int attachments; /// Total size of attachments final int storageBytes; /// Pages open for editing now (instance scope only) final int rooms; /// People connected to those pages (instance scope only) final int editors; /// Pages in the search index (instance scope only) final int indexed; Map toJson() => { 'scope': scope.toJson(), 'users': users, 'organizations': organizations, 'workspaces': workspaces, 'spaces': spaces, 'pages': pages, 'attachments': attachments, 'storageBytes': storageBytes, 'rooms': rooms, 'editors': editors, 'indexed': indexed, }; } class AdminHealthDatabase { const AdminHealthDatabase({ required this.ok, required this.latencyMs, this.error, }); factory AdminHealthDatabase.fromJson(Map json) => AdminHealthDatabase( ok: json['ok'] as bool, latencyMs: (json['latencyMs'] as num).toInt(), error: json['error'] == null ? null : json['error'] as String, ); final bool ok; final int latencyMs; final String? error; Map toJson() => { 'ok': ok, 'latencyMs': latencyMs, 'error': ?error, }; } class AdminHealth { const AdminHealth({ required this.version, required this.goVersion, required this.started, required this.uptimeSeconds, required this.database, required this.goroutines, required this.memoryMb, }); factory AdminHealth.fromJson(Map json) => AdminHealth( version: json['version'] as String, goVersion: json['goVersion'] as String, started: json['started'] as String, uptimeSeconds: (json['uptimeSeconds'] as num).toInt(), database: AdminHealthDatabase.fromJson( json['database'] as Map, ), goroutines: (json['goroutines'] as num).toInt(), memoryMb: (json['memoryMb'] as num).toInt(), ); final String version; final String goVersion; final String started; final int uptimeSeconds; final AdminHealthDatabase database; final int goroutines; final int memoryMb; Map toJson() => { 'version': version, 'goVersion': goVersion, 'started': started, 'uptimeSeconds': uptimeSeconds, 'database': database.toJson(), 'goroutines': goroutines, 'memoryMb': memoryMb, }; } class Job { const Job({ required this.name, required this.description, required this.every, required this.runnable, required this.running, required this.runs, required this.failures, required this.lastStarted, required this.lastDurationMs, required this.lastError, }); factory Job.fromJson(Map json) => Job( name: json['name'] as String, description: json['description'] as String, every: json['every'] as String, runnable: json['runnable'] as bool, running: json['running'] as bool, runs: (json['runs'] as num).toInt(), failures: (json['failures'] as num).toInt(), lastStarted: json['lastStarted'] as String, lastDurationMs: (json['lastDurationMs'] as num).toInt(), lastError: json['lastError'] as String, ); final String name; final String description; /// How often it runs on its own (Go duration); empty when only on demand final String every; /// Can be started by hand final bool runnable; final bool running; /// Runs since the server started final int runs; final int failures; /// RFC 3339; empty before the first run final String lastStarted; final int lastDurationMs; final String lastError; Map toJson() => { 'name': name, 'description': description, 'every': every, 'runnable': runnable, 'running': running, 'runs': runs, 'failures': failures, 'lastStarted': lastStarted, 'lastDurationMs': lastDurationMs, 'lastError': lastError, }; } class Backup { const Backup({required this.key, required this.size, required this.modified}); factory Backup.fromJson(Map json) => Backup( key: json['key'] as String, size: (json['size'] as num).toInt(), modified: json['modified'] as String, ); final String key; final int size; final String modified; Map toJson() => { 'key': key, 'size': size, 'modified': modified, }; } /// What a value looks like: text and link a string, number a number, checkbox a boolean, date "YYYY-MM-DD", select an option id, multi_select a list of option ids, member a list of user ids. enum PropertyType { text('text'), number('number'), checkbox('checkbox'), date('date'), select('select'), multiSelect('multi_select'), member('member'), link('link'); const PropertyType(this.value); final String value; static PropertyType fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown PropertyType', value), ); String toJson() => value; } class Integrations { const Integrations({ required this.google, required this.microsoft, required this.readwise, }); factory Integrations.fromJson(Map json) => Integrations( google: json['google'] as bool, microsoft: json['microsoft'] as bool, readwise: json['readwise'] as bool, ); /// People can connect Google Calendar final bool google; /// People can import OneNote notebooks final bool microsoft; final bool readwise; Map toJson() => { 'google': google, 'microsoft': microsoft, 'readwise': readwise, }; } class ConnectURL { const ConnectURL({required this.url}); factory ConnectURL.fromJson(Map json) => ConnectURL(url: json['url'] as String); /// Where to send the browser final String url; Map toJson() => {'url': url}; } class OneNoteNotebook { const OneNoteNotebook({ required this.id, required this.name, required this.modified, }); factory OneNoteNotebook.fromJson(Map json) => OneNoteNotebook( id: json['id'] as String, name: json['name'] as String, modified: json['modified'] as String, ); final String id; final String name; final String modified; Map toJson() => { 'id': id, 'name': name, 'modified': modified, }; } class OneNoteConnection { const OneNoteConnection({required this.account, required this.notebooks}); factory OneNoteConnection.fromJson(Map json) => OneNoteConnection( account: json['account'] as String, notebooks: (json['notebooks'] as List) .map((e) => OneNoteNotebook.fromJson(e as Map)) .toList(), ); /// The Microsoft account signed in final String account; final List notebooks; Map toJson() => { 'account': account, 'notebooks': notebooks.map((e) => e.toJson()).toList(), }; } enum OneNoteJobStatus { running('running'), done('done'), failed('failed'); const OneNoteJobStatus(this.value); final String value; static OneNoteJobStatus fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown OneNoteJobStatus', value), ); String toJson() => value; } class OneNoteJob { const OneNoteJob({ required this.id, required this.notebook, required this.status, required this.pages, required this.error, required this.created, }); factory OneNoteJob.fromJson(Map json) => OneNoteJob( id: json['id'] as String, notebook: json['notebook'] as String, status: OneNoteJobStatus.fromJson(json['status'] as String), pages: (json['pages'] as num).toInt(), error: json['error'] as String, created: (json['created'] as List) .map((e) => Page.fromJson(e as Map)) .toList(), ); final String id; final String notebook; final OneNoteJobStatus status; /// OneNote pages read so far final int pages; final String error; /// The pages made at the top final List created; Map toJson() => { 'id': id, 'notebook': notebook, 'status': status.toJson(), 'pages': pages, 'error': error, 'created': created.map((e) => e.toJson()).toList(), }; } class ReadwiseConnection { const ReadwiseConnection({ required this.connected, required this.workspace, required this.space, required this.parent, required this.enabled, required this.lastSync, required this.lastError, required this.highlights, required this.books, }); factory ReadwiseConnection.fromJson(Map json) => ReadwiseConnection( connected: json['connected'] as bool, workspace: json['workspace'] as String, space: json['space'] as String, parent: json['parent'] as String, enabled: json['enabled'] as bool, lastSync: json['lastSync'] as String, lastError: json['lastError'] as String, highlights: (json['highlights'] as num).toInt(), books: (json['books'] as num).toInt(), ); final bool connected; final String workspace; final String space; /// The "Readwise" page books go under final String parent; final bool enabled; final String lastSync; final String lastError; final int highlights; final int books; Map toJson() => { 'connected': connected, 'workspace': workspace, 'space': space, 'parent': parent, 'enabled': enabled, 'lastSync': lastSync, 'lastError': lastError, 'highlights': highlights, 'books': books, }; } class ReadwiseInput { const ReadwiseInput({this.token, this.space, this.enabled}); factory ReadwiseInput.fromJson(Map json) => ReadwiseInput( token: json['token'] == null ? null : json['token'] as String, space: json['space'] == null ? null : json['space'] as String, enabled: json['enabled'] == null ? null : json['enabled'] as bool, ); /// Empty keeps the stored one final String? token; final String? space; final bool? enabled; Map toJson() => { 'token': ?token, 'space': ?space, 'enabled': ?enabled, }; } /// google accounts are connected with /calendars/google/connect enum CalendarAccountKind { ics('ics'), caldav('caldav'), google('google'); const CalendarAccountKind(this.value); final String value; static CalendarAccountKind fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown CalendarAccountKind', value), ); String toJson() => value; } class CalendarAccount { const CalendarAccount({ required this.id, required this.name, required this.kind, required this.url, required this.username, required this.hasPassword, required this.color, required this.enabled, required this.lastSync, required this.lastError, required this.events, required this.created, }); factory CalendarAccount.fromJson(Map json) => CalendarAccount( id: json['id'] as String, name: json['name'] as String, kind: CalendarAccountKind.fromJson(json['kind'] as String), url: json['url'] as String, username: json['username'] as String, hasPassword: json['hasPassword'] as bool, color: LabelColor.fromJson(json['color'] as String), enabled: json['enabled'] as bool, lastSync: json['lastSync'] as String, lastError: json['lastError'] as String, events: (json['events'] as num).toInt(), created: json['created'] as String, ); final String id; final String name; /// google accounts are connected with /calendars/google/connect final CalendarAccountKind kind; final String url; final String username; final bool hasPassword; final LabelColor color; /// Whether its events show on journal pages final bool enabled; /// When the source was last read final String lastSync; /// Why the last read failed; empty when it worked final String lastError; /// Events the source held then (repeating ones once) final int events; final String created; Map toJson() => { 'id': id, 'name': name, 'kind': kind.toJson(), 'url': url, 'username': username, 'hasPassword': hasPassword, 'color': color.toJson(), 'enabled': enabled, 'lastSync': lastSync, 'lastError': lastError, 'events': events, 'created': created, }; } enum CalendarAccountInputKind { ics('ics'), caldav('caldav'); const CalendarAccountInputKind(this.value); final String value; static CalendarAccountInputKind fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown CalendarAccountInputKind', value), ); String toJson() => value; } class CalendarAccountInput { const CalendarAccountInput({ this.name, this.kind, this.url, this.username, this.password, this.clearPassword, this.color, this.enabled, }); factory CalendarAccountInput.fromJson(Map json) => CalendarAccountInput( name: json['name'] == null ? null : json['name'] as String, kind: json['kind'] == null ? null : CalendarAccountInputKind.fromJson(json['kind'] as String), url: json['url'] == null ? null : json['url'] as String, username: json['username'] == null ? null : json['username'] as String, password: json['password'] == null ? null : json['password'] as String, clearPassword: json['clearPassword'] == null ? null : json['clearPassword'] as bool, color: json['color'] == null ? null : LabelColor.fromJson(json['color'] as String), enabled: json['enabled'] == null ? null : json['enabled'] as bool, ); final String? name; final CalendarAccountInputKind? kind; /// http, https or webcal address final String? url; final String? username; /// Empty keeps the stored one final String? password; final bool? clearPassword; final LabelColor? color; final bool? enabled; Map toJson() => { 'name': ?name, 'kind': ?kind?.toJson(), 'url': ?url, 'username': ?username, 'password': ?password, 'clearPassword': ?clearPassword, 'color': ?color?.toJson(), 'enabled': ?enabled, }; } class CalendarEvent { const CalendarEvent({ required this.id, required this.calendar, required this.title, required this.location, required this.url, required this.start, required this.end, required this.allDay, required this.color, }); factory CalendarEvent.fromJson(Map json) => CalendarEvent( id: json['id'] as String, calendar: json['calendar'] as String, title: json['title'] as String, location: json['location'] as String, url: json['url'] as String, start: json['start'] as String, end: json['end'] as String, allDay: json['allDay'] as bool, color: LabelColor.fromJson(json['color'] as String), ); final String id; /// The calendar account's id final String calendar; final String title; final String location; final String url; /// RFC 3339 time, or a date (YYYY-MM-DD) for all-day events final String start; /// Exclusive; a date for all-day events final String end; final bool allDay; final LabelColor color; Map toJson() => { 'id': id, 'calendar': calendar, 'title': title, 'location': location, 'url': url, 'start': start, 'end': end, 'allDay': allDay, 'color': color.toJson(), }; } /// A colour of the editor palette, drawn from the theme; empty for none enum LabelColor { none(''), gray('gray'), red('red'), orange('orange'), yellow('yellow'), green('green'), teal('teal'), blue('blue'), purple('purple'), pink('pink'); const LabelColor(this.value); final String value; static LabelColor fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown LabelColor', value), ); String toJson() => value; } class PropertyOption { const PropertyOption({ required this.id, required this.name, required this.color, }); factory PropertyOption.fromJson(Map json) => PropertyOption( id: json['id'] as String, name: json['name'] as String, color: LabelColor.fromJson(json['color'] as String), ); /// Empty when creating; the server picks one final String id; final String name; final LabelColor color; Map toJson() => { 'id': id, 'name': name, 'color': color.toJson(), }; } /// Whether the page's Info panel shows it always, only with a value, or never enum PropertyVisibility { always('always'), hideEmpty('hide_empty'), never('never'); const PropertyVisibility(this.value); final String value; static PropertyVisibility fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown PropertyVisibility', value), ); String toJson() => value; } class Property { const Property({ required this.id, required this.workspace, required this.name, required this.type, required this.options, required this.visibility, required this.position, }); factory Property.fromJson(Map json) => Property( id: json['id'] as String, workspace: json['workspace'] as String, name: json['name'] as String, type: PropertyType.fromJson(json['type'] as String), options: (json['options'] as List) .map((e) => PropertyOption.fromJson(e as Map)) .toList(), visibility: PropertyVisibility.fromJson(json['visibility'] as String), position: (json['position'] as num).toDouble(), ); final String id; final String workspace; final String name; final PropertyType type; final List options; final PropertyVisibility visibility; final double position; Map toJson() => { 'id': id, 'workspace': workspace, 'name': name, 'type': type.toJson(), 'options': options.map((e) => e.toJson()).toList(), 'visibility': visibility.toJson(), 'position': position, }; } /// Creating needs name and type; updating changes the fields that are set class PropertyInput { const PropertyInput({ this.name, this.type, this.options, this.visibility, this.position, }); factory PropertyInput.fromJson(Map json) => PropertyInput( name: json['name'] == null ? null : json['name'] as String, type: json['type'] == null ? null : PropertyType.fromJson(json['type'] as String), options: json['options'] == null ? null : (json['options'] as List) .map((e) => PropertyOption.fromJson(e as Map)) .toList(), visibility: json['visibility'] == null ? null : PropertyVisibility.fromJson(json['visibility'] as String), position: json['position'] == null ? null : (json['position'] as num).toDouble(), ); final String? name; final PropertyType? type; final List? options; final PropertyVisibility? visibility; final double? position; Map toJson() => { 'name': ?name, 'type': ?type?.toJson(), 'options': ?options?.map((e) => e.toJson()).toList(), 'visibility': ?visibility?.toJson(), 'position': ?position, }; } class Tag { const Tag({ required this.id, required this.name, required this.color, required this.pages, }); factory Tag.fromJson(Map json) => Tag( id: json['id'] as String, name: json['name'] as String, color: LabelColor.fromJson(json['color'] as String), pages: (json['pages'] as num).toInt(), ); final String id; final String name; final LabelColor color; /// Live pages with the tag final int pages; Map toJson() => { 'id': id, 'name': name, 'color': color.toJson(), 'pages': pages, }; } class TagInput { const TagInput({this.name, this.color}); factory TagInput.fromJson(Map json) => TagInput( name: json['name'] == null ? null : json['name'] as String, color: json['color'] == null ? null : LabelColor.fromJson(json['color'] as String), ); final String? name; final LabelColor? color; Map toJson() => {'name': ?name, 'color': ?color?.toJson()}; } enum DocRuleOp { is_('is'), isNot('isNot'), contains('contains'), notContains('notContains'), before('before'), after('after'), withinDays('withinDays'), gt('gt'), lt('lt'), empty('empty'), notEmpty('notEmpty'); const DocRuleOp(this.value); final String value; static DocRuleOp fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown DocRuleOp', value), ); String toJson() => value; } class DocRule { const DocRule({required this.field, required this.op, this.value}); factory DocRule.fromJson(Map json) => DocRule( field: json['field'] as String, op: DocRuleOp.fromJson(json['op'] as String), value: json['value'] == null ? null : json['value'] as Object, ); /// title, space, tags, created, updated, createdBy, lastEditedBy, template, journal, or "prop:" followed by a property id final String field; final DocRuleOp op; /// A string, a list of strings (any of them), a number or a boolean, as the op needs final Object? value; Map toJson() => { 'field': field, 'op': op.toJson(), 'value': ?value, }; } enum DocFilterMatch { all('all'), any('any'); const DocFilterMatch(this.value); final String value; static DocFilterMatch fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown DocFilterMatch', value), ); String toJson() => value; } class DocFilter { const DocFilter({required this.match, required this.rules}); factory DocFilter.fromJson(Map json) => DocFilter( match: DocFilterMatch.fromJson(json['match'] as String), rules: (json['rules'] as List) .map((e) => DocRule.fromJson(e as Map)) .toList(), ); final DocFilterMatch match; final List rules; Map toJson() => { 'match': match.toJson(), 'rules': rules.map((e) => e.toJson()).toList(), }; } class DocItem { const DocItem({ required this.id, required this.title, required this.icon, required this.space, required this.spaceName, required this.parent, required this.created, required this.updated, required this.createdBy, required this.lastEditedBy, required this.isTemplate, required this.journalDate, required this.fullWidth, required this.tags, required this.properties, required this.role, }); factory DocItem.fromJson(Map json) => DocItem( id: json['id'] as String, title: json['title'] as String, icon: json['icon'] as String, space: json['space'] as String, spaceName: json['spaceName'] as String, parent: json['parent'] as String, created: json['created'] as String, updated: json['updated'] as String, createdBy: json['createdBy'] as String, lastEditedBy: json['lastEditedBy'] as String, isTemplate: json['isTemplate'] as bool, journalDate: json['journalDate'] as String, fullWidth: json['fullWidth'] as bool, tags: (json['tags'] as List).map((e) => e as String).toList(), properties: json['properties'] as Map, role: SpaceRole.fromJson(json['role'] as String), ); final String id; final String title; final String icon; final String space; final String spaceName; final String parent; final String created; final String updated; /// User id final String createdBy; /// User id final String lastEditedBy; final bool isTemplate; final String journalDate; final bool fullWidth; final List tags; final Map properties; /// The caller's role on the page final SpaceRole role; Map toJson() => { 'id': id, 'title': title, 'icon': icon, 'space': space, 'spaceName': spaceName, 'parent': parent, 'created': created, 'updated': updated, 'createdBy': createdBy, 'lastEditedBy': lastEditedBy, 'isTemplate': isTemplate, 'journalDate': journalDate, 'fullWidth': fullWidth, 'tags': tags.map((e) => e).toList(), 'properties': properties, 'role': role.toJson(), }; } class DocList { const DocList({required this.items, required this.people}); factory DocList.fromJson(Map json) => DocList( items: (json['items'] as List) .map((e) => DocItem.fromJson(e as Map)) .toList(), people: (json['people'] as Map).map( (k, e) => MapEntry(k, e as String), ), ); final List items; /// Names of the people the items mention, by user id final Map people; Map toJson() => { 'items': items.map((e) => e.toJson()).toList(), 'people': people, }; } class Collection { const Collection({ required this.id, required this.workspace, required this.name, required this.icon, required this.filter, required this.include, required this.exclude, required this.shared, required this.creator, required this.canEdit, required this.updated, }); factory Collection.fromJson(Map json) => Collection( id: json['id'] as String, workspace: json['workspace'] as String, name: json['name'] as String, icon: json['icon'] as String, filter: DocFilter.fromJson(json['filter'] as Map), include: (json['include'] as List).map((e) => e as String).toList(), exclude: (json['exclude'] as List).map((e) => e as String).toList(), shared: json['shared'] as bool, creator: json['creator'] as String, canEdit: json['canEdit'] as bool, updated: json['updated'] as String, ); final String id; final String workspace; final String name; final String icon; final DocFilter filter; /// Pages added by hand final List include; /// Pages taken out by hand final List exclude; /// Seen by everyone in the workspace final bool shared; final String creator; final bool canEdit; final String updated; Map toJson() => { 'id': id, 'workspace': workspace, 'name': name, 'icon': icon, 'filter': filter.toJson(), 'include': include.map((e) => e).toList(), 'exclude': exclude.map((e) => e).toList(), 'shared': shared, 'creator': creator, 'canEdit': canEdit, 'updated': updated, }; } /// Creating needs name; updating changes the fields that are set class CollectionInput { const CollectionInput({ this.name, this.icon, this.filter, this.include, this.exclude, this.shared, }); factory CollectionInput.fromJson(Map json) => CollectionInput( name: json['name'] == null ? null : json['name'] as String, icon: json['icon'] == null ? null : json['icon'] as String, filter: json['filter'] == null ? null : DocFilter.fromJson(json['filter'] as Map), include: json['include'] == null ? null : (json['include'] as List).map((e) => e as String).toList(), exclude: json['exclude'] == null ? null : (json['exclude'] as List).map((e) => e as String).toList(), shared: json['shared'] == null ? null : json['shared'] as bool, ); final String? name; final String? icon; final DocFilter? filter; final List? include; final List? exclude; final bool? shared; Map toJson() => { 'name': ?name, 'icon': ?icon, 'filter': ?filter?.toJson(), 'include': ?include?.map((e) => e).toList(), 'exclude': ?exclude?.map((e) => e).toList(), 'shared': ?shared, }; } class JournalDay { const JournalDay({ required this.date, required this.page, required this.title, }); factory JournalDay.fromJson(Map json) => JournalDay( date: json['date'] as String, page: json['page'] as String, title: json['title'] as String, ); final String date; final String page; final String title; Map toJson() => {'date': date, 'page': page, 'title': title}; } class JournalInfo { const JournalInfo({ required this.space, required this.template, required this.days, }); factory JournalInfo.fromJson(Map json) => JournalInfo( space: json['space'] as String, template: json['template'] as String, days: (json['days'] as List) .map((e) => JournalDay.fromJson(e as Map)) .toList(), ); /// The caller's journal space; empty until the first journal page final String space; /// The page new journal pages are filled from; empty for none final String template; final List days; Map toJson() => { 'space': space, 'template': template, 'days': days.map((e) => e.toJson()).toList(), }; } class PageUser { const PageUser({required this.id, required this.name}); factory PageUser.fromJson(Map json) => PageUser(id: json['id'] as String, name: json['name'] as String); final String id; /// Empty when the account is gone final String name; Map toJson() => {'id': id, 'name': name}; } class IdList { const IdList({required this.ids}); factory IdList.fromJson(Map json) => IdList(ids: (json['ids'] as List).map((e) => e as String).toList()); final List ids; Map toJson() => {'ids': ids.map((e) => e).toList()}; } class AiAvailability { const AiAvailability({ required this.chat, required this.embeddings, required this.transcribe, required this.canManage, }); factory AiAvailability.fromJson(Map json) => AiAvailability( chat: json['chat'] as bool, embeddings: json['embeddings'] as bool, transcribe: json['transcribe'] as bool, canManage: json['canManage'] as bool, ); /// A profile with a chat model is set up and AI is on final bool chat; /// The workspace is indexed for retrieval final bool embeddings; /// A profile can turn audio attachments into text final bool transcribe; /// The caller may change the workspace's AI settings final bool canManage; Map toJson() => { 'chat': chat, 'embeddings': embeddings, 'transcribe': transcribe, 'canManage': canManage, }; } class AiSettings { const AiSettings({ required this.enabled, required this.useInstanceProfiles, required this.index, required this.ignored, required this.monthlyTokenLimit, required this.readScans, }); factory AiSettings.fromJson(Map json) => AiSettings( enabled: json['enabled'] as bool, useInstanceProfiles: json['useInstanceProfiles'] as bool, index: json['index'] as bool, ignored: (json['ignored'] as List).map((e) => e as String).toList(), monthlyTokenLimit: (json['monthlyTokenLimit'] as num).toInt(), readScans: json['readScans'] as bool, ); final bool enabled; /// After its own profiles final bool useInstanceProfiles; /// Embed pages for retrieval (sends every page to the embedding provider) final bool index; /// Pages (with their subpages) that are neither indexed nor retrieved final List ignored; /// Tokens the workspace may use per month; 0 is no cap final int monthlyTokenLimit; /// Have a document-reading model write out scanned PDFs attached to pages final bool readScans; Map toJson() => { 'enabled': enabled, 'useInstanceProfiles': useInstanceProfiles, 'index': index, 'ignored': ignored.map((e) => e).toList(), 'monthlyTokenLimit': monthlyTokenLimit, 'readScans': readScans, }; } /// openai is any OpenAI-compatible API enum AiProviderKind { openai('openai'), anthropic('anthropic'), ollama('ollama'); const AiProviderKind(this.value); final String value; static AiProviderKind fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown AiProviderKind', value), ); String toJson() => value; } class AiProfileUsage { const AiProfileUsage({ required this.requests, required this.inputTokens, required this.outputTokens, }); factory AiProfileUsage.fromJson(Map json) => AiProfileUsage( requests: (json['requests'] as num).toInt(), inputTokens: (json['inputTokens'] as num).toInt(), outputTokens: (json['outputTokens'] as num).toInt(), ); final int requests; final int inputTokens; final int outputTokens; Map toJson() => { 'requests': requests, 'inputTokens': inputTokens, 'outputTokens': outputTokens, }; } class AiProfile { const AiProfile({ required this.id, required this.workspace, required this.name, required this.kind, required this.baseUrl, required this.keySet, required this.chatModel, required this.embedModel, required this.transcribeModel, required this.effort, required this.enabled, required this.position, required this.usage, required this.lastUsed, required this.lastError, required this.created, }); factory AiProfile.fromJson(Map json) => AiProfile( id: json['id'] as String, workspace: json['workspace'] as String, name: json['name'] as String, kind: AiProviderKind.fromJson(json['kind'] as String), baseUrl: json['baseUrl'] as String, keySet: json['keySet'] as bool, chatModel: json['chatModel'] as String, embedModel: json['embedModel'] as String, transcribeModel: json['transcribeModel'] as String, effort: json['effort'] as String, enabled: json['enabled'] as bool, position: (json['position'] as num).toInt(), usage: AiProfileUsage.fromJson(json['usage'] as Map), lastUsed: json['lastUsed'] as String, lastError: json['lastError'] as String, created: json['created'] as String, ); final String id; /// Empty for an instance default final String workspace; final String name; final AiProviderKind kind; /// Empty for the kind's default address final String baseUrl; /// An API key is stored (keys are never returned) final bool keySet; final String chatModel; /// Empty when the profile is not used for embeddings final String embedModel; /// Speech-to-text model (OpenAI-compatible); empty when unused final String transcribeModel; /// Anthropic effort level final String effort; final bool enabled; final int position; final AiProfileUsage usage; final String lastUsed; final String lastError; final String created; Map toJson() => { 'id': id, 'workspace': workspace, 'name': name, 'kind': kind.toJson(), 'baseUrl': baseUrl, 'keySet': keySet, 'chatModel': chatModel, 'embedModel': embedModel, 'transcribeModel': transcribeModel, 'effort': effort, 'enabled': enabled, 'position': position, 'usage': usage.toJson(), 'lastUsed': lastUsed, 'lastError': lastError, 'created': created, }; } enum AiProfileInputEffort { none(''), low('low'), medium('medium'), high('high'), xhigh('xhigh'), max('max'); const AiProfileInputEffort(this.value); final String value; static AiProfileInputEffort fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown AiProfileInputEffort', value), ); String toJson() => value; } /// Creating needs name and kind; updating changes the fields that are set class AiProfileInput { const AiProfileInput({ this.name, this.kind, this.baseUrl, this.apiKey, this.chatModel, this.embedModel, this.transcribeModel, this.effort, this.enabled, }); factory AiProfileInput.fromJson(Map json) => AiProfileInput( name: json['name'] == null ? null : json['name'] as String, kind: json['kind'] == null ? null : AiProviderKind.fromJson(json['kind'] as String), baseUrl: json['baseUrl'] == null ? null : json['baseUrl'] as String, apiKey: json['apiKey'] == null ? null : json['apiKey'] as String, chatModel: json['chatModel'] == null ? null : json['chatModel'] as String, embedModel: json['embedModel'] == null ? null : json['embedModel'] as String, transcribeModel: json['transcribeModel'] == null ? null : json['transcribeModel'] as String, effort: json['effort'] == null ? null : AiProfileInputEffort.fromJson(json['effort'] as String), enabled: json['enabled'] == null ? null : json['enabled'] as bool, ); final String? name; final AiProviderKind? kind; final String? baseUrl; /// Write-only; an empty string removes the key final String? apiKey; final String? chatModel; final String? embedModel; final String? transcribeModel; final AiProfileInputEffort? effort; final bool? enabled; Map toJson() => { 'name': ?name, 'kind': ?kind?.toJson(), 'baseUrl': ?baseUrl, 'apiKey': ?apiKey, 'chatModel': ?chatModel, 'embedModel': ?embedModel, 'transcribeModel': ?transcribeModel, 'effort': ?effort?.toJson(), 'enabled': ?enabled, }; } class AiTestResult { const AiTestResult({ required this.ok, required this.chat, required this.embeddings, required this.dimensions, required this.latencyMs, required this.error, }); factory AiTestResult.fromJson(Map json) => AiTestResult( ok: json['ok'] as bool, chat: json['chat'] as String, embeddings: json['embeddings'] as String, dimensions: (json['dimensions'] as num).toInt(), latencyMs: (json['latencyMs'] as num).toInt(), error: json['error'] as String, ); final bool ok; /// The model's reply final String chat; final String embeddings; final int dimensions; final int latencyMs; final String error; Map toJson() => { 'ok': ok, 'chat': chat, 'embeddings': embeddings, 'dimensions': dimensions, 'latencyMs': latencyMs, 'error': error, }; } class AiIndexStatus { const AiIndexStatus({ required this.enabled, required this.profile, required this.model, required this.pages, required this.indexed, required this.files, required this.chunks, required this.running, required this.lastRun, required this.lastError, }); factory AiIndexStatus.fromJson(Map json) => AiIndexStatus( enabled: json['enabled'] as bool, profile: json['profile'] as String, model: json['model'] as String, pages: (json['pages'] as num).toInt(), indexed: (json['indexed'] as num).toInt(), files: (json['files'] as num).toInt(), chunks: (json['chunks'] as num).toInt(), running: json['running'] as bool, lastRun: json['lastRun'] as String, lastError: json['lastError'] as String, ); final bool enabled; /// The profile vectors come from; empty when none has an embedding model final String profile; final String model; /// Pages that can be indexed final int pages; final int indexed; final int files; final int chunks; final bool running; final String lastRun; final String lastError; Map toJson() => { 'enabled': enabled, 'profile': profile, 'model': model, 'pages': pages, 'indexed': indexed, 'files': files, 'chunks': chunks, 'running': running, 'lastRun': lastRun, 'lastError': lastError, }; } class AiFile { const AiFile({ required this.id, required this.name, required this.size, required this.chars, required this.indexed, required this.created, }); factory AiFile.fromJson(Map json) => AiFile( id: json['id'] as String, name: json['name'] as String, size: (json['size'] as num).toInt(), chars: (json['chars'] as num).toInt(), indexed: json['indexed'] as bool, created: json['created'] as String, ); final String id; final String name; final int size; final int chars; final bool indexed; final String created; Map toJson() => { 'id': id, 'name': name, 'size': size, 'chars': chars, 'indexed': indexed, 'created': created, }; } enum AiScope { workspace('workspace'), space('space'), page('page'); const AiScope(this.value); final String value; static AiScope fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown AiScope', value), ); String toJson() => value; } class AiSessionSummary { const AiSessionSummary({ required this.id, required this.title, required this.scope, required this.scopeId, required this.created, required this.updated, }); factory AiSessionSummary.fromJson(Map json) => AiSessionSummary( id: json['id'] as String, title: json['title'] as String, scope: AiScope.fromJson(json['scope'] as String), scopeId: json['scopeId'] as String, created: json['created'] as String, updated: json['updated'] as String, ); final String id; final String title; final AiScope scope; /// The space or page; empty for the workspace final String scopeId; final String created; final String updated; Map toJson() => { 'id': id, 'title': title, 'scope': scope.toJson(), 'scopeId': scopeId, 'created': created, 'updated': updated, }; } class AiCitation { const AiCitation({ required this.n, this.page, this.block, this.file, required this.title, required this.snippet, }); factory AiCitation.fromJson(Map json) => AiCitation( n: (json['n'] as num).toInt(), page: json['page'] == null ? null : json['page'] as String, block: json['block'] == null ? null : json['block'] as String, file: json['file'] == null ? null : json['file'] as String, title: json['title'] as String, snippet: json['snippet'] as String, ); /// The number the answer cites as [n] final int n; final String? page; /// The cited block (link with #b-``) final String? block; /// An extra file instead of a page final String? file; final String title; final String snippet; Map toJson() => { 'n': n, 'page': ?page, 'block': ?block, 'file': ?file, 'title': title, 'snippet': snippet, }; } enum AiMessageRole { user('user'), assistant('assistant'); const AiMessageRole(this.value); final String value; static AiMessageRole fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown AiMessageRole', value), ); String toJson() => value; } class AiMessage { const AiMessage({ required this.id, required this.role, required this.content, this.citations, this.error, required this.created, }); factory AiMessage.fromJson(Map json) => AiMessage( id: json['id'] as String, role: AiMessageRole.fromJson(json['role'] as String), content: json['content'] as String, citations: json['citations'] == null ? null : (json['citations'] as List) .map((e) => AiCitation.fromJson(e as Map)) .toList(), error: json['error'] == null ? null : json['error'] as String, created: json['created'] as String, ); final String id; final AiMessageRole role; /// Markdown final String content; final List? citations; /// Why the answer stopped final String? error; final String created; Map toJson() => { 'id': id, 'role': role.toJson(), 'content': content, 'citations': ?citations?.map((e) => e.toJson()).toList(), 'error': ?error, 'created': created, }; } class AiSession { const AiSession({ required this.id, required this.title, required this.scope, required this.scopeId, required this.created, required this.updated, required this.workspace, required this.messages, }); factory AiSession.fromJson(Map json) => AiSession( id: json['id'] as String, title: json['title'] as String, scope: AiScope.fromJson(json['scope'] as String), scopeId: json['scopeId'] as String, created: json['created'] as String, updated: json['updated'] as String, workspace: json['workspace'] as String, messages: (json['messages'] as List) .map((e) => AiMessage.fromJson(e as Map)) .toList(), ); final String id; final String title; final AiScope scope; /// The space or page; empty for the workspace final String scopeId; final String created; final String updated; final String workspace; final List messages; Map toJson() => { 'id': id, 'title': title, 'scope': scope.toJson(), 'scopeId': scopeId, 'created': created, 'updated': updated, 'workspace': workspace, 'messages': messages.map((e) => e.toJson()).toList(), }; } class AiSessionInput { const AiSessionInput({this.title, this.scope, this.scopeId}); factory AiSessionInput.fromJson(Map json) => AiSessionInput( title: json['title'] == null ? null : json['title'] as String, scope: json['scope'] == null ? null : AiScope.fromJson(json['scope'] as String), scopeId: json['scopeId'] == null ? null : json['scopeId'] as String, ); final String? title; final AiScope? scope; final String? scopeId; Map toJson() => { 'title': ?title, 'scope': ?scope?.toJson(), 'scopeId': ?scopeId, }; } class AiForkInput { const AiForkInput({this.message}); factory AiForkInput.fromJson(Map json) => AiForkInput( message: json['message'] == null ? null : json['message'] as String, ); /// The last message to copy; empty copies all final String? message; Map toJson() => {'message': ?message}; } enum AiWriteAction { rewrite('rewrite'), summarize('summarize'), translate('translate'), continue_('continue'), shorter('shorter'), longer('longer'), fix('fix'), custom('custom'); const AiWriteAction(this.value); final String value; static AiWriteAction fromJson(String value) => values.firstWhere( (e) => e.value == value, orElse: () => throw FormatException('unknown AiWriteAction', value), ); String toJson() => value; } class AiWriteInput { const AiWriteInput({ required this.action, required this.text, this.before, this.language, this.instruction, }); factory AiWriteInput.fromJson(Map json) => AiWriteInput( action: AiWriteAction.fromJson(json['action'] as String), text: json['text'] as String, before: json['before'] == null ? null : json['before'] as String, language: json['language'] == null ? null : json['language'] as String, instruction: json['instruction'] == null ? null : json['instruction'] as String, ); final AiWriteAction action; /// The selection final String text; /// Text in front of the selection (continue) final String? before; /// Target language (translate) final String? language; /// What to do (custom) final String? instruction; Map toJson() => { 'action': action.toJson(), 'text': text, 'before': ?before, 'language': ?language, 'instruction': ?instruction, }; } class AiUsage { const AiUsage({ required this.workspace, this.name, required this.month, required this.requests, required this.inputTokens, required this.outputTokens, required this.instanceTokens, required this.limit, required this.instanceLimit, }); factory AiUsage.fromJson(Map json) => AiUsage( workspace: json['workspace'] as String, name: json['name'] == null ? null : json['name'] as String, month: json['month'] as String, requests: (json['requests'] as num).toInt(), inputTokens: (json['inputTokens'] as num).toInt(), outputTokens: (json['outputTokens'] as num).toInt(), instanceTokens: (json['instanceTokens'] as num).toInt(), limit: (json['limit'] as num).toInt(), instanceLimit: (json['instanceLimit'] as num).toInt(), ); final String workspace; /// The workspace's name (admin listing) final String? name; /// Calendar month in UTC, e.g. 2026-11 final String month; final int requests; final int inputTokens; final int outputTokens; /// Tokens used through the server's own profiles final int instanceTokens; /// The workspace's monthly token cap; 0 is none final int limit; /// The server's cap on instanceTokens; 0 is none final int instanceLimit; Map toJson() => { 'workspace': workspace, 'name': ?name, 'month': month, 'requests': requests, 'inputTokens': inputTokens, 'outputTokens': outputTokens, 'instanceTokens': instanceTokens, 'limit': limit, 'instanceLimit': instanceLimit, }; } class AiInstanceSettings { const AiInstanceSettings({required this.workspaceTokenLimit}); factory AiInstanceSettings.fromJson(Map json) => AiInstanceSettings( workspaceTokenLimit: (json['workspaceTokenLimit'] as num).toInt(), ); /// Tokens one workspace may use through the server's profiles per month; 0 is no cap final int workspaceTokenLimit; Map toJson() => {'workspaceTokenLimit': workspaceTokenLimit}; } class AiTranscript { const AiTranscript({ required this.name, required this.text, required this.summary, this.summaryError, }); factory AiTranscript.fromJson(Map json) => AiTranscript( name: json['name'] as String, text: json['text'] as String, summary: json['summary'] as String, summaryError: json['summaryError'] == null ? null : json['summaryError'] as String, ); final String name; final String text; /// Markdown; empty when not asked for or when it failed final String summary; final String? summaryError; Map toJson() => { 'name': name, 'text': text, 'summary': summary, 'summaryError': ?summaryError, }; }