From e4eeccb1d9090c4c922d53c897ae23a6467dac78 Mon Sep 17 00:00:00 2001 From: Carlos Cortizas <97907068+CarlosCortizasCT@users.noreply.github.com> Date: Mon, 7 Feb 2022 20:14:53 +0100 Subject: [PATCH] fix(application-config): allow to define `entryPointUriPath` with env placeholder (#2474) * fix(application-config): allow env vars in entryPointUriPath config * fix(application-config): allow env vars in entryPointUriPath config * fix: update Readme instruction command for playground * chore: changeset added * chore: better changeset description Co-authored-by: Nicola Molinari * chore: update version type in changeset Co-authored-by: Nicola Molinari * fix(application-config): incorrect schema typing Co-authored-by: Nicola Molinari * fix(application-config): incorrect entryPointUriPath TS type * test(application-config): udpate json-schema test * test(application-config): update fixture for entry point as env variable Co-authored-by: Nicola Molinari --- .changeset/slimy-parrots-deny.md | 5 +++++ README.md | 2 +- packages/application-config/schema.json | 12 +++++++++--- packages/application-config/src/schema.ts | 2 +- .../test/fixtures/config-env-variables.json | 2 +- packages/application-config/test/json-schema.spec.js | 1 + .../application-config/test/process-config.spec.js | 4 ++++ 7 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 .changeset/slimy-parrots-deny.md diff --git a/.changeset/slimy-parrots-deny.md b/.changeset/slimy-parrots-deny.md new file mode 100644 index 0000000000..5fa9e9becf --- /dev/null +++ b/.changeset/slimy-parrots-deny.md @@ -0,0 +1,5 @@ +--- +'@commercetools-frontend/application-config': patch +--- + +Allow to use environment variable placeholders for the `entryPointUriPath` field. diff --git a/README.md b/README.md index 41396d2e20..09fcf2e6a0 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Start the [playground application](./playground): ```bash // Terminal process 1 -$ yarn build:bundles:watch +$ yarn build:watch // Terminal process 2 $ yarn playground:start diff --git a/packages/application-config/schema.json b/packages/application-config/schema.json index 572b61d47e..707d864aca 100644 --- a/packages/application-config/schema.json +++ b/packages/application-config/schema.json @@ -27,12 +27,18 @@ }, "entryPointUriPath": { "description": "See https://docs.commercetools.com/custom-applications/api-reference/application-config#entrypointuripath", - "type": "string", - "pattern": "^[^\\-_]([0-9a-z]|[\\-_](?![\\-_])){2,64}[^\\-_]$" + "oneOf": [ + { + "type": "string", + "pattern": "^[^\\-_]([0-9a-z]|[\\-_](?![\\-_])){2,64}[^\\-_]$" + }, + { + "$ref": "#/definitions/envVariablePlaceholder" + } + ] }, "cloudIdentifier": { "description": "See https://docs.commercetools.com/custom-applications/api-reference/application-config#cloudidentifier", - "type": "string", "oneOf": [ { "enum": ["gcp-au", "gcp-eu", "gcp-us", "aws-fra", "aws-ohio"] diff --git a/packages/application-config/src/schema.ts b/packages/application-config/src/schema.ts index 67cdf8b9f3..040a6c211d 100644 --- a/packages/application-config/src/schema.ts +++ b/packages/application-config/src/schema.ts @@ -21,7 +21,7 @@ export interface JSONSchemaForCustomApplicationConfigurationFiles { /** * See https://docs.commercetools.com/custom-applications/api-reference/application-config#cloudidentifier */ - cloudIdentifier: (('gcp-au' | 'gcp-eu' | 'gcp-us' | 'aws-fra' | 'aws-ohio') | EnvVariablePlaceholder) & string; + cloudIdentifier: ('gcp-au' | 'gcp-eu' | 'gcp-us' | 'aws-fra' | 'aws-ohio') | EnvVariablePlaceholder; /** * See https://docs.commercetools.com/custom-applications/api-reference/application-config#mcapiurl */ diff --git a/packages/application-config/test/fixtures/config-env-variables.json b/packages/application-config/test/fixtures/config-env-variables.json index 7b0d3c8d78..9dcec5968f 100644 --- a/packages/application-config/test/fixtures/config-env-variables.json +++ b/packages/application-config/test/fixtures/config-env-variables.json @@ -1,6 +1,6 @@ { "name": "avengers-app", - "entryPointUriPath": "avengers", + "entryPointUriPath": "${env:ENTRY_POINT_URI_PATH}", "cloudIdentifier": "${env:CLOUD_IDENTIFIER}", "env": { "development": { diff --git a/packages/application-config/test/json-schema.spec.js b/packages/application-config/test/json-schema.spec.js index 01427cb807..1b5effaaf4 100644 --- a/packages/application-config/test/json-schema.spec.js +++ b/packages/application-config/test/json-schema.spec.js @@ -28,6 +28,7 @@ describe.each` ${'avengers01'} ${'avengers-01'} ${'avengers_01'} + ${'${env:APP_ENTRY_POINT_URI_PATH}'} `('validating "entryPointUriPath"', ({ entryPointUriPath }) => { it(`should validate "${entryPointUriPath}" correctly`, () => { expect(() => diff --git a/packages/application-config/test/process-config.spec.js b/packages/application-config/test/process-config.spec.js index 174021ad3a..9f1d05910f 100644 --- a/packages/application-config/test/process-config.spec.js +++ b/packages/application-config/test/process-config.spec.js @@ -421,6 +421,7 @@ describe('processing a config with environment variable placeholders', () => { const result = processConfig( createTestOptions({ processEnv: { + ENTRY_POINT_URI_PATH: 'avengers', APP_URL: 'https://avengers.app', CLOUD_IDENTIFIER: 'gcp-eu', NODE_ENV: 'test', @@ -473,6 +474,7 @@ describe('processing a config with environment variable placeholders', () => { const result = processConfig( createTestOptions({ processEnv: { + ENTRY_POINT_URI_PATH: 'avengers', APP_URL: 'https://avengers.app', CLOUD_IDENTIFIER: 'gcp-eu', NODE_ENV: 'production', @@ -511,6 +513,7 @@ describe('processing a config with environment variable placeholders', () => { const result = processConfig( createTestOptions({ processEnv: { + ENTRY_POINT_URI_PATH: 'avengers', APP_URL: 'https://avengers.app', CLOUD_IDENTIFIER: 'gcp-eu', NODE_ENV: 'production', @@ -567,6 +570,7 @@ describe('processing a config with environment variable placeholders', () => { const result = processConfig( createTestOptions({ processEnv: { + ENTRY_POINT_URI_PATH: 'avengers', APP_URL: 'https://avengers.app', CLOUD_IDENTIFIER: 'gcp-eu', NODE_ENV: 'production',