@easy-cms/core 0.40.0 → 0.42.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 +100 -1
- package/dist/index.js +2814 -2543
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -208,6 +208,13 @@ declare class Auth {
|
|
|
208
208
|
hasUsers(): Promise<boolean>;
|
|
209
209
|
/** Ends the session for a signed token. Unknown tokens are ignored. */
|
|
210
210
|
logout(signedToken: string): Promise<void>;
|
|
211
|
+
/**
|
|
212
|
+
* The user a request's headers carry: a Bearer token (session or API key) or the session
|
|
213
|
+
* cookie; `null` when there is none or it is not valid. For frameworks' pages and handlers.
|
|
214
|
+
*/
|
|
215
|
+
userFromHeaders(headers: {
|
|
216
|
+
get(name: string): string | null | undefined;
|
|
217
|
+
}): Promise<AuthUser | null>;
|
|
211
218
|
/**
|
|
212
219
|
* Returns the user for a signed session token, or for an API key (`ecms_…`, with `apiKey` set
|
|
213
220
|
* on the user), or `null` if it is invalid or expired.
|
|
@@ -1047,6 +1054,17 @@ declare class MediaFolders {
|
|
|
1047
1054
|
id: ID;
|
|
1048
1055
|
private: boolean;
|
|
1049
1056
|
}[]>;
|
|
1057
|
+
/**
|
|
1058
|
+
* The privacy each folder of a subtree would have after a change to its top folder: made
|
|
1059
|
+
* private or public, moved, or (as `private: false`) deleted with its contents moving up.
|
|
1060
|
+
*/
|
|
1061
|
+
privacyAfter(id: ID, change: {
|
|
1062
|
+
private?: boolean;
|
|
1063
|
+
parent?: ID | null;
|
|
1064
|
+
}): Promise<{
|
|
1065
|
+
id: ID;
|
|
1066
|
+
private: boolean;
|
|
1067
|
+
}[]>;
|
|
1050
1068
|
/**
|
|
1051
1069
|
* The folder with this key (`folder: 'banners'` on upload fields), made at the top level when
|
|
1052
1070
|
* there is none yet.
|
|
@@ -1103,6 +1121,28 @@ interface StorageAdapter {
|
|
|
1103
1121
|
* (`<api>/media/file/<key>`), as the local adapter does.
|
|
1104
1122
|
*/
|
|
1105
1123
|
url?(key: string): string | undefined;
|
|
1124
|
+
/**
|
|
1125
|
+
* Lets a browser send a file straight to the storage (large files, past a host's request
|
|
1126
|
+
* limit): where to send it and how. The URL must work for `expiresIn` seconds and accept at
|
|
1127
|
+
* most `size` bytes. Without it, files are uploaded through the server.
|
|
1128
|
+
*/
|
|
1129
|
+
uploadURL?(key: string, options: {
|
|
1130
|
+
contentType: string;
|
|
1131
|
+
size: number;
|
|
1132
|
+
expiresIn: number;
|
|
1133
|
+
}): Promise<DirectUpload>;
|
|
1134
|
+
/**
|
|
1135
|
+
* The first `bytes` of a file and its whole size, without reading it all (to check a file
|
|
1136
|
+
* uploaded straight to the storage); `null` when there is no such file. Default: `get`.
|
|
1137
|
+
*/
|
|
1138
|
+
getStart?(key: string, bytes: number): Promise<StoredFile | null>;
|
|
1139
|
+
}
|
|
1140
|
+
/** Where and how a browser sends a file straight to the storage (`StorageAdapter.uploadURL`). */
|
|
1141
|
+
interface DirectUpload {
|
|
1142
|
+
readonly url: string;
|
|
1143
|
+
readonly method: 'PUT' | 'POST';
|
|
1144
|
+
/** Headers to send with the file. */
|
|
1145
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
1106
1146
|
}
|
|
1107
1147
|
interface LocalStorageOptions {
|
|
1108
1148
|
/** Directory, relative to the project root. Default `uploads`. */
|
|
@@ -1254,6 +1294,32 @@ declare class EasyCMS<C extends Config = Config> {
|
|
|
1254
1294
|
data: Uint8Array;
|
|
1255
1295
|
name: string;
|
|
1256
1296
|
}, data?: Record<string, unknown>, options?: DepthOptions): Promise<MediaDocument>;
|
|
1297
|
+
/**
|
|
1298
|
+
* Starts an upload straight to the storage, for files too large to send through the server
|
|
1299
|
+
* (`POST <api>/media/uploads`): checks who uploads what where, as `upload()` does, and returns
|
|
1300
|
+
* a signed ticket and where to send the file. `upload` is `null` when the storage can't take
|
|
1301
|
+
* files directly: send it to `upload()` instead. Then `completeUpload(ticket)`.
|
|
1302
|
+
*/
|
|
1303
|
+
createUpload(file: {
|
|
1304
|
+
name: string;
|
|
1305
|
+
size: number;
|
|
1306
|
+
type?: string;
|
|
1307
|
+
}, data?: Record<string, unknown>, options?: AccessOptions): Promise<{
|
|
1308
|
+
ticket: string;
|
|
1309
|
+
upload: DirectUpload | null;
|
|
1310
|
+
}>;
|
|
1311
|
+
/**
|
|
1312
|
+
* Finishes an upload made with `createUpload()` (`POST <api>/media/uploads/complete`): checks
|
|
1313
|
+
* the file in the storage like any upload (its size, and its type from its contents), then
|
|
1314
|
+
* makes its media document. A file that fails is deleted.
|
|
1315
|
+
*/
|
|
1316
|
+
completeUpload(ticket: string, options?: DepthOptions): Promise<MediaDocument>;
|
|
1317
|
+
/** Who may upload, and into which folder: `upload()` and direct uploads. */
|
|
1318
|
+
private checkUpload;
|
|
1319
|
+
/** A value with its HMAC (`secret`), for `purpose` only: `<base64url JSON>.<signature>`. */
|
|
1320
|
+
private sign;
|
|
1321
|
+
/** The value of a token made by `sign`, or `undefined` when it isn't genuine. */
|
|
1322
|
+
private verify;
|
|
1257
1323
|
/**
|
|
1258
1324
|
* Downloads a file from an `http(s)` link and uploads it like `upload()`. Private network
|
|
1259
1325
|
* addresses are refused unless `upload.fromURL.allowPrivate`. Calls on behalf of a user (the
|
|
@@ -1307,6 +1373,11 @@ declare class EasyCMS<C extends Config = Config> {
|
|
|
1307
1373
|
private relocate;
|
|
1308
1374
|
/** A folder's name, parent and permissions; private only with somewhere private to keep files. */
|
|
1309
1375
|
private validateFolder;
|
|
1376
|
+
/**
|
|
1377
|
+
* Refuses a change that would move more than 200 files between storages in one request: they
|
|
1378
|
+
* are copied one by one, which could outlast a serverless function.
|
|
1379
|
+
*/
|
|
1380
|
+
private checkMoveLimit;
|
|
1310
1381
|
/** After a folder became private or public (or moved): its files follow, in every subfolder. */
|
|
1311
1382
|
private settlePrivacy;
|
|
1312
1383
|
/** Files at the top level are public. */
|
|
@@ -2806,6 +2877,32 @@ interface ValidateResult {
|
|
|
2806
2877
|
/** Checks and normalizes data against fields. Unknown keys are dropped. */
|
|
2807
2878
|
declare function validateFields(fields: readonly Field[], input: Data, options: ValidateOptions, prefix?: string): Promise<ValidateResult>;
|
|
2808
2879
|
|
|
2880
|
+
/**
|
|
2881
|
+
* The Easy CMS instance for this server, made on first use and kept across hot reloads.
|
|
2882
|
+
*
|
|
2883
|
+
* Configs are compared by structure, not identity: frameworks bundle the config into each server
|
|
2884
|
+
* layer, so the same config can arrive as several objects. A change to fields or options (in
|
|
2885
|
+
* development) closes the old instance and makes a new one; a change to a hook's code alone needs
|
|
2886
|
+
* a restart. A failed start is not kept: the next call tries again.
|
|
2887
|
+
*/
|
|
2888
|
+
declare function sharedEasyCMS<const C extends Config>(config: C, options?: CreateEasyCMSOptions): Promise<EasyCMS<C>>;
|
|
2889
|
+
interface ApiHandlerOptions {
|
|
2890
|
+
/** Where the API is mounted. Default: `routes.api` of the config. */
|
|
2891
|
+
readonly basePath?: string;
|
|
2892
|
+
/**
|
|
2893
|
+
* The client's IP (login rate limiting, the audit log), from the framework's request object.
|
|
2894
|
+
* Takes precedence over `trustProxy`.
|
|
2895
|
+
*/
|
|
2896
|
+
readonly getClientIp?: (request: Request) => string | undefined;
|
|
2897
|
+
/** Use the first `X-Forwarded-For` address. Only behind a proxy you trust (Vercel, Netlify…). */
|
|
2898
|
+
readonly trustProxy?: boolean;
|
|
2899
|
+
}
|
|
2900
|
+
/**
|
|
2901
|
+
* The REST API as a `(Request) => Response` handler for a framework's route, on the shared
|
|
2902
|
+
* instance (`sharedEasyCMS`). Mount it at `routes.api` (default `/api/cms`), for every method.
|
|
2903
|
+
*/
|
|
2904
|
+
declare function createApiHandler(config: Config, options?: ApiHandlerOptions): (request: Request) => Promise<Response>;
|
|
2905
|
+
|
|
2809
2906
|
declare const CONFIG_FILE_NAMES: readonly ["easy-cms.config.ts", "easy-cms.config.mts", "easy-cms.config.js", "easy-cms.config.mjs"];
|
|
2810
2907
|
interface LoadConfigOptions {
|
|
2811
2908
|
/** Directory to search. Default `process.cwd()`. */
|
|
@@ -3193,7 +3290,9 @@ interface AdminStatus {
|
|
|
3193
3290
|
attention: AdminAttention[];
|
|
3194
3291
|
}
|
|
3195
3292
|
|
|
3293
|
+
/** The session cookie the REST API sets at login. */
|
|
3196
3294
|
declare const SESSION_COOKIE = "ecms-session";
|
|
3295
|
+
|
|
3197
3296
|
declare const CSRF_COOKIE = "ecms-csrf";
|
|
3198
3297
|
declare const CSRF_HEADER = "x-csrf-token";
|
|
3199
3298
|
interface RestHandlerOptions {
|
|
@@ -3231,4 +3330,4 @@ declare function validateConfig(config: Config): ConfigIssue[];
|
|
|
3231
3330
|
/** The version of `@easy-cms/core`, set when the package is built. */
|
|
3232
3331
|
declare const VERSION: string;
|
|
3233
3332
|
|
|
3234
|
-
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 AdminRole, type AdminRoleChange, type AdminRoleField, type AdminRoleTarget, type AdminRoleView, type AdminRoles, type AdminSchema, type AdminSso, type AdminStatus, type AdminViewAccess, type AdminWebhookDelivery, type AdminWidgetRef, type AfterChangeHook, type AfterDeleteHook, type AfterReadHook, type ApiKeyContext, type ApiKeyGlobalOperation, type ApiKeyOperation, type ApiKeyPermissions, type ArrayField, type AuditChange, type AuditConfig, type AuditEntry, AuditLog, type AuditPage, type AuditVerification, Auth, type AuthConfig, type AuthProvider, type AuthProviderProfile, type AuthProviderRequest, 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 BuiltinMediaFoldersCollection, 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, FOLDER_LEVELS, type Field, type FieldAccess, type FieldAccessFn, type FieldAdmin, type FieldError, type FieldRule, 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, type FolderLevel, type FolderPermissions, 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, MEDIA_FOLDERS, MIME_GROUPS, MIN_PASSWORD_LENGTH, MIN_SECRET_LENGTH, type MediaDocument, MediaFolders, 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, ROLE_OPERATIONS, type RawDocument, type ReadOptions, type RelationshipField, type ResolvedConfig, type RestHandler, type RestHandlerOptions, type RichTextDocument, type RichTextField, type Role, type RoleOperation, type RolePermissions, Roles, type RoutesConfig, SESSION_COOKIE, SSO_COOKIE, type ScheduledJob, SchemaError, type SchemaMode, type SelectField, type SelectOption, type Session, type SlugField, type SlugOf, type SsoOutcome, type SsoProviderRef, type StorageAdapter, type StoredFile, type TextField, type TextareaField, TooManyRequestsError, type TypedPlugin, UnauthorizedError, type UpdateInput, type UpdateOptions, type UploadConfig, type UploadField, type UploadFromURLConfig, type UserIdentity, 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, expandMimeTypes, 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 };
|
|
3333
|
+
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 AdminRole, type AdminRoleChange, type AdminRoleField, type AdminRoleTarget, type AdminRoleView, type AdminRoles, type AdminSchema, type AdminSso, type AdminStatus, type AdminViewAccess, type AdminWebhookDelivery, type AdminWidgetRef, type AfterChangeHook, type AfterDeleteHook, type AfterReadHook, type ApiHandlerOptions, type ApiKeyContext, type ApiKeyGlobalOperation, type ApiKeyOperation, type ApiKeyPermissions, type ArrayField, type AuditChange, type AuditConfig, type AuditEntry, AuditLog, type AuditPage, type AuditVerification, Auth, type AuthConfig, type AuthProvider, type AuthProviderProfile, type AuthProviderRequest, 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 BuiltinMediaFoldersCollection, 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 DirectUpload, type DocumentOf, EXTENSIONS, EasyCMS, EasyCMSError, type EmailAdapter, type EmailCheck, type EmailField, type EmailMessage, type EmailSetting, type Endpoint, type EndpointRequest, FIELD_TYPES, FIELD_TYPE_BASES, FOLDER_LEVELS, type Field, type FieldAccess, type FieldAccessFn, type FieldAdmin, type FieldError, type FieldRule, 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, type FolderLevel, type FolderPermissions, 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, MEDIA_FOLDERS, MIME_GROUPS, MIN_PASSWORD_LENGTH, MIN_SECRET_LENGTH, type MediaDocument, MediaFolders, 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, ROLE_OPERATIONS, type RawDocument, type ReadOptions, type RelationshipField, type ResolvedConfig, type RestHandler, type RestHandlerOptions, type RichTextDocument, type RichTextField, type Role, type RoleOperation, type RolePermissions, Roles, type RoutesConfig, SESSION_COOKIE, SSO_COOKIE, type ScheduledJob, SchemaError, type SchemaMode, type SelectField, type SelectOption, type Session, type SlugField, type SlugOf, type SsoOutcome, type SsoProviderRef, type StorageAdapter, type StoredFile, type TextField, type TextareaField, TooManyRequestsError, type TypedPlugin, UnauthorizedError, type UpdateInput, type UpdateOptions, type UploadConfig, type UploadField, type UploadFromURLConfig, type UserIdentity, 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, createApiHandler, createEasyCMS, createRestHandler, createRootEndpointHandler, defineConfig, defineFieldType, definePlugin, expandMimeTypes, fillMissing, findConfigFile, generateSlugs, generateTypes, hasRows, hashPassword, imageDimensions, importConfig, isAdmin, isHasMany, isLoggedIn, keyAllows, loadConfig, localStorage, mergeForUpdate, mimeAllowed, mimeAllowedBy, parseId, populate, readCookie, resolveAdminModule, resolveConfig, rowFields, sharedEasyCMS, silentLogger, singularize, slugify, sniffMimeType, validateConfig, validateFields, verifyPassword, writeBackupFile };
|