From 1a81a8daee1eb5660864bff4e8b5290eb2280296 Mon Sep 17 00:00:00 2001 From: Pascal Kaufmann Date: Mon, 13 Jan 2025 13:46:28 +0100 Subject: [PATCH] Reduce logging and export new platform function to print the plugins --- .../advanced/write-plugins/payment-pricing.md | 3 -- docs/docs/advanced/write-plugins/quotation.md | 4 -- packages/api/src/api-index.ts | 6 --- packages/api/src/schema/index.ts | 15 +++++- .../src/module/configureWorkerModule.ts | 6 +-- packages/core/src/core-index.ts | 48 +++++++++++++++++++ .../core/src/directors/BaseDiscountAdapter.ts | 8 +--- .../core/src/directors/BasePricingAdapter.ts | 10 +--- .../core/src/directors/DeliveryAdapter.ts | 8 +--- .../core/src/directors/EnrollmentAdapter.ts | 9 +--- packages/core/src/directors/FilterAdapter.ts | 8 +--- .../core/src/directors/MessagingDirector.ts | 17 ++----- packages/core/src/directors/PaymentAdapter.ts | 8 +--- .../core/src/directors/QuotationAdapter.ts | 8 +--- .../core/src/directors/WarehousingAdapter.ts | 9 +--- packages/core/src/directors/WorkerAdapter.ts | 8 +--- packages/core/src/directors/WorkerDirector.ts | 8 +--- packages/events/src/EventDirector.ts | 2 - .../file-upload/src/director/FileAdapter.ts | 8 +--- .../platform/src/migrations/runMigrations.ts | 6 +-- packages/platform/src/platform-index.ts | 15 ++++++ packages/platform/src/startPlatform.ts | 20 ++++---- .../plugins/src/payment/paypal-checkout.ts | 4 +- packages/plugins/src/worker/BaseWorker.ts | 5 +- .../plugins/src/worker/error-notifications.ts | 2 +- packages/utils/src/director/BaseAdapter.ts | 9 +++- packages/utils/src/director/BaseDirector.ts | 7 --- 27 files changed, 129 insertions(+), 132 deletions(-) diff --git a/docs/docs/advanced/write-plugins/payment-pricing.md b/docs/docs/advanced/write-plugins/payment-pricing.md index bf0943b319..e923b7ca02 100644 --- a/docs/docs/advanced/write-plugins/payment-pricing.md +++ b/docs/docs/advanced/write-plugins/payment-pricing.md @@ -35,9 +35,6 @@ export const ShopCommission: IPaymentPricingAdapter = { isActivatedFor: (context: PaymentPricingAdapterContext): boolean => { return true; }, - log(message: string, options?: LogOptions): void { - console.log(message); - }, actions: (params: { calculationSheet: IPaymentPricingSheet; diff --git a/docs/docs/advanced/write-plugins/quotation.md b/docs/docs/advanced/write-plugins/quotation.md index f00a3f917c..af6bd4e748 100644 --- a/docs/docs/advanced/write-plugins/quotation.md +++ b/docs/docs/advanced/write-plugins/quotation.md @@ -69,10 +69,6 @@ export const ManualOffering: IQuotationAdapter = { }, }; }, - - log(message: string, { level = LogLevel.Debug, ...options } = {}) { - return log(message, { level, ...options }); - }, }; ``` diff --git a/packages/api/src/api-index.ts b/packages/api/src/api-index.ts index 513b1a3468..fea1462933 100644 --- a/packages/api/src/api-index.ts +++ b/packages/api/src/api-index.ts @@ -25,8 +25,6 @@ export type UnchainedServerOptions = { adminUiConfig?: AdminUiConfig; unchainedAPI: UnchainedCore; context?: (defaultResolver: UnchainedContextResolver) => UnchainedContextResolver; - events: Array; - workTypes: Array; } & GraphQLServerOptions; export const startAPIServer = async (options: UnchainedServerOptions) => { @@ -35,8 +33,6 @@ export const startAPIServer = async (options: UnchainedServerOptions) => { context: customContext, roles, adminUiConfig = {}, - events, - workTypes, typeDefs: additionalTypeDefs = [], resolvers: additionalResolvers = [], ...serverOptions @@ -56,8 +52,6 @@ export const startAPIServer = async (options: UnchainedServerOptions) => { typeDefs: [ ...buildDefaultTypeDefs({ actions: Object.keys(actions), - events, - workTypes, }), ...additionalTypeDefs, ], diff --git a/packages/api/src/schema/index.ts b/packages/api/src/schema/index.ts index 5e9a341d50..13fc603a87 100644 --- a/packages/api/src/schema/index.ts +++ b/packages/api/src/schema/index.ts @@ -4,8 +4,21 @@ import types from './types/index.js'; import inputTypes from './inputTypes.js'; import query from './query.js'; import mutation from './mutation.js'; +import { getRegisteredEvents } from '@unchainedshop/events'; +import { WorkerDirector } from '@unchainedshop/core'; +import { createLogger } from '@unchainedshop/logger'; + +const logger = createLogger('unchained:api'); + +export const buildDefaultTypeDefs = ({ actions = [] }) => { + logger.debug(`${actions.length} role actions added to GraphQL schema`, { actions }); + + const events = getRegisteredEvents() || []; + logger.debug(`${events.length} event types added to GraphQL schema`, { events }); + + const workTypes = WorkerDirector.getActivePluginTypes() || []; + logger.debug(`${workTypes.length} work types added to GraphQL schema`, { workTypes }); -export const buildDefaultTypeDefs = ({ actions = [], events = [], workTypes = [] }) => { const dynamicTypeDefs = [ actions?.length && `extend enum RoleAction { ${actions.join(',')} }`, events?.length && `extend enum EventType { ${events.join(',')} }`, diff --git a/packages/core-worker/src/module/configureWorkerModule.ts b/packages/core-worker/src/module/configureWorkerModule.ts index c271beb1a8..19081d7603 100644 --- a/packages/core-worker/src/module/configureWorkerModule.ts +++ b/packages/core-worker/src/module/configureWorkerModule.ts @@ -272,7 +272,7 @@ export const configureWorkerModule = async ({ const duration = new Date(work.finished).getTime() - new Date(work.started).getTime(); if (work.success) { - logger.info(`${work.type} finished with success (${duration}ms)`, { + logger.debug(`${work.type} finished with success (${duration}ms)`, { workId, worker, }); @@ -422,7 +422,7 @@ export const configureWorkerModule = async ({ worker, }); - logger.info(`${type} scheduled @ ${new Date(scheduled || created).toISOString()}`, { + logger.debug(`${type} scheduled @ ${new Date(scheduled || created).toISOString()}`, { workId, }); @@ -532,7 +532,7 @@ export const configureWorkerModule = async ({ ); if (!result.lastErrorObject.updatedExisting) { - logger.info(`${type} auto-scheduled @ ${new Date(scheduled).toISOString()}`, { + logger.debug(`${type} auto-scheduled @ ${new Date(scheduled).toISOString()}`, { workId, }); emit(WorkerEventTypes.ADDED, removePrivateFields(result.value)); diff --git a/packages/core/src/core-index.ts b/packages/core/src/core-index.ts index efe759bd67..ee5cdd0fa3 100644 --- a/packages/core/src/core-index.ts +++ b/packages/core/src/core-index.ts @@ -2,6 +2,22 @@ import { mongodb, MigrationRepository, ModuleInput } from '@unchainedshop/mongod import initServices, { CustomServices, Services } from './services/index.js'; import initModules, { Modules, ModuleOptions } from './modules.js'; +import { + WorkerDirector, + DeliveryDirector, + DeliveryPricingDirector, + EnrollmentDirector, + FilterDirector, + OrderDiscountDirector, + OrderPricingDirector, + PaymentDirector, + PaymentPricingDirector, + ProductDiscountDirector, + ProductPricingDirector, + QuotationDirector, + WarehousingDirector, +} from './directors/index.js'; + export * from './services/index.js'; export * from './directors/index.js'; @@ -50,3 +66,35 @@ export const initCore = async ({ options, }; }; + +export const getAllAdapters = () => { + const worker = WorkerDirector.getAdapters(); + const delivery = DeliveryDirector.getAdapters(); + const deliveryPricing = DeliveryPricingDirector.getAdapters(); + const enrollment = EnrollmentDirector.getAdapters(); + const filter = FilterDirector.getAdapters(); + const orderDiscount = OrderDiscountDirector.getAdapters(); + const orderPricing = OrderPricingDirector.getAdapters(); + const payment = PaymentDirector.getAdapters(); + const paymentPricing = PaymentPricingDirector.getAdapters(); + const productDiscount = ProductDiscountDirector.getAdapters(); + const productPricing = ProductPricingDirector.getAdapters(); + const quotation = QuotationDirector.getAdapters(); + const warehousing = WarehousingDirector.getAdapters(); + + return [].concat( + worker, + delivery, + deliveryPricing, + enrollment, + filter, + orderDiscount, + orderPricing, + payment, + paymentPricing, + productDiscount, + productPricing, + quotation, + warehousing, + ); +}; diff --git a/packages/core/src/directors/BaseDiscountAdapter.ts b/packages/core/src/directors/BaseDiscountAdapter.ts index 3c5517d193..bae21b2151 100644 --- a/packages/core/src/directors/BaseDiscountAdapter.ts +++ b/packages/core/src/directors/BaseDiscountAdapter.ts @@ -1,5 +1,4 @@ -import { log, LogLevel } from '@unchainedshop/logger'; -import { IBaseAdapter } from '@unchainedshop/utils'; +import { BaseAdapter, IBaseAdapter } from '@unchainedshop/utils'; import { IPricingSheet } from './BasePricingSheet.js'; import { PricingCalculation } from '@unchainedshop/utils'; import { Order, OrderDiscount } from '@unchainedshop/core-orders'; @@ -35,6 +34,7 @@ export interface DiscountAdapterActions { } export const BaseDiscountAdapter: Omit, 'key' | 'label' | 'version'> = { + ...BaseAdapter, orderIndex: 0, isManualAdditionAllowed: async () => { @@ -83,8 +83,4 @@ export const BaseDiscountAdapter: Omit, 'key' | 'label return null; }, }), - - log(message: string, { level = LogLevel.Debug, ...options } = {}) { - return log(message, { level, ...options }); - }, }; diff --git a/packages/core/src/directors/BasePricingAdapter.ts b/packages/core/src/directors/BasePricingAdapter.ts index 0e20410b2c..ea2137a31d 100644 --- a/packages/core/src/directors/BasePricingAdapter.ts +++ b/packages/core/src/directors/BasePricingAdapter.ts @@ -1,11 +1,8 @@ -import { createLogger } from '@unchainedshop/logger'; import { IPricingSheet } from './BasePricingSheet.js'; -import { IBaseAdapter, PricingCalculation } from '@unchainedshop/utils'; +import { BaseAdapter, IBaseAdapter, PricingCalculation } from '@unchainedshop/utils'; import { Discount } from './BasePricingDirector.js'; import { Order, OrderDiscount } from '@unchainedshop/core-orders'; -const logger = createLogger('unchained:core'); - interface IDiscountableItem { _id?: string; orderId?: string; @@ -54,6 +51,7 @@ export const BasePricingAdapter = < PricingAdapterContext extends BasePricingAdapterContext, Calculation extends PricingCalculation, >(): IPricingAdapter> => ({ + ...BaseAdapter, key: '', label: '', version: '', @@ -73,8 +71,4 @@ export const BasePricingAdapter = < }, // abstract }; }, - - log(message: string, options) { - return logger.debug(message, options); - }, }); diff --git a/packages/core/src/directors/DeliveryAdapter.ts b/packages/core/src/directors/DeliveryAdapter.ts index 68cc47b1c1..f57b2e5427 100644 --- a/packages/core/src/directors/DeliveryAdapter.ts +++ b/packages/core/src/directors/DeliveryAdapter.ts @@ -1,5 +1,4 @@ -import { log, LogLevel } from '@unchainedshop/logger'; -import { IBaseAdapter } from '@unchainedshop/utils'; +import { BaseAdapter, IBaseAdapter } from '@unchainedshop/utils'; import type { Order, OrderPosition, OrderDelivery } from '@unchainedshop/core-orders'; import type { Product } from '@unchainedshop/core-products'; import type { WarehousingProvider } from '@unchainedshop/core-warehousing'; @@ -57,6 +56,7 @@ export type IDeliveryAdapter = IBaseAdapter & { }; export const DeliveryAdapter: Omit = { + ...BaseAdapter, initialConfiguration: [], typeSupported: () => { @@ -103,8 +103,4 @@ export const DeliveryAdapter: Omit { - return log(message, { level, ...options }); - }, }; diff --git a/packages/core/src/directors/EnrollmentAdapter.ts b/packages/core/src/directors/EnrollmentAdapter.ts index 6cbae2b662..ac944688ef 100644 --- a/packages/core/src/directors/EnrollmentAdapter.ts +++ b/packages/core/src/directors/EnrollmentAdapter.ts @@ -1,5 +1,4 @@ -import { IBaseAdapter } from '@unchainedshop/utils'; -import { log, LogLevel } from '@unchainedshop/logger'; +import { BaseAdapter, IBaseAdapter } from '@unchainedshop/utils'; import { Enrollment, EnrollmentPeriod, @@ -52,6 +51,7 @@ export const periodForReferenceDate = (referenceDate: Date, intervalCount = 1, i }; export const EnrollmentAdapter: Omit = { + ...BaseAdapter, isActivatedFor: () => { return false; }, @@ -105,9 +105,4 @@ export const EnrollmentAdapter: Omit = { + ...BaseAdapter, orderIndex: 0, actions: () => { @@ -96,8 +96,4 @@ export const FilterAdapter: Omit = }, }; }, - - log(message: string, { level = LogLevel.Debug, ...options } = {}) { - return log(message, { level, ...options }); - }, }; diff --git a/packages/core/src/directors/MessagingDirector.ts b/packages/core/src/directors/MessagingDirector.ts index 5d7b28ebc5..e34f19fa1a 100644 --- a/packages/core/src/directors/MessagingDirector.ts +++ b/packages/core/src/directors/MessagingDirector.ts @@ -1,5 +1,3 @@ -import { log } from '@unchainedshop/logger'; - export type EmailTemplateType = { type: 'EMAIL'; input: { @@ -41,19 +39,14 @@ export type TemplateResolver = ( unchainedAPI, ) => Promise>; -export type IMessagingDirector = { - registerTemplate: (templateName: string, templateResolver: TemplateResolver) => void; - getTemplate: (templateName: string) => TemplateResolver; -}; - const TemplateResolvers = new Map(); -export const MessagingDirector: IMessagingDirector = { - registerTemplate: (templateName, templateResolver) => { - log(`MessagingDirector -> Registered template resolver for ${templateName}`); - +export const MessagingDirector = { + registerTemplate: (templateName: string, templateResolver: TemplateResolver) => { TemplateResolvers.set(templateName, templateResolver); }, - getTemplate: (templateName) => TemplateResolvers.get(templateName), + getTemplate: (templateName: string) => TemplateResolvers.get(templateName), + + getRegisteredTemplates: () => Array.from(TemplateResolvers.keys()), }; diff --git a/packages/core/src/directors/PaymentAdapter.ts b/packages/core/src/directors/PaymentAdapter.ts index 4d000ca67c..b550241b98 100644 --- a/packages/core/src/directors/PaymentAdapter.ts +++ b/packages/core/src/directors/PaymentAdapter.ts @@ -1,5 +1,4 @@ -import { log, LogLevel } from '@unchainedshop/logger'; -import { IBaseAdapter } from '@unchainedshop/utils'; +import { BaseAdapter, IBaseAdapter } from '@unchainedshop/utils'; import { Order, OrderPayment } from '@unchainedshop/core-orders'; import { PaymentConfiguration, PaymentProvider, PaymentProviderType } from '@unchainedshop/core-payment'; import { Modules } from '../modules.js'; @@ -58,6 +57,7 @@ export type IPaymentAdapter = IBaseAdapter & { }; export const PaymentAdapter: Omit = { + ...BaseAdapter, initialConfiguration: [], typeSupported: () => { @@ -111,8 +111,4 @@ export const PaymentAdapter: Omit }, }; }, - - log(message: string, { level = LogLevel.Debug, ...options } = {}) { - return log(message, { level, ...options }); - }, }; diff --git a/packages/core/src/directors/QuotationAdapter.ts b/packages/core/src/directors/QuotationAdapter.ts index b548d7ec94..958e0ffb27 100644 --- a/packages/core/src/directors/QuotationAdapter.ts +++ b/packages/core/src/directors/QuotationAdapter.ts @@ -3,8 +3,7 @@ import { QuotationItemConfiguration, QuotationProposal, } from '@unchainedshop/core-quotations'; -import { log, LogLevel } from '@unchainedshop/logger'; -import { IBaseAdapter } from '@unchainedshop/utils'; +import { BaseAdapter, IBaseAdapter } from '@unchainedshop/utils'; export type QuotationContext = { quotation?: Quotation; @@ -38,6 +37,7 @@ export enum QuotationError { } export const QuotationAdapter: Omit = { + ...BaseAdapter, orderIndex: 0, isActivatedFor: () => { @@ -79,8 +79,4 @@ export const QuotationAdapter: Omit = { + ...BaseAdapter, orderIndex: 0, typeSupported: () => { @@ -75,9 +75,4 @@ export const WarehousingAdapter: Omit true, }; }, - - log(message, { level = LogLevel.Debug, ...options } = {}) { - // eslint-disable-line - return log(message, { level, ...options }); - }, }; diff --git a/packages/core/src/directors/WorkerAdapter.ts b/packages/core/src/directors/WorkerAdapter.ts index 74bd127657..ea1196512a 100644 --- a/packages/core/src/directors/WorkerAdapter.ts +++ b/packages/core/src/directors/WorkerAdapter.ts @@ -1,5 +1,4 @@ -import { log, LogLevel } from '@unchainedshop/logger'; -import { IBaseAdapter } from '@unchainedshop/utils'; +import { BaseAdapter, IBaseAdapter } from '@unchainedshop/utils'; import { WorkResult } from '@unchainedshop/core-worker'; import { Modules } from '../modules.js'; import { Services } from '../services/index.js'; @@ -18,13 +17,10 @@ export type IWorkerAdapter = IBaseAdapter & { }; export const WorkerAdapter: Omit, 'key' | 'label' | 'type' | 'version'> = { + ...BaseAdapter, external: false, async doWork() { return { success: false, result: null }; }, - - log(message: string, { level = LogLevel.Debug, ...options } = {}) { - return log(message, { level, ...options }); - }, }; diff --git a/packages/core/src/directors/WorkerDirector.ts b/packages/core/src/directors/WorkerDirector.ts index c9c23f4983..5e68df63da 100644 --- a/packages/core/src/directors/WorkerDirector.ts +++ b/packages/core/src/directors/WorkerDirector.ts @@ -73,14 +73,10 @@ export const WorkerDirector: IWorkerDirector = { }, configureAutoscheduling: (workItemConfiguration) => { - const adapter = WorkerDirector.getAdapterByType(workItemConfiguration.type); AutoScheduleMap.set( workItemConfiguration.scheduleId || workItemConfiguration.type, workItemConfiguration, ); - logger.info( - `WorkerDirector -> Configured ${adapter.type} ${adapter.key}@${adapter.version} (${adapter.label}) for Autorun at ${JSON.stringify(workItemConfiguration.schedule?.schedules)}`, - ); }, getAutoSchedules: () => Array.from(AutoScheduleMap), @@ -98,7 +94,7 @@ export const WorkerDirector: IWorkerDirector = { const adapter = WorkerDirector.getAdapterByType(type); if (!adapter) { - logger.info(`WorkerDirector: No registered adapter for type: ${type}`); + logger.warn(`WorkerDirector: No registered adapter for type: ${type}`); } try { @@ -107,7 +103,7 @@ export const WorkerDirector: IWorkerDirector = { } catch (error) { // DO not use this as flow control. The adapter should catch expected errors and return status: FAILED logger.debug('DO not use this as flow control.'); - logger.info(`WorkerDirector -> Error doing work ${type}: ${error.message}`); + logger.error(`WorkerDirector -> Error doing work ${type}: ${error.message}`); const errorOutput = { error, success: false }; return errorOutput; diff --git a/packages/events/src/EventDirector.ts b/packages/events/src/EventDirector.ts index 1646c2c6e2..88630db8b0 100644 --- a/packages/events/src/EventDirector.ts +++ b/packages/events/src/EventDirector.ts @@ -44,7 +44,6 @@ export const EventDirector = { registerEvents: (events: string[]): void => { if (events.length) { events.forEach((e) => RegisteredEventsSet.add(e)); - logger.info(`EventDirector -> Registered ${JSON.stringify(events)}`); } }, @@ -99,7 +98,6 @@ export const EventDirector = { Adapter?.subscribe(eventName, callback); HistoryAdapter?.subscribe(eventName, callback); RegisteredCallbacksSet.add(currentSubscription); - logger.debug(`EventDirector -> Subscribed to ${eventName}`); } }, }; diff --git a/packages/file-upload/src/director/FileAdapter.ts b/packages/file-upload/src/director/FileAdapter.ts index f39846d149..4dc1cb0d6f 100644 --- a/packages/file-upload/src/director/FileAdapter.ts +++ b/packages/file-upload/src/director/FileAdapter.ts @@ -1,6 +1,5 @@ import type { Readable } from 'node:stream'; -import { log, LogLevel } from '@unchainedshop/logger'; -import { IBaseAdapter } from '@unchainedshop/utils'; +import { BaseAdapter, IBaseAdapter } from '@unchainedshop/utils'; import { UploadedFile, UploadFileData } from '../types.js'; export interface IFileAdapter extends IBaseAdapter { @@ -29,6 +28,7 @@ export interface IFileAdapter extends IBaseAdapter { createDownloadStream: (file: UploadedFile, unchainedAPI: Context) => Promise; } export const FileAdapter: Omit = { + ...BaseAdapter, async createDownloadURL() { throw new Error('Method not implemented'); }, @@ -58,8 +58,4 @@ export const FileAdapter: Omit = { resolve(null); }); }, - - log(message: string, { level = LogLevel.Debug, ...options } = {}) { - return log(message, { level, ...options }); - }, }; diff --git a/packages/platform/src/migrations/runMigrations.ts b/packages/platform/src/migrations/runMigrations.ts index fc22b974e7..e459d44550 100644 --- a/packages/platform/src/migrations/runMigrations.ts +++ b/packages/platform/src/migrations/runMigrations.ts @@ -17,7 +17,7 @@ export const runMigrations = async ({ const findCurrentId = async () => { const last = await LastMigration.findOne({ category: 'unchained' }, { sort: { _id: -1 } }); const id = last ? last._id : 0; - logger.info(`Most recent migration id: ${id}`); + logger.debug(`Most recent migration id: ${id}`); return id; }; @@ -55,9 +55,9 @@ export const runMigrations = async ({ if (operationCount > 0) { logger.info(`All ${operationCount} migrations completed with most recent id: ${lastMigrationId}`); } else { - logger.info(`No migrations run, already at latest id: ${currentId}`); + logger.debug(`No migrations run, already at latest id: ${currentId}`); } } else { - logger.info(`Some migrations failed, last successful id: ${lastMigrationId}`); + logger.warn(`Some migrations failed, last successful id: ${lastMigrationId}`); } }; diff --git a/packages/platform/src/platform-index.ts b/packages/platform/src/platform-index.ts index 688fb7a821..3e3c80249d 100644 --- a/packages/platform/src/platform-index.ts +++ b/packages/platform/src/platform-index.ts @@ -2,3 +2,18 @@ export * from './startPlatform.js'; export * from './context/index.js'; export * from './bulk-importer/createBulkImporter.js'; export * from './templates/index.js'; + +import { MessagingDirector, getAllAdapters } from '@unchainedshop/core'; +import { getRegisteredEvents } from '@unchainedshop/events'; +import { log } from '@unchainedshop/logger'; + +export const printRuntimeConfiguration = () => { + const messaging = MessagingDirector.getRegisteredTemplates(); + log(`Messaging Templates: ${messaging.length}`, { messaging }); + + const events = getRegisteredEvents(); + log(`Events: ${events.length}`, { events }); + + const adapters = getAllAdapters().map((adapter) => adapter.asString()); + log(`Adapters: ${adapters.length}`, { adapters }); +}; diff --git a/packages/platform/src/startPlatform.ts b/packages/platform/src/startPlatform.ts index c2d766e01c..eb0d27e4c3 100644 --- a/packages/platform/src/startPlatform.ts +++ b/packages/platform/src/startPlatform.ts @@ -1,10 +1,8 @@ import { startAPIServer, roles, UnchainedServerOptions } from '@unchainedshop/api'; import { initCore, UnchainedCoreOptions } from '@unchainedshop/core'; import { initDb, mongodb } from '@unchainedshop/mongodb'; -import { createLogger } from '@unchainedshop/logger'; +import { defaultLogger } from '@unchainedshop/logger'; import { UnchainedCore } from '@unchainedshop/core'; -import { getRegisteredEvents } from '@unchainedshop/events'; -import { WorkerDirector } from '@unchainedshop/core'; import { BulkImportHandler, createBulkImporterFactory } from './bulk-importer/createBulkImporter.js'; import { runMigrations } from './migrations/runMigrations.js'; import { setupAccounts } from './setup/setupAccounts.js'; @@ -24,9 +22,7 @@ export type PlatformOptions = { rolesOptions?: IRoleOptionConfig; workQueueOptions?: SetupWorkqueueOptions & SetupCartsOptions & { skipInvalidationOnStartup?: boolean }; } & Omit & - Omit; - -const logger = createLogger('unchained'); + Omit; const REQUIRED_ENV_VARIABLES = [ 'EMAIL_WEBSITE_NAME', @@ -41,7 +37,7 @@ const { UNCHAINED_DISABLE_WORKER } = process.env; const exitOnMissingEnvironmentVariables = () => { const failedEnv = REQUIRED_ENV_VARIABLES.filter((key) => !process.env[key]); if (failedEnv.length > 0) { - logger.error(`Missing required environment variables at boot time: ${failedEnv.join(', ')}`); + defaultLogger.error(`Missing required environment variables at boot time: ${failedEnv.join(', ')}`); process.exit(1); } }; @@ -93,9 +89,6 @@ export const startPlatform = async ({ await runMigrations({ migrationRepository, unchainedAPI }); } - const configuredEvents = getRegisteredEvents(); - const configuredWorkTypes = WorkerDirector.getActivePluginTypes(); - // Setup accountsjs specific extensions and event handlers setupAccounts(unchainedAPI); @@ -109,8 +102,6 @@ export const startPlatform = async ({ const graphqlHandler = await startAPIServer({ unchainedAPI, roles: configuredRoles, - events: configuredEvents, - workTypes: configuredWorkTypes, ...arbitraryAPIServerConfiguration, }); @@ -126,5 +117,10 @@ export const startPlatform = async ({ setImmediate(() => unchainedAPI.services.filters.invalidateFilterCache()); } + const { default: packageJson } = await import(`${import.meta.dirname}/../package.json`, { + with: { type: 'json' }, + }); + defaultLogger.info(`Unchained Engine running`, { version: packageJson.version }); + return { unchainedAPI, graphqlHandler, db }; }; diff --git a/packages/plugins/src/payment/paypal-checkout.ts b/packages/plugins/src/payment/paypal-checkout.ts index 3482cfd1a2..27adebcdfe 100644 --- a/packages/plugins/src/payment/paypal-checkout.ts +++ b/packages/plugins/src/payment/paypal-checkout.ts @@ -38,9 +38,9 @@ const environment = () => { const PaypalCheckout: IPaymentAdapter = { ...PaymentAdapter, - key: 'com.paypal.checkout', + key: 'shop.unchained.payment.paypal', label: 'Paypal', - version: '1.0.0', + version: '1.0.1', initialConfiguration: [], diff --git a/packages/plugins/src/worker/BaseWorker.ts b/packages/plugins/src/worker/BaseWorker.ts index 34ce337bd8..88ff06244a 100644 --- a/packages/plugins/src/worker/BaseWorker.ts +++ b/packages/plugins/src/worker/BaseWorker.ts @@ -1,5 +1,4 @@ import later from '@breejs/later'; -import { log } from '@unchainedshop/logger'; import { Work, WorkData } from '@unchainedshop/core-worker'; import { WorkerDirector } from '@unchainedshop/core'; @@ -41,9 +40,7 @@ export const BaseWorker: IWorker = { return floored; }, - actions: ({ workerId, worker }: WorkerParams, unchainedAPI) => { - log(`${worker.key} -> Initialized ${worker.type}`); - + actions: ({ workerId }: WorkerParams, unchainedAPI) => { const workerActions = { start() { throw new Error(`Not implemented on ${this.constructor.key}`); diff --git a/packages/plugins/src/worker/error-notifications.ts b/packages/plugins/src/worker/error-notifications.ts index 83d7a70892..c592f11a46 100644 --- a/packages/plugins/src/worker/error-notifications.ts +++ b/packages/plugins/src/worker/error-notifications.ts @@ -15,7 +15,7 @@ const everyDayAtFourInTheNight = later.parse.cron('0 3 * * *'); export const ErrorNotifications: IWorkerAdapter = { ...WorkerAdapter, - key: 'ch.unchained.worker.error-notifications', + key: 'shop.unchained.worker.error-notifications', label: 'Send a daily report about errors that failed permanently/unrecoverable', version: '1.0', diff --git a/packages/utils/src/director/BaseAdapter.ts b/packages/utils/src/director/BaseAdapter.ts index 542aaee010..b503b48979 100644 --- a/packages/utils/src/director/BaseAdapter.ts +++ b/packages/utils/src/director/BaseAdapter.ts @@ -1,9 +1,10 @@ -import { log, LogLevel } from '@unchainedshop/logger'; +import { defaultLogger, LogLevel } from '@unchainedshop/logger'; export interface IBaseAdapter { key: string; label: string; version: string; + asString: () => string; log: ( message: string, options?: { @@ -15,6 +16,10 @@ export interface IBaseAdapter { export const BaseAdapter: Omit = { log(message: string, { level = LogLevel.Debug, ...options } = {}) { - return log(message, { level, ...options }); + defaultLogger[level](message, options); + }, + + asString() { + return `${this.key}@${this.version}`; }, }; diff --git a/packages/utils/src/director/BaseDirector.ts b/packages/utils/src/director/BaseDirector.ts index 1ee783a4de..78180af452 100644 --- a/packages/utils/src/director/BaseDirector.ts +++ b/packages/utils/src/director/BaseDirector.ts @@ -1,4 +1,3 @@ -import { log } from '@unchainedshop/logger'; import { IBaseAdapter } from './BaseAdapter.js'; export interface IBaseDirector { @@ -31,16 +30,10 @@ export const BaseDirector = ( }, registerAdapter: (Adapter) => { - log( - `${directorName} -> Registered ${keyField !== 'key' ? `${Adapter[keyField]}` : ''} ${ - Adapter.key - } ${Adapter.version} (${Adapter.label})`, - ); Adapters.set(Adapter[keyField], Adapter); }, unregisterAdapter: (key) => { - log(`${directorName} -> Unregistered ${key}`); return Adapters.delete(key); }, };