@easy-cms/core 0.30.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.
Files changed (3) hide show
  1. package/dist/index.d.ts +114 -1
  2. package/dist/index.js +748 -266
  3. package/package.json +1 -1
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
  /**
@@ -245,6 +247,25 @@ interface EmailAdapter {
245
247
  send(message: EmailMessage & {
246
248
  readonly from: string;
247
249
  }): Promise<void>;
250
+ /**
251
+ * The settings in use, shown to admins on Settings → Email. Never return secrets: say whether
252
+ * a password is set, not what it is.
253
+ */
254
+ describe?(): readonly EmailSetting[];
255
+ /** Checks the connection without sending (Settings → Email); throws with the reason. */
256
+ verify?(): Promise<void>;
257
+ }
258
+ /** One setting an email adapter shows to admins (`describe()`). */
259
+ interface EmailSetting {
260
+ /**
261
+ * `host`, `port`, `secure`, `user`, `password`, `from` and `delivery` (`log`: printed, not sent)
262
+ * are translated in the admin; others are shown as they are.
263
+ */
264
+ readonly key: string;
265
+ /** `null`: not set. */
266
+ readonly value: string | null;
267
+ /** Where it comes from, e.g. `SMTP_HOST` or `smtp({ host })`. */
268
+ readonly source?: string;
248
269
  }
249
270
  /** Prints emails to the log instead of sending them: for development and tests. */
250
271
  declare function consoleEmail(options?: {
@@ -1784,6 +1805,27 @@ type TypedPlugin<T extends PluginTypes> = Plugin & {
1784
1805
  * ```
1785
1806
  */
1786
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
+ }
1787
1829
  interface Config {
1788
1830
  /** Signs sessions. At least 32 characters; read it from `process.env.EASY_CMS_SECRET`. */
1789
1831
  readonly secret: string;
@@ -1839,6 +1881,11 @@ interface Config {
1839
1881
  * database and retried until sent.
1840
1882
  */
1841
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;
1842
1889
  readonly plugins?: readonly Plugin[];
1843
1890
  }
1844
1891
  /** The config after plugins ran, validation passed and defaults were applied. */
@@ -1898,6 +1945,46 @@ declare function hashPassword(password: string): Promise<string>;
1898
1945
  /** Checks a password against a hash in constant time. Malformed hashes never match. */
1899
1946
  declare function verifyPassword(password: string, stored: string): Promise<boolean>;
1900
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
+
1901
1988
  declare const MEDIA = "media";
1902
1989
  /** Collections Easy CMS uses internally. Not exposed over REST or in the admin UI. */
1903
1990
  declare const INTERNAL_COLLECTIONS: ReadonlySet<string>;
@@ -2080,6 +2167,26 @@ interface AdminDeliveries {
2080
2167
  counts: Record<DeliveryState, number>;
2081
2168
  }
2082
2169
 
2170
+ /** Settings → Email in the admin (`GET <api>/admin/email`). */
2171
+ interface AdminEmail {
2172
+ /** An `email` adapter is set in the config. */
2173
+ configured: boolean;
2174
+ /** The adapter's name, e.g. `smtp`; `custom` when it has none. */
2175
+ name: string | null;
2176
+ /** The default sender. */
2177
+ from: string | null;
2178
+ /** What the adapter tells about itself (`describe()`), never secrets. */
2179
+ settings: EmailSetting[];
2180
+ /** The adapter can check its connection without sending (`verify()`). */
2181
+ canVerify: boolean;
2182
+ }
2183
+ type EmailCheck = {
2184
+ ok: true;
2185
+ } | {
2186
+ ok: false;
2187
+ error: string;
2188
+ };
2189
+
2083
2190
  /**
2084
2191
  * Finds the file of an admin module (`admin.modules`): a package export or a path relative to
2085
2192
  * the project root. Looks from the project root first, then from the server's entry file
@@ -2259,6 +2366,12 @@ type AdminAttention =
2259
2366
  /** In production without `serverURL`: links in emails can't be made. */
2260
2367
  | {
2261
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;
2262
2375
  };
2263
2376
  /** What the dashboard shows admins (`GET <api>/admin/status`). */
2264
2377
  interface AdminStatus {
@@ -2320,4 +2433,4 @@ declare function validateConfig(config: Config): ConfigIssue[];
2320
2433
  /** The version of `@easy-cms/core`, set when the package is built. */
2321
2434
  declare const VERSION: string;
2322
2435
 
2323
- 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 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 EmailField, type EmailMessage, 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 };