/* tslint:disable:no-console */ import { AdminUiPlugin } from '@vendure/admin-ui-plugin'; import { AssetServerPlugin } from '@vendure/asset-server-plugin'; import { ADMIN_API_PATH, API_PORT, SHOP_API_PATH } from '@vendure/common/lib/shared-constants'; import { DefaultJobQueuePlugin, DefaultLogger, DefaultSearchPlugin, examplePaymentHandler, FulfillmentHandler, LanguageCode, Logger, LogLevel, manualFulfillmentHandler, PermissionDefinition, VendureConfig, } from '@vendure/core'; import { ElasticsearchPlugin } from '@vendure/elasticsearch-plugin'; import { defaultEmailHandlers, EmailPlugin } from '@vendure/email-plugin'; import path from 'path'; import { ConnectionOptions } from 'typeorm'; const customFulfillmentHandler = new FulfillmentHandler({ code: 'ship-o-matic', description: [ { languageCode: LanguageCode.en, value: 'Generate tracking codes via the Ship-o-matic API', }, ], args: { preferredService: { type: 'string', ui: { component: 'select-form-input', options: [{ value: 'first_class' }, { value: 'priority' }, { value: 'standard' }], }, }, }, createFulfillment: async (ctx, orders, orderItems, args) => { return { method: `Ship-o-matic ${args.preferredService}`, trackingCode: 'SHIP-' + Math.random().toString(36).substr(3), }; }, onFulfillmentTransition: async (fromState, toState, { fulfillment }) => { Logger.info(`Transitioned Fulfillment ${fulfillment.trackingCode} to state ${toState}`); }, }); const pickupFulfillmentHandler = new FulfillmentHandler({ code: 'customer-collect', description: [ { languageCode: LanguageCode.en, value: 'Customer collect fulfillment', }, ], args: {}, createFulfillment: async (ctx, orders, orderItems, args) => { return { method: `Customer collect`, }; }, }); /** * Config settings used during development */ export const devConfig: VendureConfig = { apiOptions: { port: API_PORT, adminApiPath: ADMIN_API_PATH, adminApiPlayground: { settings: { 'request.credentials': 'include', } as any, }, adminApiDebug: true, shopApiPath: SHOP_API_PATH, shopApiPlayground: { settings: { 'request.credentials': 'include', } as any, }, shopApiDebug: true, }, authOptions: { disableAuth: false, tokenMethod: 'cookie', sessionSecret: 'some-secret', requireVerification: true, customPermissions: [], }, dbConnectionOptions: { synchronize: false, logging: false, migrations: [path.join(__dirname, 'migrations/*.ts')], ...getDbConfig(), }, paymentOptions: { paymentMethodHandlers: [examplePaymentHandler], }, customFields: {}, logger: new DefaultLogger({ level: LogLevel.Info }), importExportOptions: { importAssetsDir: path.join(__dirname, 'import-assets'), }, shippingOptions: { fulfillmentHandlers: [manualFulfillmentHandler, customFulfillmentHandler, pickupFulfillmentHandler], }, plugins: [ AssetServerPlugin.init({ route: 'assets', assetUploadDir: path.join(__dirname, 'assets'), port: 5002, }), DefaultSearchPlugin, DefaultJobQueuePlugin, // ElasticsearchPlugin.init({ // host: 'http://localhost', // port: 9200, // }), EmailPlugin.init({ devMode: true, handlers: defaultEmailHandlers, templatePath: path.join(__dirname, '../email-plugin/templates'), outputPath: path.join(__dirname, 'test-emails'), mailboxPort: 5003, globalTemplateVars: { verifyEmailAddressUrl: 'http://localhost:4201/verify', passwordResetUrl: 'http://localhost:4201/reset-password', changeEmailAddressUrl: 'http://localhost:4201/change-email-address', }, }), AdminUiPlugin.init({ port: 5001, }), ], }; function getDbConfig(): ConnectionOptions { const dbType = process.env.DB || 'mysql'; switch (dbType) { case 'postgres': console.log('Using postgres connection'); return { synchronize: true, type: 'postgres', host: '127.0.0.1', port: 5432, username: 'admin', password: 'secret', database: 'vendure-dev', }; case 'sqlite': console.log('Using sqlite connection'); return { synchronize: false, type: 'better-sqlite3', database: path.join(__dirname, 'vendure.sqlite'), }; case 'sqljs': console.log('Using sql.js connection'); return { type: 'sqljs', autoSave: true, database: new Uint8Array([]), location: path.join(__dirname, 'vendure.sqlite'), }; case 'mysql': default: console.log('Using mysql connection'); return { synchronize: true, type: 'mariadb', host: '127.0.0.1', port: 3306, username: 'root', password: '', database: 'vendure-dev', }; } }