@vendure/core
Version:
A modern, headless ecommerce framework
198 lines (197 loc) • 7.09 kB
TypeScript
import { DynamicModule, INestApplication } from '@nestjs/common';
import { NestApplicationContextOptions } from '@nestjs/common/interfaces/nest-application-context-options.interface';
import { NestApplicationOptions } from '@nestjs/common/interfaces/nest-application-options.interface';
import { Type } from '@vendure/common/lib/shared-types';
import { RuntimeVendureConfig, VendureConfig } from './config/vendure-config';
import { VendureWorker } from './worker/vendure-worker';
export type VendureBootstrapFunction = (config: VendureConfig) => Promise<INestApplication>;
/**
* @description
* Additional options that can be used to configure the bootstrap process of the
* Vendure server.
*
* @since 2.2.0
* @docsCategory common
* @docsPage bootstrap
*/
export interface BootstrapOptions {
/**
* @description
* These options get passed directly to the `NestFactory.create()` method.
*/
nestApplicationOptions?: NestApplicationOptions;
/**
* @description
* By default, if a plugin specifies a compatibility range which does not include the current
* Vendure version, the bootstrap process will fail. This option allows you to ignore compatibility
* errors for specific plugins.
*
* This setting should be used with caution, only if you are sure that the plugin will still
* work as expected with the current version of Vendure.
*
* @example
* ```ts
* import { bootstrap } from '\@vendure/core';
* import { config } from './vendure-config';
* import { MyPlugin } from './plugins/my-plugin';
*
* bootstrap(config, {
* ignoreCompatibilityErrorsForPlugins: [MyPlugin],
* });
* ```
*
* @default []
* @since 3.1.0
*/
ignoreCompatibilityErrorsForPlugins?: Array<DynamicModule | Type<any>>;
/**
* @description
* A function which is called before the app starts listening. This can be used to perform any final configuration of the Nest application.
* E.g., to set up OpenAPI specification with Swagger.
*
* @example
* ```ts
* import { bootstrap } from '\@vendure/core';
* import { config } from './vendure-config';
* import { SwaggerModule, DocumentBuilder } from '\@nestjs/swagger';
*
* bootstrap(config, {
* onBeforeAppListen: async (app) => {
* const config = new DocumentBuilder()
* .setTitle('Cats example')
* .setDescription('The cats API description')
* .setVersion('1.0')
* .addTag('cats')
* .build();
* const documentFactory = () => SwaggerModule.createDocument(app, config);
* SwaggerModule.setup('api', app, documentFactory);
* }
* });
* ```
* @default undefined
* @since 3.6.0
*/
onBeforeAppListen?: (app: INestApplication) => void | Promise<void>;
}
/**
* @description
* Additional options that can be used to configure the bootstrap process of the
* Vendure worker.
*
* @since 2.2.0
* @docsCategory worker
* @docsPage bootstrapWorker
*/
export interface BootstrapWorkerOptions {
/**
* @description
* These options get passed directly to the `NestFactory.createApplicationContext` method.
*/
nestApplicationContextOptions?: NestApplicationContextOptions;
/**
* @description
* See the `ignoreCompatibilityErrorsForPlugins` option in {@link BootstrapOptions}.
*
* @default []
* @since 3.1.0
*/
ignoreCompatibilityErrorsForPlugins?: Array<DynamicModule | Type<any>>;
}
/**
* @description
* Bootstraps the Vendure server. This is the entry point to the application.
*
* @example
* ```ts
* import { bootstrap } from '\@vendure/core';
* import { config } from './vendure-config';
*
* bootstrap(config).catch(err => {
* console.log(err);
* process.exit(1);
* });
* ```
*
* ### Passing additional options
*
* Since v2.2.0, you can pass additional options to the NestJs application via the `options` parameter.
* For example, to integrate with the [Nest Devtools](https://docs.nestjs.com/devtools/overview), you need to
* pass the `snapshot` option:
*
* ```ts
* import { bootstrap } from '\@vendure/core';
* import { config } from './vendure-config';
*
* bootstrap(config, {
* nestApplicationOptions: { // [!code highlight]
* snapshot: true, // [!code highlight]
* } // [!code highlight]
* }).catch(err => {
* console.log(err);
* process.exit(1);
* });
* ```
*
* ### Ignoring compatibility errors for plugins
*
* Since v3.1.0, you can ignore compatibility errors for specific plugins by passing the `ignoreCompatibilityErrorsForPlugins` option.
*
* This should be used with caution, only if you are sure that the plugin will still work as expected with the current version of Vendure.
*
* @example
* ```ts
* import { bootstrap } from '\@vendure/core';
* import { config } from './vendure-config';
* import { MyPlugin } from './plugins/my-plugin';
*
* bootstrap(config, {
* // Let's say that `MyPlugin` is not yet compatible with the current version of Vendure
* // but we know that it will still work as expected, and we are not able to publish
* // a new version of the plugin right now.
* ignoreCompatibilityErrorsForPlugins: [MyPlugin],
* });
* ```
*
* @docsCategory common
* @docsPage bootstrap
* @docsWeight 0
* */
export declare function bootstrap(userConfig: Partial<VendureConfig>, options?: BootstrapOptions): Promise<INestApplication>;
/**
* @description
* Bootstraps a Vendure worker. Resolves to a {@link VendureWorker} object containing a reference to the underlying
* NestJs [standalone application](https://docs.nestjs.com/standalone-applications) as well as convenience
* methods for starting the job queue.
*
* Read more about the [Vendure Worker](/developer-guide/worker-job-queue/).
*
* @example
* ```ts
* import { bootstrapWorker } from '\@vendure/core';
* import { config } from './vendure-config';
*
* bootstrapWorker(config)
* .then(worker => worker.startJobQueue())
* .catch(err => {
* console.log(err);
* process.exit(1);
* });
* ```
* @docsCategory worker
* @docsPage bootstrapWorker
* @docsWeight 0
* */
export declare function bootstrapWorker(userConfig: Partial<VendureConfig>, options?: BootstrapWorkerOptions): Promise<VendureWorker>;
/**
* Setting the global config must be done prior to loading the AppModule.
*/
export declare function preBootstrapConfig(userConfig: Partial<VendureConfig>): Promise<Readonly<RuntimeVendureConfig>>;
/**
* Run the configuration functions of all plugins and return the final config object.
*/
export declare function runPluginConfigurations(config: RuntimeVendureConfig): Promise<RuntimeVendureConfig>;
/**
* Returns an array of core entities and any additional entities defined in plugins.
*/
export declare function getAllEntities(userConfig: Partial<VendureConfig>): Array<Type<any>>;
export declare function configureSessionCookies(app: INestApplication, userConfig: Readonly<RuntimeVendureConfig>): void;