import * as _homer0_jimple from '@homer0/jimple'; import { J as Jimpex } from '../../index-DAUqbQ6h.js'; import { Response } from 'express'; import { Statuses } from '../../utils/fns/statuses.js'; import { SimpleConfig } from '@homer0/simple-config'; import '../../types/express.js'; import '../../types/http.js'; import 'https'; import 'http'; import 'spdy'; import 'node-fetch'; import '../../types/utils.js'; import '@homer0/path-utils'; import '@homer0/simple-logger'; import '@homer0/events-hub'; import 'statuses'; /** * The options to construct a {@link ResponsesBuilder}. * * @group Services/ResponsesBuilder */ type ResponsesBuilderConstructorOptions = { /** * A dictionary with the dependencies to inject. */ inject: { config: SimpleConfig; statuses: Statuses; }; }; /** * The options to build a response for a post message. * * @group Services/ResponsesBuilder */ type HTMLPostMessageResponseOptions = { /** * The response object generated by the application. */ res: Response; /** * The title for the HTML. */ title: string; /** * The contents of the post message. */ message: string; /** * The status code for the response. * * @default 200 */ status?: number | string; /** * From which object will the `postMessage` method called from. * * @default 'window.opener' */ target?: string; /** * Whether or not to call `window.close` after sending the message. * * @default true */ close?: boolean; /** * In case `close` is set to `true`, this option is to specify how many milliseconds * should be waited before closing the window. * * @default 700 */ closeDelay?: number; }; /** * The options to build a response for JSON. * * @group Services/ResponsesBuilder */ type JSONResponseOptions = { /** * The response object generated by the application. */ res: Response; /** * The actual data for the response. It will be added in a `data` property. */ data: unknown; /** * The status code for the response. * * @default 200 */ status?: number | string; /** * Extra information to include inside the `metadata` object. */ metadata?: object; }; /** * A utility service to build responses. * * @group Services * @group Services/ResponsesBuilder */ declare class ResponsesBuilder { /** * The application configuration, to get the `version` and the `postMessagesPrefix`. */ protected readonly _config: SimpleConfig; /** * The utility service to get HTTP status codes. */ protected readonly _statuses: Statuses; /** * @param options The options to construct the service. */ constructor({ inject: { config, statuses } }: ResponsesBuilderConstructorOptions); /** * Generates and send an HTML response that emits a post message. * The post message will be prefixed with the value of the configuration setting * `postMessagesPrefix`. * * @param options The options to customize how the HTML is generated. */ htmlPostMessage(options: HTMLPostMessageResponseOptions): void; /** * Generates and sends a JSON response. * * @param options The options to customize how the JSON is generated. * @example * * The generated looks like this. * * { * metadata: { * version: 'dev', * status: 200, * }, * data: { foo: 'bar' }, * } * */ json(options: JSONResponseOptions): void; /** * Generates a basic HTML template for the service to use when generating a post message * response. * * @param title The HTML `` attribute. * @param code Javascript code to be wrapped on a `<script />` tag. */ protected _htmlTemplate(title: string, code: string): string; /** * Utility method used to make sure a received status is a valid status code. If the * status is a string, the method will try to find the code from the `statuses` package. * * @param status The status to normalize. * @returns If `status` is a string, but there's no valid code, it will return 200. */ protected _normalizeStatus(status: number | string): number; } /** * The service provider that once registered on the container will set an instance of * {@link ResponsesBuilder} as the `responsesBuilder` service. * * @example * * // Register it on the container * container.register(responsesBuilderProvider); * // Getting access to the service instance * const responsesBuilder = container.get<ResponsesBuilder>('responsesBuilder'); * * @group Providers * @group Services/ResponsesBuilder */ declare const responsesBuilderProvider: _homer0_jimple.Resource<"provider", "register", _homer0_jimple.ProviderRegisterFn<Jimpex>>; export { type HTMLPostMessageResponseOptions, type JSONResponseOptions, ResponsesBuilder, type ResponsesBuilderConstructorOptions, responsesBuilderProvider };