Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
UpdateAddress,
UpdateCustomer,
} from './graphql/generated-e2e-admin-types';
import { AddItemToOrder } from './graphql/generated-e2e-shop-types';
import { GET_CUSTOMER, GET_CUSTOMER_LIST } from './graphql/shared-definitions';
import { ADD_ITEM_TO_ORDER } from './graphql/shop-definitions';
import { assertThrowsWithMessage } from './utils/assert-throws-with-message';
// tslint:disable:no-non-null-assertion
let sendEmailFn: jest.Mock;
/**
* This mock plugin simulates an EmailPlugin which would send emails
* on the registration & password reset events.
*/
@VendurePlugin({
imports: [EventBusModule],
})
class TestEmailPlugin implements OnModuleInit {
constructor(private eventBus: EventBus) {}
onModuleInit() {
this.eventBus.ofType(AccountRegistrationEvent).subscribe(event => {
sendEmailFn(event);
});
}
}
describe('Customer resolver', () => {
const { server, adminClient, shopClient } = createTestEnvironment(
mergeConfig(testConfig, { plugins: [TestEmailPlugin] }),
);
*
* @example
* ```ts
* import { AdminUiPlugin } from '\@vendure/admin-ui-plugin';
*
* const config: VendureConfig = {
* // Add an instance of the plugin to the plugins array
* plugins: [
* AdminUiPlugin.init({ port: 3002 }),
* ],
* };
* ```
*
* @docsCategory AdminUiPlugin
*/
@VendurePlugin({
imports: [PluginCommonModule],
providers: [UiAppCompiler],
configuration: config => AdminUiPlugin.configure(config),
})
export class AdminUiPlugin implements OnVendureBootstrap, OnVendureClose {
private static options: AdminUiOptions;
private server: Server;
private watcher: Watcher | undefined;
constructor(private configService: ConfigService, private appCompiler: UiAppCompiler) {}
/**
* @description
* Set the plugin options
*/
static init(options: AdminUiOptions): Type {
* "score": 30.58831,
* "price": {
* "min": 4984,
* "max": 4984
* }
* },
* // ... truncated
* ]
* }
* }
*}
* ```
*
* @docsCategory ElasticsearchPlugin
*/
@VendurePlugin({
imports: [PluginCommonModule],
providers: [
ElasticsearchIndexService,
ElasticsearchService,
{ provide: ELASTIC_SEARCH_OPTIONS, useFactory: () => ElasticsearchPlugin.options },
{ provide: ELASTIC_SEARCH_CLIENT, useFactory: () => ElasticsearchPlugin.client },
],
adminApiExtensions: { resolvers: [AdminElasticSearchResolver] },
shopApiExtensions: {
resolvers: () => {
const { options } = ElasticsearchPlugin;
const requiresUnionResolver =
0 < Object.keys(options.customProductMappings || {}).length &&
0 < Object.keys(options.customProductVariantMappings || {}).length;
return requiresUnionResolver
? [ShopElasticSearchResolver, CustomMappingsResolver]
REGISTER_ACCOUNT,
REQUEST_PASSWORD_RESET,
REQUEST_UPDATE_EMAIL_ADDRESS,
RESET_PASSWORD,
UPDATE_EMAIL_ADDRESS,
VERIFY_EMAIL,
} from './graphql/shop-definitions';
import { assertThrowsWithMessage } from './utils/assert-throws-with-message';
let sendEmailFn: jest.Mock;
/**
* This mock plugin simulates an EmailPlugin which would send emails
* on the registration & password reset events.
*/
@VendurePlugin({
imports: [EventBusModule],
})
class TestEmailPlugin implements OnModuleInit {
constructor(private eventBus: EventBus) {}
onModuleInit() {
this.eventBus.ofType(AccountRegistrationEvent).subscribe(event => {
sendEmailFn(event);
});
this.eventBus.ofType(PasswordResetEvent).subscribe(event => {
sendEmailFn(event);
});
this.eventBus.ofType(IdentifierChangeRequestEvent).subscribe(event => {
sendEmailFn(event);
});
this.eventBus.ofType(IdentifierChangeEvent).subscribe(event => {
sendEmailFn(event);
import { AdminUiExtension } from '@vendure/common/lib/shared-types';
import { VendurePlugin } from '@vendure/core';
import path from 'path';
@VendurePlugin({})
export class UiPlugin {
static uiExtensions: AdminUiExtension[] = [
{
extensionPath: path.join(__dirname, 'extensions'),
ngModules: [
{
type: 'lazy',
ngModuleFileName: 'ui-plugin.module.ts',
ngModuleName: 'TestModule',
},
{
type: 'shared',
ngModuleFileName: 'ui-shared-plugin.module.ts',
ngModuleName: 'TestSharedModule',
},
],
* devMode: true,
* handlers: defaultEmailHandlers,
* templatePath: path.join(__dirname, 'vendure/email/templates'),
* outputPath: path.join(__dirname, 'test-emails'),
* mailboxPort: 5003,
* })
* ```
*
* ### Dev mailbox
*
* In dev mode, specifying the optional `mailboxPort` will start a webmail-like interface available at the `/mailbox` path, e.g.
* http://localhost:3000/mailbox. This is a simple way to view the output of all emails generated by the EmailPlugin while in dev mode.
*
* @docsCategory EmailPlugin
*/
@VendurePlugin({
imports: [PluginCommonModule],
configuration: config => EmailPlugin.configure(config),
})
export class EmailPlugin implements OnVendureBootstrap, OnVendureClose {
private static options: EmailPluginOptions | EmailPluginDevModeOptions;
private transport: EmailTransportOptions;
private templateLoader: TemplateLoader;
private emailSender: EmailSender;
private generator: HandlebarsMjmlGenerator;
private devMailbox: DevMailbox | undefined;
/** @internal */
constructor(
private eventBus: EventBus,
@InjectConnection() private connection: Connection,
private moduleRef: ModuleRef,
*
* `http://localhost:3000/assets/some-asset.jpg?w=85&h=85&mode=crop`
*
* The AssetServerPlugin comes pre-configured with the following presets:
*
* name | width | height | mode
* -----|-------|--------|-----
* tiny | 50px | 50px | crop
* thumb | 150px | 150px | crop
* small | 300px | 300px | resize
* medium | 500px | 500px | resize
* large | 800px | 800px | resize
*
* @docsCategory AssetServerPlugin
*/
@VendurePlugin({
configuration: config => AssetServerPlugin.configure(config),
})
export class AssetServerPlugin implements OnVendureBootstrap, OnVendureClose {
private server: Server;
private static assetStorage: AssetStorageStrategy;
private readonly cacheDir = 'cache';
private presets: ImageTransformPreset[] = [
{ name: 'tiny', width: 50, height: 50, mode: 'crop' },
{ name: 'thumb', width: 150, height: 150, mode: 'crop' },
{ name: 'small', width: 300, height: 300, mode: 'resize' },
{ name: 'medium', width: 500, height: 500, mode: 'resize' },
{ name: 'large', width: 800, height: 800, mode: 'resize' },
];
private static options: AssetServerOptions;
/**