Skip to main content

Managing Static Values

You can implement a solution to manage reusable static values used by Conscia developers based on this recipe that manages the Merchant Account identifier for the Adyen payment provider.

Overall Orchestration Flow

You should use secrets to store values that should not be visible and are only available to connections. If you try to use the secret() function to access secrets outside of the context of a connection, you will receive an error "Callee is not a function", because secrets are only availavble to connections. Instead of using secrets, you can use a component to store static values used outside of the context of a connection.

If you use a release management process to migrate elements from one Conscia environment to another, consider how you will manage secrets and other static values.

To optimize performance, you can cache the response of components used to store static values.

Mapping Out DX Engine Components and Templates

Many Adyen Webservice APIs require a Mercahng Account identifier in the JSON payload passed to the Webservice. You could specify the Merchant Account identifier in every component that invokes an Adyen Webservice. Alternatively, you can implement a Conscia Component to store that value and any other static values in your solution, or you can implement multiple components for this purpose.

DX Engine Configuration Details

To create a Component to store static values, in the Conscia User Interface:

  1. Click Manage Experiences in the top navigation, and then click Components. The Manage Components page appears.
  2. Click Add Component.
  3. For Componen Code, enter an identifier for the Component, such as static-values.
  4. For Component Name, enter a name for the Component, such as Static Values.
  5. Optionally, enter a Commponent Description.
  6. Select the No Rules checkbox.
  7. For Component Type, select Conscia - Object Mapper.
  8. Click Submit.

To configure the Component, in the Manage Components page of the Conscia User Intercace:

  1. Click the Edit button next to the component.
  2. For Response Transform, enter JavaScript such as the following:
_.assign({},{
"adyen":
{
"merchantAccount": "ConsciaECOM"
}
})

This code uses the assign() function in the Lodash library to create an empty object, and then adds the adyen/merchantAccount key set to the Adyen Merchant Account identifier.

The Component returns the resulting JSON as its response.

  1. Click Submit.

You can use the componentResponse() function to access values managed by this Component from other Components. The following example is a JS Expression used as the Body of a Component that calls an Adyen Webservice API.

_.assign({},{
"merchantAccount": componentResponse('static-values').adyen.merchantAccount
})

This code uses the assign() function in the Lodash library to create an empty object, and then adds a merchantAccount key set to the Adyen Merchant Account identifier from the static-values Component, and then POSTS that JSON to the Adyen Webservice API.

Alternatives

You could also a Conscia Universal API Connector Component to invoke the Conscia Webservice API used to invoke Orchestration Templates and Orchestration Components that would contain the values.

If you would prefer to define the values through the DX Studio UI, then you can use a Conscia - Metadata Component for the values.

You can use Experience Rules to apply different values under different conditions, such as to vary the response of a Component depending on the Environment.

References