import type { APIAnyTemplate, FulltextGatheringFn, LinkGatheringFn, Migration, ValidationFeedback } from '@dosgato/templating'; import { GQLServer, type GQLStartOpts } from '@txstate-mws/graphql-server'; import type { FastifyInstance, FastifyRequest } from 'fastify'; import { type AnalyticsClient, type FastifyTxStateOptions } from 'fastify-txstate'; import { PagetreeType, type DBMigration, type Role, type DGRestrictOperations, type EventInfo } from './internal.js'; export interface AssetMeta { validation?: (data: DataType, extras: { path: string; }) => Promise; migrations?: Migration[]; getLinks?: LinkGatheringFn; getFulltext?: FulltextGatheringFn; getHtml?: FulltextGatheringFn; } export interface DGUser { login: string; firstname: string; lastname: string; email: string; enabled?: boolean; groups?: string[]; } export interface DGStartOpts extends Omit { templates: APIAnyTemplate[]; fixtures?: () => Promise; migrations?: DBMigration[]; resolvers?: any[]; assetMeta?: AssetMeta; /** * Provide a function that can look up users in your IdM. * * Return object should be a map of input strings and results. For instance, if we are batching two * searches the input might be ['john.smith', 'jane.williams'] and the return should be * { 'john.smith': { ... John's details ... }, 'jane.williams': { ... Jane's details ... } } * * It's the responsibility of the implementation to do the work as efficiently as it can. */ userLookup?: (logins: string[]) => Promise>; /** * Provide a function that can search for users * * This will be connected to the admin UI so that you can search your IdM for users when creating * a Dos Gato user. Login, name and email will be fetched automatically instead of making the administrator * type it all out. * * If this function is not provided, userLookup will be used instead (meaning only full logins will show results). * If neither is provided, the feature will be disabled. */ userSearch?: (search: string) => Promise; /** * Provide a function to protect certain pages from being deleted, unpublished, moved, renamed, or having their template * changed. Editing and publishing are unaffected, and creating/copying/importing is possible * unless the path already exists. * * This is useful if you want to ensure that sites maintain mandatory pages like /404 or /sitemap, but you * want editors to have freedom to customize those pages. * * Return true if the given operation should be blocked. 'into' means that a page is being created * or moved underneath the page. * * Blocking an operation will mean that even a system administrator will be unable to complete the operation, so be * sure to inspect the `roles` array if you want to allow operations for superuser or other roles (by name). */ restrictPageOperation?: (page: { id: string; name: string; path: string; templateKey: string; pagetreeType: PagetreeType; }, operation: DGRestrictOperations, roles: Role[]) => boolean; /** * Provide a function to receive live events from the API. * * This is useful for setting up real-time syncing with other systems. * * This first version only includes an event for publishing a page, for real-time cache invalidation. * * Your function will be inside a try/catch so as not to interrupt regular operation. */ onEvent?: (info: EventInfo) => void | Promise; /** * The server registers fastify-txstate's analytics plugin so that the admin UI can report * user interaction events to POST /analytics. NODE_ENV must be set or startup will fail. * * By default, events go to elasticsearch when ELASTICSEARCH_URL is set, are printed to the * console in development, and are sent to the server log otherwise. Use these options to * customize that behavior. */ analytics?: { /** Identifies the reporting application in stored events. Default 'dosgato-admin'. */ appName?: string; /** Override where events are stored, e.g. to send them to a different analytics database. */ analyticsClient?: AnalyticsClient; /** Reject event submissions with a 401 when this returns false. By default, unauthenticated * requests are rejected; provide your own function, e.g. `() => true`, if you intend to * accept events from unauthenticated users like visitors to your public web pages. */ authorize?: boolean | ((req: FastifyRequest) => boolean); }; } export declare class DGServer { protected gqlServer: GQLServer; app: FastifyInstance; constructor(config?: FastifyTxStateOptions); start(opts: DGStartOpts): Promise; } export * from './internal.js';