import { HttpMethod, RequestHeader, ResponseHeader, ThenableReject, ThenableResolve } from './types.js'; import { Readable } from 'node:stream'; import { Blob } from 'node:buffer'; import { SageHttpResponse } from './SageHttpResponse.js'; import { FormDataOptions } from './FormDataOptions.js'; import { SageConfig } from './SageConfig.js'; import { SageServer } from './SageServer.js'; import { IncomingHttpHeaders } from 'undici/types/header.js'; import { HttpStatus } from './constants.js'; /** * Greetings, I'm Sage - a chainable HTTP Testing Assistant. * Not meant to be used directly. */ export declare class Sage { private sageServer; private config; private request; private client; private deferredPromises; private asserts; /** * Sets the HTTP method and path for the request. * Not meant to be called directly. * @param sageServer * @param method * @param path * @param config */ constructor(sageServer: SageServer, method: HttpMethod, path: string, config: SageConfig); /** * Sets query parameters for the request. * Also, the URI spec is quite vague about query params, and their handling is different from environment to environment. * I'd advise encoding complex query params into base64 and passing them as a single string. * @param query Supposed to be just a record of strings and numbers. * Other values/types will be ignored. */ query(query: object): this; /** * Sets body payload for the request. * If body is an object, it will be stringified to JSON. Content-Type will be set to application/json. * If body is a string, it will be used as is. Content-Type will remain plain/text. * If body is a Readable stream, it will be used as is. * If you need to set a different Content-Type, use the set method. * @throws SageException if formData is already set * @param body */ send(body?: string | object): this; /** * Sets a header for the request. * Consider using this at the end of the chain if you want to override any of the defaults. * Note: you can pass multiple values as an array for a request header. * However, response headers are always concatenated into a string with a comma separator. * It's done for the sake of testing simplicity. * @param key */ set(key: IncomingHttpHeaders): this; set(key: RequestHeader, value: string | string[]): this; set(key: RequestHeader, value: string): this; /** * If password is provided, Basic Auth header will be added. * If password is not provided, Bearer token header will be added. * Automatically adds Basic or Bearer prefix to the token. * @param usernameOrToken * @param password */ auth(usernameOrToken: string, password?: string): this; cookie(key: string, value: string): this; /** * Method is designed to work only with FormData requests. * Cannot be combined with .send(). * If file is a relative path, it will be treated starting from the working directory (process.cwd()). * When using form-data requests, you can skip setting the Content-Type header. * It will be set automatically. * @throws SageException if body is already set * @param field * @param file a Blob, Buffer, Readable stream or a file path either staring from the working directory, or an absolute path * @param options you can pass either object with type and filename or just a string with filename */ attach(field: string, file: Blob | Buffer | Readable | string, options?: FormDataOptions | string): this; /** * When using form-data requests, you can skip setting the Content-Type header. * It will be set automatically. * @param field * @param value */ field(field: string, value: string | string[] | number | boolean): this; expect(header: ResponseHeader, expectedHeader: string | string[] | RegExp): this; expect(statuses: HttpStatus[]): this; expect(status: HttpStatus): this; then(resolve: ThenableResolve>, reject: ThenableReject): Promise; /** * Request Line term is taken from HTTP spec. * https://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html * @param sageServer * @param method * @param path * @param config */ static fromRequestLine(sageServer: SageServer, method: HttpMethod, path: string, config: SageConfig): Sage; private expectStatuses; private expectHeaders; private assert; }