import { CollectionTypeManager, SingleTypeManager, UsersPermissionsUsersManager } from './content-types'; import { FilesManager } from './files'; import type { UsersPermissionsUsersIdOverloads } from './content-types'; import type { ContentTypeManagerOptions } from './content-types/abstract'; export interface StrapiClientConfig { /** The base URL of the Strapi content API, required for all client library operations. */ baseURL: string; /** Optional authentication configuration, which specifies a strategy and its details. */ auth?: AuthConfig; /** Optional custom headers to include with every request. */ headers?: Record; } /** * Describes an authentication strategy used in the client library configuration. * * @template T The type of options for the authentication strategy. */ export interface AuthConfig { /** The identifier of the authentication method */ strategy: string; /** Configuration details for the specified strategy */ options?: T; } /** * Class representing the Strapi Client to interface with a Strapi backend. * * This class integrates setting up configuration, validation, and handling * HTTP requests with authentication. * * It serves as the main interface through which users interact with * their Strapi installation programmatically. */ export declare class StrapiClient { /** * Gives access to the files API to interact with media files uploaded to Strapi. * * @example * ```typescript * // Initialize the client with required configuration * const client = strapi({ baseURL: 'http://localhost:1337/api' }); * * // Example: retrieve a list of image files * const imageFiles = await client.files.find({ * filters: { mime: { $contains: 'image' } }, * sort: 'name:asc' * }); * * // Example: retrieve a single file by ID * const file = await client.files.findOne(1); * ``` * * @see FilesManager * @see StrapiClient */ readonly files: FilesManager; /** * Retrieves the base URL of the Strapi Client instance. * * This getter returns the `baseURL` property stored within the client's configuration object. * * The base URL is used as the starting point for all HTTP requests initiated through the client. * * @returns The current base URL configured in the client. * This URL typically represents the root endpoint of the Strapi service the client interfaces with. * * @example * const config = { baseURL: 'http://localhost:1337/api' }; * const client = new Strapi(config); * * console.log(client.baseURL); // Output: http://localhost:1337 */ get baseURL(): string; /** * Executes an HTTP fetch request to a specified endpoint using the client HTTP client. * * This method ensures authentication is handled before issuing requests and sets the necessary headers. * * @param url - The endpoint to fetch from, appended to the base URL of the client. * @param [init] - Optional initialization options for the request, such as headers or method type. * * @example * ```typescript * // Create the client instance * const config = { baseURL: 'http://localhost:1337/api' }; * const client = new Strapi(config); * * // Perform a custom fetch query * const response = await client.fetch('/categories'); * * // Parse the categories into a readable JSON object * const categories = await response.json(); * * // Log the categories * console.log(categories); * ``` * * @note * - The method automatically handles authentication by checking if the user is authenticated and attempts to authenticate if not. * - The base URL is prepended to the provided endpoint path. */ fetch(url: string, init?: RequestInit): Promise; /** * Returns a {@link CollectionTypeManager} instance to interact with the specified collection-type routes in the * Strapi app. * * This instance provides methods for performing operations on the associated documents: create, read, update, delete. * * @param resource - The plural name of the collection to interact with. * This should match the collection name as defined in the Strapi app. * @param [options] - Optional parameter to specify additional configuration such as custom API path or plugin context. * * @returns An instance of {@link CollectionTypeManager} for the given {@link resource}. * * @example * ```typescript * // Initialize the client with required configuration * const config = { baseURL: 'http://localhost:1337/api' }; * const client = new Strapi(config); * * // Retrieve a CollectionTypeManager for the 'articles' collection * const articles = client.collection('articles'); * * // Example: find all articles * const allArticles = await articles.find(); * * // Example: find a single article by ID * const singleArticle = await articles.findOne('936c6dc0-f2ec-46c3-ac6d-c0f2ec46c396'); * * // Example: create a new article * const newArticle = await articles.create({ title: 'New Article' }); * * // Example: update an existing article * const updatedArticle = await articles.update('90169631-7033-4963-9696-317033a96341', { title: 'Updated Title' }); * * // Example: delete an article * await articles.delete('dde61ffb-00a6-4cc7-a61f-fb00a63cc740'); * * // Example with a custom API path * const customArticles = client.collection('articles', { path: '/custom-articles-path' }); * const customAllArticles = await customArticles.find(); * * // Example: Working with users (auto-detected as users-permissions plugin) * const users = client.collection('users'); * await users.create({ username: 'john', email: 'john@example.com', password: 'Test1234!' }); * * // Example: Working with a custom plugin (routes prefixed by default) * const posts = client.collection('posts', { * plugin: { * name: 'blog', // routes are prefixed with the plugin name by default * } * }); * * // This makes requests to /blog/posts * const newPost = await posts.create({ title: 'My Post', content: 'Post content' }); * ``` * * @see CollectionTypeManager * @see StrapiClient */ collection(resource: T, options?: ClientCollectionOptions): T extends 'users' ? UsersPermissionsUsersManager & UsersPermissionsUsersIdOverloads : CollectionTypeManager; /** * Returns a {@link SingleTypeManager} instance to interact with the specified single-type routes in the Strapi app. * * This instance provides methods for managing the associated single-type document: read, update, delete. * * @param resource - The singular name of the single-type resource to interact with. * This should match the single-type name as defined in the Strapi app. * @param [options] - Optional parameter to specify additional configuration such as custom API path. * * @returns An instance of {@link SingleTypeManager} for the given {@link resource}. * * @example * ```typescript * // Initialize the client with required configuration * const client = new Strapi({ baseURL: 'http://localhost:1337/api' }); * * // Retrieve a SingleTypeManager for the 'homepage' resource * const homepage = client.single('homepage'); * * // Example: fetch the homepage content in Spanish * const homepageContent = await homepage.find({ locale: 'es' }); * * // Example: update the homepage content * const updatedHomepage = await homepage.update({ title: 'Updated Homepage Title' }); * * // Example: delete the homepage content * await homepage.delete(); * * // Example with a custom API path * const customHomepage = client.single('homepage', { path: '/custom-homepage-path' }); * const customHomepageDocument = await customHomepage.find(); * ``` * * @see SingleTypeManager * @see StrapiClient */ single(resource: string, options?: SingleCollectionOptions): SingleTypeManager; } export type ClientCollectionOptions = Pick; export type SingleCollectionOptions = Pick;