A Custom View configuration file defines the necessary requirements to develop and build your application.
custom-view-config.mjs in the root of your project directory (next to package.json).Supported file extensions
custom-view-config..json, .js, .cjs, .mjs, .ts.For example:
/**
* @type {import('@commercetools-frontend/application-config').ConfigOptionsForCustomView}
*/
const config = {
name: 'Test custom view',
// ...
};
module.exports = config;
Editor support
To facilitate the usage of the Custom View config, you should instruct your editor to provide hints and code completion (IntelliSense) depending on the format of the configuration file.
Use JSDoc @type expression
@type tag, pointing it to the exported TypeScript declaration of the @commercetools-frontend/application-config package./**
* @type {import('@commercetools-frontend/application-config').ConfigOptionsForCustomView}
*/
const config = {
// ...
};
module.exports = config;
.ts, you can import the type directly instead.import type { ConfigOptionsForCustomView } from '@commercetools-frontend/application-config';
const config: ConfigOptionsForCustomView = {
// ...
};
export default config;
Configuration properties
To learn more about the Custom View config properties, read the following.
name
The name of the Custom View.
It will be used in the Merchant Center when a user is presented with a list of Custom Views available for a specific view.
const config = {
name: 'Channels app',
// ...
};
description
An optional description of the Custom View, for information purposes.
const config = {
description: 'Manage Channels',
// ...
};
cloudIdentifier
const config = {
cloudIdentifier: 'gcp-eu',
// ...
};
mcApiUrl property to the Custom View config file with the full origin URL.mcApiUrl
cloudIdentifier. Use this only if the cloudIdentifier does not contain a value for the environment you want to connect to.env
development or production. Which environment is used depends on the environment variable MC_APP_ENV. If MC_APP_ENV isn't set, NODE_ENV will be used. If neither is set, it defaults to development.MC_APP_ENV is useful if you want to run the production build of the Custom View locally. In this case the NODE_ENV needs to be set to production. However, because the application runs locally, you need to have the URL references pointing to localhost, thus the MC_APP_ENV needs to be set to development.env.development.initialProjectKey
projectKey of a commercetools Project you have access to. To be used as the default Project upon login in development.const config = {
env: {
development: {
initialProjectKey: 'my-project-key',
},
},
// ...
};
env.development.teamId
Administrators Team of your Organization with no additional configuration required.teamId of the user's team.env.development.hostUriPath
hostUrl property with the value of the built-in application's current URL. When working locally it is set to http://localhost:3001/<projectKey>/@@custom-view-host@@ by default.env.development.hostUriPath.const config = {
env: {
development: {
hostUriPath: '/<projectKey>/products/111-2222-33333-44444',
},
},
// ...
};
env.production.customViewId
const config = {
env: {
production: {
customViewId: 'ckvtahxl90097sys6har1e6n3',
},
},
// ...
};
As long as you are developing the Custom View locally, you can define any random value as it's a required field.
env.production.url
const config = {
env: {
production: {
url: 'https://channels.app',
},
},
// ...
};
env.production.cdnUrl
const config = {
env: {
production: {
cdnUrl: 'https://cdn.channels.app',
},
},
// ...
};
env.production.url value will be used instead.additionalEnv
For example, if the Custom View should reference an external API, or have links to certain support pages:
const config = {
additionalEnv: {
trackingSentry: 'https://000@sentry.io/000',
channelsSupportUrl: 'https://support.channels.app',
},
// ...
};
oAuthScopes
You can have "view-only" or "manage-only" OAuth Scopes and leave the other list field empty, as long as at least one OAuth Scope is specified.
oAuthScopes.view
View permission.const config = {
oAuthScopes: {
view: ['view_states'],
},
// ...
};
oAuthScopes.manage
Manage permission.const config = {
oAuthScopes: {
manage: ['manage_orders'],
},
// ...
};
manage_ OAuth Scopes always imply the corresponding view_ OAuth Scope.additionalOAuthScopes
additionalOAuthScopes.*.name
A unique name for the additional permission group.
const config = {
additionalOAuthScopes: [
{
name: 'movies',
},
],
// ...
};
The name value must adhere to the following restrictions:
- Only lowercase alphabetic characters are allowed.
- Must be between 2 and 64 characters.
- Hyphens are allowed except as leading, trailing, and adjacent characters.
additionalOAuthScopes.*.view
View<GroupName> permission.const config = {
additionalOAuthScopes: [
{
name: 'movies',
view: ['view_products'],
manage: [],
},
{
name: 'merch',
view: ['view_categories'],
manage: [],
},
],
// ...
};
additionalOAuthScopes.*.manage
Manage<GroupName> permission.const config = {
additionalOAuthScopes: [
{
name: 'movies',
view: [],
manage: ['manage_products'],
},
{
name: 'merch',
view: [],
manage: ['manage_categories'],
},
],
// ...
};
headers
An optional object to configure HTTP headers used by the Custom View.
headers.csp
connect-srcfont-srcframe-srcimg-srcmedia-srcscript-srcstyle-src
*) to control from where certain types of content can be loaded or executed.const config = {
headers: {
csp: {
'connect-src': ['https://api.stripe.com'],
'frame-src': ['https://js.stripe.com', 'https://hooks.stripe.com'],
'script-src': ['https://js.stripe.com'],
},
},
// ...
};
cloudIdentifier and the env.production.url. This includes the hostname where the Custom View is hosted and the hostname of the Merchant Center API Gateway.headers.permissionsPolicies
Permissions-Policy header.headers.permissionPolicies object is used only for local development. To enable these features for production, you need to instruct your hosting server to return the header with the modified values. The Merchant Center Proxy Router will then attempt to merge the values with the default ones.const config = {
headers: {
permissionsPolicies: {
microphone: '()',
camera: '()',
payment: '()',
usb: '()',
geolocation: '()',
},
},
// ...
};
headers.strictTransportSecurity
Strict-Transport-Security header.const config = {
headers: {
strictTransportSecurity: ['includeSubDomains', 'preload'],
},
// ...
};
labelAllLocales
{ locale, value } with translated labels for each custom view locale, available in the user profile.name values will be used instead.const config = {
labelAllLocales: [
{ locale: 'en', value: 'Popular Channels' },
{ locale: 'de', value: 'Beliebte Channels' },
],
// ...
};
type
CustomPanel value.const config = {
type: 'CustomPanel',
// ...
};
typeSettings
Depending on the Custom View type, different settings might be required.
typeSettings.size
CustomPanel type is used, the size property is required. It defines the size of the Custom View panel.SMALL, LARGE.const config = {
type: 'CustomPanel',
typeSettings: {
size: 'SMALL',
},
// ...
};
locators
Since Custom Views are rendered in the context of built-in Merchant Center applications, you need to define the specific views where the Custom View should be rendered.
This configuration property is a list of identifiers of Merchant Center locations where the Custom View is allowed to be rendered.
const config = {
locators: ['products.product_details.general'],
// ...
};
<application>.<view>.<subview>.The following list contains all the currently available locators:
Products application
products.product_details.generalproducts.product_details.variantsproducts.product_details.searchproducts.product_details.selectionsproducts.product_variant_details.generalproducts.product_variant_details.imagesproducts.product_variant_details.pricesproducts.product_variant_details.prices.edit_priceproducts.product_variant_details.inventoryproducts.product_variant_details.inventory.detailsproducts.product_variant_details.inventory.details.add_inventoryproducts.product_variant_images.add_imageproducts.product_variant_prices.add_price
Categories application
categories.category_details.generalcategories.category_details.productscategories.category_details.external_searchcategories.category_products.manage_storefront_order
Customers application
customers.customer_details.generalcustomers.customer_details.addressescustomers.customer_details.orderscustomers.customer_details.business_unitscustomers.customer_addresses.new_addresscustomers.customer_addresses.edit_addresscustomers.customer_orders.order_detailcustomers.business_unit_details.generalcustomers.business_unit_details.associatescustomers.business_unit_details.addressescustomers.business_unit_details.orderscustomers.business_unit_associates.new_associatecustomers.business_unit_associates.edit_associatecustomers.business_unit_addresses.new_addresscustomers.business_unit_addresses.edit_addresscustomers.add_business_unit.business_unit_details
Orders application
orders.order_details.generalorders.order_details.shipping_and_deliveryorders.order_details.returnsorders.order_details.paymentsorders.order_shipping_and_delivery.create_deliveryorders.order_shipping_and_delivery.edit_deliveryorders.order_shipping_and_delivery.add_parcelorders.order_returns.create_returnorders.order_returns.edit_return
Prices application
standalone_prices.add_standalone_pricestandalone_prices.standalone_price_details
Discounts application
discounts.product_discount_details.generaldiscounts.cart_discount_details.generaldiscounts.cart_discount_details.custom_fieldsdiscounts.discount_code_details.generaldiscounts.discount_code_details.custom_fieldsdiscounts.generate_discount_codes
Operations application
operations.import_log_details
Use variable placeholders
Variable placeholders are a way of injecting certain information into the "static" configuration file.
Environment variable references
To make the Custom View config reusable across different environments, you can use references to environment variables within the config file.
${} together with the prefix key env:. For example, to load an environment variable called APP_URL, you would use ${env:APP_URL}.${env:CLOUD_IDENTIFIER} reference to the field cloudIdentifier and pass the actual value using environment variables.const config = {
cloudIdentifier: '${env:CLOUD_IDENTIFIER}',
// ...
};
CLOUD_IDENTIFIER environment variable can be provided in various ways.For example:
-
as an inline environment variable when running a script command
CLOUD_IDENTIFIER=gcp-eu mc-scripts start -
using a dotenv file
CLOUD_IDENTIFIER=gcp-eumc-scripts --env .env-eu start -
by defining the environment variables in your CI service
You can also pass multiple references to the same value:
const config = {
additionalEnv: {
authorityUrl: 'https://${env:IDP_URL}/${env:IDP_ID}',
},
// ...
};
Intl message references
20.8.0 onwards.${} together with the prefix key intl:. For example, to load a translation message from the en.json file named Menu.Channels, you would use ${intl:en:Menu.Channels}.const config = {
labelAllLocales: [
{ locale: 'en', value: '${intl:en:Menu.Channels}' },
{ locale: 'de', value: '${intl:de:Menu.Channels}' },
],
// ...
};
The reference placeholder assumes that the Custom View has the translation files in one of the following locations:
<app_root>/src/i18n/data/<locale>.json<app_root>/i18n/data/<locale>.json
Runtime application environment
window.app.environment prop is parsed and injected into a React Context, making it available to the entire application. To access it, use the @commercetools-frontend/application-shell-connectors package.import { useCustomViewContext } from '@commercetools-frontend/application-shell-connectors';
const MyComponent = () => {
const applicationName = useCustomViewContext(
(context) => context.environment.applicationName
);
return <div>{`Welcome to the application ${applicationName}!`}</div>;
};
additionalEnv object are made available to the context.environment object.For more information, see Custom user properties.