UNPKG

studiocms

Version:

Astro Native CMS for AstroDB. Built from the ground up by the Astro community.

83 lines (82 loc) 4.04 kB
import { UserPermissionLevel } from '@withstudiocms/auth-kit/types'; import type { APIContext } from 'astro'; import { Effect } from '../effect.js'; import type { UserSessionData } from '../virtuals/auth/types.js'; import type { SiteConfigCacheObject } from '../virtuals/sdk/types/index.js'; export declare const getUserPermissionLevel: (userData: UserSessionData) => Effect.Effect<UserPermissionLevel, import("@withstudiocms/auth-kit/errors").UserError, never>; /** * Retrieves the user's permission levels based on their session data. * * @param userData - The session data of the user. * @returns An object containing boolean flags indicating the user's permission levels: * - `isVisitor`: True if the user has at least visitor-level permissions. * - `isEditor`: True if the user has at least editor-level permissions. * - `isAdmin`: True if the user has at least admin-level permissions. * - `isOwner`: True if the user has owner-level permissions. */ export declare const getUserPermissions: (userData: UserSessionData) => Effect.Effect<{ isVisitor: boolean; isEditor: boolean; isAdmin: boolean; isOwner: boolean; }, import("@withstudiocms/auth-kit/errors").UserError, never>; /** * Creates a fallback site configuration object with default values. * * This function is typically used when no site configuration is available, * providing sensible defaults for the StudioCMS project. * * @returns {SiteConfigCacheObject} The fallback site configuration object. */ export declare const makeFallbackSiteConfig: () => SiteConfigCacheObject; /** * Represents the structure for setting local values in the StudioCMS context. * * @property general - Contains general StudioCMS local values, excluding 'security' and 'plugins'. * @property security - Contains security-related StudioCMS local values. * @property plugins - Contains plugin-related StudioCMS local values. */ export type SetLocalValues = { general: Omit<APIContext['locals']['StudioCMS'], 'security' | 'plugins'>; security: APIContext['locals']['StudioCMS']['security']; plugins: APIContext['locals']['StudioCMS']['plugins']; }; /** * Represents the keys of the {@link SetLocalValues} type. * Useful for extracting valid property names from the {@link SetLocalValues} object type. */ export type SetLocalValuesKeys = keyof SetLocalValues; /** * Enum representing different local settings categories. * * @remarks * Used to specify the context for local configuration, such as general settings, * security-related settings, or plugin-specific settings. * * @enum {string} * @property {string} general - Represents general settings. * @property {string} security - Represents security-related settings. * @property {string} plugins - Represents plugin-specific settings. */ export declare enum SetLocal { GENERAL = "general", SECURITY = "security", PLUGINS = "plugins" } /** * Updates the `locals.StudioCMS` property of the given API context with new values for a specified key. * * Depending on the provided `key`, merges the new `values` into the corresponding section of `locals.StudioCMS`: * - `'general'`: Merges into the root of `StudioCMS`. * - `'security'`: Merges into the `security` property of `StudioCMS`. * - `'plugins'`: Merges into the `plugins` property of `StudioCMS`. * * Uses a deep merge strategy to combine existing and new values. * * @template T - The key of the section to update (`'general'`, `'security'`, or `'plugins'`). * @template V - The type of values to merge, corresponding to the section specified by `T`. * @param context - The API context containing the `locals.StudioCMS` object to update. * @param key - The section of `StudioCMS` to update. * @param values - The new values to merge into the specified section. */ export declare const setLocals: <T extends SetLocalValuesKeys, V extends SetLocalValues[T]>(context: APIContext<Record<string, any>, Record<string, string | undefined>>, key: T, values: V) => Effect.Effect<undefined, Error, never>;