UNPKG

propr

Version:

A proper way to interface with prepr.io

113 lines (110 loc) 4.1 kB
import { FetchOptions } from 'ofetch'; /** * Options for configuring a PreprClient instance. * @public */ interface PreprClientOptions { /** * The Prepr API token used to authenticate requests. */ token: string; /** * The base URL of the Prepr API. If not provided, defaults to https://cdn.prepr.io. */ baseUrl?: string | URL; /** * The timeout in milliseconds for requests to the Prepr API. If not provided, defaults to 4000. */ timeout?: number; /** * The ID of the user associated with this PreprClient instance. */ userId?: string; } declare class PreprClient { #private; /** * The query parameters used for the request. * @public */ query: URLSearchParams; /** * Creates a new PreprClient instance with the specified options. * @param options - The options used to configure the PreprClient instance. */ constructor(options: PreprClientOptions); /** * Calculates the numeric user ID from a string. * @private */ private calculateUserId; /** * Sets the user ID for the Prepr-ABTesting header used in requests made by this PreprClient instance. * @param userId - The user ID to set. If `undefined`, the header will be removed from requests. * @returns This PreprClient instance. */ userId(userId?: string): this; /** * Sets the timeout for requests made by this PreprClient instance. * @param milliseconds - The timeout in milliseconds. * @returns This PreprClient instance. */ timeout(milliseconds: number): this; /** * Sets the timeout in milliseconds for requests made by this PreprClient instance. * @param milliseconds - The timeout in milliseconds. * @returns This PreprClient instance. */ sort(field: string): this; /** * Sets the maximum number of results to return for requests made by this PreprClient instance. * @param limit - The maximum number of results to return. * @returns This PreprClient instance. */ limit(limit: number): this; /** * Sets the number of results to skip for requests made by this PreprClient instance. * @param skip - The number of results to skip. * @returns This PreprClient instance. */ skip(skip: number): this; /** * Sets the path for requests made by this PreprClient instance. * @param path - The path to set. * @returns This PreprClient instance. */ path(path: string): this; /** * Sets the Prepr API token for requests made by this PreprClient instance. * @param token - The Prepr API token to set. * @returns This PreprClient instance. */ token(token: string): this; /** * Sets the GraphQL query to include in requests made by this PreprClient instance. * @param graphqlQuery - The GraphQL query to set. * @returns This PreprClient instance. */ graphqlQuery(graphqlQuery: string): this; /** * Sets the GraphQL variables to include in requests made by this PreprClient instance. * @param graphqlVariables - The GraphQL variables to set. * @returns This PreprClient instance. */ graphqlVariables(graphqlVariables: object): this; /** * Makes a request to the Prepr API. * @param request - The request to make. This can be a URL, a Request object, or a string representing a path to append to the base URL. * @param options - The options for the request. These will be merged with the options set on this PreprClient instance. * @returns A Promise that resolves to the response from the Prepr API. */ fetch<T>(request?: RequestInfo, options?: FetchOptions<"json">): Promise<T>; } /** * Creates a new instance of `PreprClient`. * @param options - The options used to configure the `PreprClient` instance. * @returns A new instance of `PreprClient`. * @public */ declare const createPreprClient: (options: PreprClientOptions) => PreprClient; export { PreprClientOptions, createPreprClient, PreprClient as default };