diff --git a/extension/docs/DevelopmentAndDeploymentGuide.md b/extension/docs/DevelopmentAndDeploymentGuide.md index 1d50d3590..e2f84b87c 100644 --- a/extension/docs/DevelopmentAndDeploymentGuide.md +++ b/extension/docs/DevelopmentAndDeploymentGuide.md @@ -36,6 +36,7 @@ Environment variables to configure the notification module: |`API_EXTENSION_BASE_URL` | URL of the Extension module server. In case of any payment changes, [CTP API extension](https://docs.commercetools.com/http-api-projects-api-extensions) will call this URL and pass the payment object in body. | YES | | |`LOG_LEVEL` | bunyan log level (`trace`, `debug`, `info`, `warn`, `error`, `fatal`)| NO | `info` |`PORT` | port on which the application will run | NO | 8080 +|`ENSURE_RESOURCES` | Set to `false` to disable the creation of resources in commercetools (e.g. custom types) | NO | `true` After setting all environmental variables, execute command `npm run extension` to run the module. diff --git a/extension/src/config/config.js b/extension/src/config/config.js index 574dd167d..e9cfd2242 100644 --- a/extension/src/config/config.js +++ b/extension/src/config/config.js @@ -6,7 +6,8 @@ function getEnvConfig () { logLevel: process.env.LOG_LEVEL, apiExtensionBaseUrl: process.env.API_EXTENSION_BASE_URL, keepAliveTimeout: !Number.isNaN(process.env.KEEP_ALIVE_TIMEOUT) ? parseFloat(process.env.KEEP_ALIVE_TIMEOUT, 10) - : undefined + : undefined, + ensureResources: process.env.ENSURE_RESOURCES !== 'false' } } diff --git a/extension/src/config/init/ensure-resources.js b/extension/src/config/init/ensure-resources.js index 66aac1df7..8f46c1adb 100644 --- a/extension/src/config/init/ensure-resources.js +++ b/extension/src/config/init/ensure-resources.js @@ -2,7 +2,7 @@ const { ensurePaymentCustomType } = require('./ensure-payment-custom-type') const { ensureInterfaceInteractionCustomType } = require('./ensure-interface-interaction-custom-type') const { ensureApiExtensions } = require('./ensure-api-extensions') const ctpClientBuilder = require('../../ctp/ctp-client') -const config = require('../../config/config') +const configLoader = require('../../config/config') const ctpClient = ctpClientBuilder.get() @@ -14,9 +14,11 @@ function ensureCustomTypes () { } function ensureResources () { + let config = configLoader.load() + if (!config.ensureResources) return Promise.resolve() return Promise.all([ ensureCustomTypes(), - ensureApiExtensions(ctpClient, config.load().apiExtensionBaseUrl) + ensureApiExtensions(ctpClient, config.apiExtensionBaseUrl) ]) } diff --git a/notification/docs/DevelopmentGuide.md b/notification/docs/DevelopmentGuide.md index 8733f834a..6e8c6e1f8 100644 --- a/notification/docs/DevelopmentGuide.md +++ b/notification/docs/DevelopmentGuide.md @@ -26,6 +26,7 @@ CTP_CLIENT_SECRET | commercetools client secret (you can get in the [commercetoo LOG_LEVEL | bunyan log level (`trace`, `debug`, `info`, `warn`, `error`, `fatal`)| NO | `info` PORT | port on which the application will run | NO | 443 KEEP_ALIVE_TIMEOUT | milliseconds to keep a socket alive after the last response ([Node.js docs](https://nodejs.org/dist/latest-v8.x/docs/api/http.html#http_server_keepalivetimeout)) | NO | Node.js default +ENSURE_RESOURCES | Set to `false` to disable the creation of resources in commercetools (e.g. custom types) | NO | `true` Don't forget to provide all required environment variables After setting all variables, execute command `npm run start` to run the module. diff --git a/notification/src/config/config.js b/notification/src/config/config.js index 90e4211f6..e1a372cc4 100644 --- a/notification/src/config/config.js +++ b/notification/src/config/config.js @@ -8,7 +8,8 @@ function getEnvConfig () { return { logLevel: process.env.LOG_LEVEL, keepAliveTimeout: !Number.isNaN(process.env.KEEP_ALIVE_TIMEOUT) ? parseFloat(process.env.KEEP_ALIVE_TIMEOUT, 10) - : undefined + : undefined, + ensureResources: process.env.ENSURE_RESOURCES !== 'false' } } diff --git a/notification/src/config/init/ensure-interface-interaction-custom-type.js b/notification/src/config/init/ensure-interface-interaction-custom-type.js index 366ce281b..8e124f939 100644 --- a/notification/src/config/init/ensure-interface-interaction-custom-type.js +++ b/notification/src/config/init/ensure-interface-interaction-custom-type.js @@ -1,9 +1,11 @@ const logger = require('../../utils/logger').getLogger() const interfaceInteractionType = require('../../../resources/payment-interface-interaction-type.json') +const config = require('../../config/config')() async function ensureInterfaceInteractionCustomType (ctpClient) { try { + if (!config.ensureResources) return logger.debug('Ensuring interfaceInteraction') const { body } = await ctpClient.fetch(ctpClient.builder.types.where(`key="${interfaceInteractionType.key}"`)) if (body.results.length === 0) {