diff --git a/packages/core/src/bootstrap.ts b/packages/core/src/bootstrap.ts index 43cfa3c3de..643de956ad 100644 --- a/packages/core/src/bootstrap.ts +++ b/packages/core/src/bootstrap.ts @@ -147,6 +147,9 @@ export async function preBootstrapConfig( }); let config = getConfig(); + // The logger is set here so that we are able to log any messages prior to the final + // logger (which may depend on config coming from a plugin) being set. + Logger.useLogger(config.logger); config = await runPluginConfigurations(config); const entityIdStrategy = config.entityOptions.entityIdStrategy ?? config.entityIdStrategy; setEntityIdStrategy(entityIdStrategy, entities); diff --git a/packages/core/src/entity/register-custom-entity-fields.ts b/packages/core/src/entity/register-custom-entity-fields.ts index 6d7b357d76..3c90ae44d7 100644 --- a/packages/core/src/entity/register-custom-entity-fields.ts +++ b/packages/core/src/entity/register-custom-entity-fields.ts @@ -255,32 +255,70 @@ function getDefault(customField: CustomFieldConfig, dbEngine: DataSourceOptions[ return type === 'datetime' ? formatDefaultDatetime(dbEngine, defaultValue) : defaultValue; } +function assertLocaleFieldsNotSpecified(config: VendureConfig, entityName: keyof CustomFields) { + const customFields = config.customFields && config.customFields[entityName]; + if (customFields) { + for (const customField of customFields) { + if (customField.type === 'localeString' || customField.type === 'localeText') { + Logger.error( + `Custom field "${customField.name}" on entity "${entityName}" cannot be of type "localeString" or "localeText". ` + + `This entity does not support localization.`, + ); + } + } + } +} + /** * Dynamically registers any custom fields with TypeORM. This function should be run at the bootstrap * stage of the app lifecycle, before the AppModule is initialized. */ export function registerCustomEntityFields(config: VendureConfig) { registerCustomFieldsForEntity(config, 'Address', CustomAddressFields); + assertLocaleFieldsNotSpecified(config, 'Address'); + registerCustomFieldsForEntity(config, 'Administrator', CustomAdministratorFields); + assertLocaleFieldsNotSpecified(config, 'Administrator'); + registerCustomFieldsForEntity(config, 'Asset', CustomAssetFields); + assertLocaleFieldsNotSpecified(config, 'Asset'); + registerCustomFieldsForEntity(config, 'Collection', CustomCollectionFields); registerCustomFieldsForEntity(config, 'Collection', CustomCollectionFieldsTranslation, true); + registerCustomFieldsForEntity(config, 'Channel', CustomChannelFields); + assertLocaleFieldsNotSpecified(config, 'Channel'); + registerCustomFieldsForEntity(config, 'Customer', CustomCustomerFields); + assertLocaleFieldsNotSpecified(config, 'Customer'); + registerCustomFieldsForEntity(config, 'CustomerGroup', CustomCustomerGroupFields); + assertLocaleFieldsNotSpecified(config, 'CustomerGroup'); + registerCustomFieldsForEntity(config, 'Facet', CustomFacetFields); registerCustomFieldsForEntity(config, 'Facet', CustomFacetFieldsTranslation, true); + registerCustomFieldsForEntity(config, 'FacetValue', CustomFacetValueFields); registerCustomFieldsForEntity(config, 'FacetValue', CustomFacetValueFieldsTranslation, true); + registerCustomFieldsForEntity(config, 'Fulfillment', CustomFulfillmentFields); + assertLocaleFieldsNotSpecified(config, 'Fulfillment'); + registerCustomFieldsForEntity(config, 'Order', CustomOrderFields); + assertLocaleFieldsNotSpecified(config, 'Order'); + registerCustomFieldsForEntity(config, 'OrderLine', CustomOrderLineFields); + assertLocaleFieldsNotSpecified(config, 'OrderLine'); + registerCustomFieldsForEntity(config, 'PaymentMethod', CustomPaymentMethodFields); registerCustomFieldsForEntity(config, 'PaymentMethod', CustomPaymentMethodFieldsTranslation, true); + registerCustomFieldsForEntity(config, 'Product', CustomProductFields); registerCustomFieldsForEntity(config, 'Product', CustomProductFieldsTranslation, true); + registerCustomFieldsForEntity(config, 'ProductOption', CustomProductOptionFields); registerCustomFieldsForEntity(config, 'ProductOption', CustomProductOptionFieldsTranslation, true); + registerCustomFieldsForEntity(config, 'ProductOptionGroup', CustomProductOptionGroupFields); registerCustomFieldsForEntity( config, @@ -288,19 +326,36 @@ export function registerCustomEntityFields(config: VendureConfig) { CustomProductOptionGroupFieldsTranslation, true, ); + registerCustomFieldsForEntity(config, 'ProductVariant', CustomProductVariantFields); registerCustomFieldsForEntity(config, 'ProductVariant', CustomProductVariantFieldsTranslation, true); + registerCustomFieldsForEntity(config, 'Promotion', CustomPromotionFields); registerCustomFieldsForEntity(config, 'Promotion', CustomPromotionFieldsTranslation, true); + registerCustomFieldsForEntity(config, 'TaxCategory', CustomTaxCategoryFields); + assertLocaleFieldsNotSpecified(config, 'TaxCategory'); + registerCustomFieldsForEntity(config, 'TaxRate', CustomTaxRateFields); + assertLocaleFieldsNotSpecified(config, 'TaxRate'); + registerCustomFieldsForEntity(config, 'User', CustomUserFields); + assertLocaleFieldsNotSpecified(config, 'User'); registerCustomFieldsForEntity(config, 'GlobalSettings', CustomGlobalSettingsFields); + assertLocaleFieldsNotSpecified(config, 'GlobalSettings'); + registerCustomFieldsForEntity(config, 'Region', CustomRegionFields); registerCustomFieldsForEntity(config, 'Region', CustomRegionFieldsTranslation, true); + registerCustomFieldsForEntity(config, 'Seller', CustomSellerFields); + assertLocaleFieldsNotSpecified(config, 'Seller'); + registerCustomFieldsForEntity(config, 'ShippingMethod', CustomShippingMethodFields); registerCustomFieldsForEntity(config, 'ShippingMethod', CustomShippingMethodFieldsTranslation, true); + registerCustomFieldsForEntity(config, 'StockLocation', CustomStockLocationFields); + assertLocaleFieldsNotSpecified(config, 'StockLocation'); + registerCustomFieldsForEntity(config, 'Zone', CustomZoneFields); + assertLocaleFieldsNotSpecified(config, 'Zone'); }