@easy-cms/core 0.31.0 → 0.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -187,6 +187,8 @@ interface Database {
187
187
  readonly backup?: ((file: string) => Promise<void>) | undefined;
188
188
  /** Raw table access for copying a whole database to another (`easy-cms copy`). */
189
189
  readonly transfer?: DatabaseTransfer | undefined;
190
+ /** The prefix of its tables (`tablePrefix`), so a copy (a backup) can use the same. */
191
+ readonly tablePrefix?: string | undefined;
190
192
  destroy(): Promise<void>;
191
193
  }
192
194
  /**
@@ -1803,6 +1805,27 @@ type TypedPlugin<T extends PluginTypes> = Plugin & {
1803
1805
  * ```
1804
1806
  */
1805
1807
  declare function definePlugin<const T extends PluginTypes = Record<never, never>>(plugin: Plugin, info?: PluginInfo): TypedPlugin<T>;
1808
+ /** Database backups (Settings → Backups): one compressed SQLite file each. */
1809
+ interface BackupsConfig {
1810
+ /** Back up automatically every day or week. Default: only by hand. */
1811
+ readonly every?: 'day' | 'week';
1812
+ /** When, as `HH:MM` in the server's time zone. Default `03:00`. */
1813
+ readonly at?: string;
1814
+ /** How many finished backups to keep; older ones are deleted. Default 7. */
1815
+ readonly keep?: number;
1816
+ /** Folder for the default local storage, from the project root. Default `backups`. Never served publicly. */
1817
+ readonly dir?: string;
1818
+ /** Where backups are stored instead, e.g. `s3Storage()` with a private bucket. */
1819
+ readonly storage?: StorageAdapter;
1820
+ /**
1821
+ * For Postgres: the SQLite adapter that writes the backup file, `sqlite` from
1822
+ * `@easy-cms/db-sqlite`. SQLite databases back themselves up and don't need it.
1823
+ */
1824
+ readonly sqlite?: (options: {
1825
+ url: string;
1826
+ tablePrefix?: string;
1827
+ }) => DatabaseAdapter;
1828
+ }
1806
1829
  interface Config {
1807
1830
  /** Signs sessions. At least 32 characters; read it from `process.env.EASY_CMS_SECRET`. */
1808
1831
  readonly secret: string;
@@ -1858,6 +1881,11 @@ interface Config {
1858
1881
  * database and retried until sent.
1859
1882
  */
1860
1883
  readonly email?: EmailAdapter;
1884
+ /**
1885
+ * Database backups, made on a schedule and from the admin (Settings → Backups). Without
1886
+ * `every`, admins can still back up by hand.
1887
+ */
1888
+ readonly backups?: BackupsConfig;
1861
1889
  readonly plugins?: readonly Plugin[];
1862
1890
  }
1863
1891
  /** The config after plugins ran, validation passed and defaults were applied. */
@@ -1917,6 +1945,46 @@ declare function hashPassword(password: string): Promise<string>;
1917
1945
  /** Checks a password against a hash in constant time. Malformed hashes never match. */
1918
1946
  declare function verifyPassword(password: string, stored: string): Promise<boolean>;
1919
1947
 
1948
+ type BackupState = 'pending' | 'running' | 'done' | 'failed';
1949
+ /** One backup as the admin shows it (`GET <api>/admin/backups`). */
1950
+ interface AdminBackup {
1951
+ id: ID;
1952
+ state: BackupState;
1953
+ trigger: 'manual' | 'scheduled';
1954
+ /** The file's name, e.g. `my-site-2026-10-04-0300.db.gz`. */
1955
+ filename: string | null;
1956
+ /** Bytes, compressed. */
1957
+ size: number | null;
1958
+ startedAt: string | null;
1959
+ finishedAt: string | null;
1960
+ error: string | null;
1961
+ /** Who started it (manual backups). */
1962
+ author: string | null;
1963
+ downloadedBy: string | null;
1964
+ downloadedAt: string | null;
1965
+ }
1966
+ /** Settings → Backups (`GET <api>/admin/backups`). */
1967
+ interface AdminBackups {
1968
+ settings: {
1969
+ every: 'day' | 'week' | null;
1970
+ at: string;
1971
+ keep: number;
1972
+ /** The storage adapter's name, e.g. `local` or `s3`. */
1973
+ storage: string;
1974
+ /** The folder, for local storage. */
1975
+ dir: string | null;
1976
+ database: string;
1977
+ /** Why backups can't be made with this setup, if they can't. */
1978
+ unavailable: string | null;
1979
+ };
1980
+ backups: AdminBackup[];
1981
+ }
1982
+ /**
1983
+ * Writes a consistent copy of the database to `file` as SQLite, while the CMS keeps running:
1984
+ * SQLite copies itself; other databases are copied into a new SQLite file (`backups.sqlite`).
1985
+ */
1986
+ declare function writeBackupFile<C extends Config>(cms: EasyCMS<C>, file: string): Promise<void>;
1987
+
1920
1988
  declare const MEDIA = "media";
1921
1989
  /** Collections Easy CMS uses internally. Not exposed over REST or in the admin UI. */
1922
1990
  declare const INTERNAL_COLLECTIONS: ReadonlySet<string>;
@@ -2298,6 +2366,12 @@ type AdminAttention =
2298
2366
  /** In production without `serverURL`: links in emails can't be made. */
2299
2367
  | {
2300
2368
  id: 'no-server-url';
2369
+ }
2370
+ /** The last scheduled backup failed, or none finished in two periods (`backups.every`). */
2371
+ | {
2372
+ id: 'backups';
2373
+ failed: boolean;
2374
+ lastDone: string | null;
2301
2375
  };
2302
2376
  /** What the dashboard shows admins (`GET <api>/admin/status`). */
2303
2377
  interface AdminStatus {
@@ -2359,4 +2433,4 @@ declare function validateConfig(config: Config): ConfigIssue[];
2359
2433
  /** The version of `@easy-cms/core`, set when the package is built. */
2360
2434
  declare const VERSION: string;
2361
2435
 
2362
- export { ADMIN_ICONS, API_KEYS, API_KEY_GLOBAL_OPERATIONS, API_KEY_OPERATIONS, type Access, type AccessArgs, type AccessOptions, type AdminAttention, type AdminBrand, type AdminCollection, type AdminComponent, type AdminComponentRef, type AdminConfig, type AdminDeliveries, type AdminDelivery, type AdminEmail, type AdminEmailDelivery, type AdminField, type AdminGlobal, type AdminIcon, type AdminLocale, type AdminPage, type AdminPageRef, type AdminSchema, type AdminStatus, type AdminViewAccess, type AdminWebhookDelivery, type AdminWidgetRef, type AfterChangeHook, type AfterDeleteHook, type AfterReadHook, type ApiKeyContext, type ApiKeyGlobalOperation, type ApiKeyOperation, type ApiKeyPermissions, type ArrayField, Auth, type AuthConfig, type AuthUser, BUILTIN_COLLECTIONS, type BeforeChangeHook, type BeforeDeleteHook, type BeforeValidateHook, type Block, type BlocksField, type BooleanField, type BuiltinApiKeysCollection, type BuiltinMediaCollection, type BuiltinUsersCollection, type BundleHints, CONFIG_FILE_NAMES, CSRF_COOKIE, CSRF_HEADER, type CliCommand, type CollectionAccess, type CollectionAdmin, type CollectionConfig, type CollectionDocument, type CollectionHooks, type CollectionListAdmin, type CollectionSlug, type Config, ConfigError, type ConfigIssue, type ContainerAdmin, type CopyProgress, type CopyResult, type CreateEasyCMSOptions, type CreateInput, type CreateMigrationResult, type CustomField, type CustomFieldTypes, DEFAULT_ADMIN_PATH, DEFAULT_API_PATH, DEFAULT_DEPTH, DEFAULT_MAX_FILE_SIZE, DEFAULT_MAX_VERSIONS, DEFAULT_PASSWORD_EMAILS, DEFAULT_TOKEN_EXPIRATION, type DashboardWidget, type Database, type DatabaseAdapter, type DatabaseInitArgs, type DatabaseTransfer, type DateField, type DeliveryKind, type DeliveryState, type DepthOptions, type DocumentOf, EXTENSIONS, EasyCMS, EasyCMSError, type EmailAdapter, type EmailCheck, type EmailField, type EmailMessage, type EmailSetting, type Endpoint, type EndpointRequest, FIELD_TYPES, FIELD_TYPE_BASES, type Field, type FieldAccess, type FieldAccessFn, type FieldAdmin, type FieldError, type FieldType, type FieldTypeBase, type FieldTypeDefinition, type FieldTypeValidateContext, type FieldValidate, type FieldValidateContext, type FieldValue, type FieldsInput, type FieldsValue, type FilterOptions, type FilterOptionsArgs, type FindArgs, type FindOptions, ForbiddenError, type GlobalAccess, type GlobalConfig, type GlobalDocument, type GlobalHooks, type GlobalInput, type GlobalSlug, type GroupField, type ID, INTERNAL_COLLECTIONS, type ImageSize, type InferCollection, type InferGlobal, type JsonField, type Label, type LivePreview, type LoadConfigOptions, type LocalStorageOptions, type LocalizationConfig, type Logger, type LoginArgs, MAX_DEPTH, MEDIA, MIN_PASSWORD_LENGTH, MIN_SECRET_LENGTH, type MediaDocument, type MediaSize, type MigrationInfo, NotFoundError, type NumberField, type Operation, type PaginatedDocs, type PasswordEmail, type PasswordEmailArgs, type PasswordEmailFn, type PasswordLinkOptions, PayloadTooLargeError, type Plugin, type PluginInfo, type PluginTypes, type PreviewTarget, type PreviewURL, QueryError, type RawDocument, type ReadOptions, type RelationshipField, type ResolvedConfig, type RestHandler, type RestHandlerOptions, type RichTextDocument, type RichTextField, type Role, type RoutesConfig, SESSION_COOKIE, type ScheduledJob, SchemaError, type SchemaMode, type SelectField, type SelectOption, type Session, type SlugField, type SlugOf, type StorageAdapter, type StoredFile, type TextField, type TextareaField, TooManyRequestsError, type TypedPlugin, UnauthorizedError, type UpdateInput, type UpdateOptions, type UploadConfig, type UploadField, type UploadFromURLConfig, VERSION, ValidationError, type Version, type VersionSummary, type VersionsConfig, WEBHOOK_EVENTS, type WebhookConfig, type WebhookEvent, type WebhookPayload, type Where, type WhereOperators, anyone, applyDefaults, applyPlugins, configSignature, consoleEmail, consoleLogger, copyDatabase, createEasyCMS, createRestHandler, createRootEndpointHandler, defineConfig, defineFieldType, definePlugin, fillMissing, findConfigFile, generateSlugs, generateTypes, hasRows, hashPassword, imageDimensions, importConfig, isAdmin, isHasMany, isLoggedIn, keyAllows, loadConfig, localStorage, mergeForUpdate, mimeAllowed, mimeAllowedBy, parseId, populate, readCookie, resolveAdminModule, resolveConfig, rowFields, silentLogger, singularize, slugify, sniffMimeType, validateConfig, validateFields, verifyPassword };
2436
+ export { ADMIN_ICONS, API_KEYS, API_KEY_GLOBAL_OPERATIONS, API_KEY_OPERATIONS, type Access, type AccessArgs, type AccessOptions, type AdminAttention, type AdminBackup, type AdminBackups, type AdminBrand, type AdminCollection, type AdminComponent, type AdminComponentRef, type AdminConfig, type AdminDeliveries, type AdminDelivery, type AdminEmail, type AdminEmailDelivery, type AdminField, type AdminGlobal, type AdminIcon, type AdminLocale, type AdminPage, type AdminPageRef, type AdminSchema, type AdminStatus, type AdminViewAccess, type AdminWebhookDelivery, type AdminWidgetRef, type AfterChangeHook, type AfterDeleteHook, type AfterReadHook, type ApiKeyContext, type ApiKeyGlobalOperation, type ApiKeyOperation, type ApiKeyPermissions, type ArrayField, Auth, type AuthConfig, type AuthUser, BUILTIN_COLLECTIONS, type BackupState, type BackupsConfig, type BeforeChangeHook, type BeforeDeleteHook, type BeforeValidateHook, type Block, type BlocksField, type BooleanField, type BuiltinApiKeysCollection, type BuiltinMediaCollection, type BuiltinUsersCollection, type BundleHints, CONFIG_FILE_NAMES, CSRF_COOKIE, CSRF_HEADER, type CliCommand, type CollectionAccess, type CollectionAdmin, type CollectionConfig, type CollectionDocument, type CollectionHooks, type CollectionListAdmin, type CollectionSlug, type Config, ConfigError, type ConfigIssue, type ContainerAdmin, type CopyProgress, type CopyResult, type CreateEasyCMSOptions, type CreateInput, type CreateMigrationResult, type CustomField, type CustomFieldTypes, DEFAULT_ADMIN_PATH, DEFAULT_API_PATH, DEFAULT_DEPTH, DEFAULT_MAX_FILE_SIZE, DEFAULT_MAX_VERSIONS, DEFAULT_PASSWORD_EMAILS, DEFAULT_TOKEN_EXPIRATION, type DashboardWidget, type Database, type DatabaseAdapter, type DatabaseInitArgs, type DatabaseTransfer, type DateField, type DeliveryKind, type DeliveryState, type DepthOptions, type DocumentOf, EXTENSIONS, EasyCMS, EasyCMSError, type EmailAdapter, type EmailCheck, type EmailField, type EmailMessage, type EmailSetting, type Endpoint, type EndpointRequest, FIELD_TYPES, FIELD_TYPE_BASES, type Field, type FieldAccess, type FieldAccessFn, type FieldAdmin, type FieldError, type FieldType, type FieldTypeBase, type FieldTypeDefinition, type FieldTypeValidateContext, type FieldValidate, type FieldValidateContext, type FieldValue, type FieldsInput, type FieldsValue, type FilterOptions, type FilterOptionsArgs, type FindArgs, type FindOptions, ForbiddenError, type GlobalAccess, type GlobalConfig, type GlobalDocument, type GlobalHooks, type GlobalInput, type GlobalSlug, type GroupField, type ID, INTERNAL_COLLECTIONS, type ImageSize, type InferCollection, type InferGlobal, type JsonField, type Label, type LivePreview, type LoadConfigOptions, type LocalStorageOptions, type LocalizationConfig, type Logger, type LoginArgs, MAX_DEPTH, MEDIA, MIN_PASSWORD_LENGTH, MIN_SECRET_LENGTH, type MediaDocument, type MediaSize, type MigrationInfo, NotFoundError, type NumberField, type Operation, type PaginatedDocs, type PasswordEmail, type PasswordEmailArgs, type PasswordEmailFn, type PasswordLinkOptions, PayloadTooLargeError, type Plugin, type PluginInfo, type PluginTypes, type PreviewTarget, type PreviewURL, QueryError, type RawDocument, type ReadOptions, type RelationshipField, type ResolvedConfig, type RestHandler, type RestHandlerOptions, type RichTextDocument, type RichTextField, type Role, type RoutesConfig, SESSION_COOKIE, type ScheduledJob, SchemaError, type SchemaMode, type SelectField, type SelectOption, type Session, type SlugField, type SlugOf, type StorageAdapter, type StoredFile, type TextField, type TextareaField, TooManyRequestsError, type TypedPlugin, UnauthorizedError, type UpdateInput, type UpdateOptions, type UploadConfig, type UploadField, type UploadFromURLConfig, VERSION, ValidationError, type Version, type VersionSummary, type VersionsConfig, WEBHOOK_EVENTS, type WebhookConfig, type WebhookEvent, type WebhookPayload, type Where, type WhereOperators, anyone, applyDefaults, applyPlugins, configSignature, consoleEmail, consoleLogger, copyDatabase, createEasyCMS, createRestHandler, createRootEndpointHandler, defineConfig, defineFieldType, definePlugin, fillMissing, findConfigFile, generateSlugs, generateTypes, hasRows, hashPassword, imageDimensions, importConfig, isAdmin, isHasMany, isLoggedIn, keyAllows, loadConfig, localStorage, mergeForUpdate, mimeAllowed, mimeAllowedBy, parseId, populate, readCookie, resolveAdminModule, resolveConfig, rowFields, silentLogger, singularize, slugify, sniffMimeType, validateConfig, validateFields, verifyPassword, writeBackupFile };