Create an integration server

Use our sample template to create an integration server that integrates InStore with Composable Commerce.

We provide modifiable templates that include the InStore modular store, InStore core modules, Composable Commerce, and a secure integration layer so the components can communicate. This guide describes how to build the integration server, which is sometimes referred to as a backend-for-frontend (BFF) server.

We recommend using the integration server, but you can choose a component-based microservice approach instead if you prefer.

Set up one integration server per InStore tenant environment. For example, if you have one test environment and one production environment, set up two integration servers.

What is the integration server

The integration server handles tasks that InStore itself does not support, including but not limited to:

  • Authenticating users of the InStore colleague app via your identity provider
  • Loading startup configuration
  • Adding and removing cart items
  • Loading customer and loyalty information
  • Loading catalog and discount information
  • Transferring and tracking your order management system, fulfillment, shipping options, and taxation information
Payment information does not pass through the integration server. Instead, it is communicated directly to the InStore APIs. For more information about the structures that handle cash management and payment operations, see Callbacks and Webhooks.

It is your responsibility to build and maintain the integration server. The template repository is a starting point only, and you must not use it in production environments without first enhancing its security and resiliency.

Prerequisites

  • Node.js v18.20.5 LTS
  • A Composable Commerce API client with the scopes required for store operations
  • A Composable Commerce Project with the following components:
    • Product Type
    • Types:
      • Cart
      • Order
      • Category
      • LineItem
      • Payment
      • Transaction

Install the integration template repository

Set up and configure the integration server

When setting up your integration server, connect it to your Composable Commerce Project. This is a many-to-one relationship, with all integration servers sharing the same Project.

To set up and configure the integration server, do the following:

  1. Run the following in the mist-integration-server directory:
    npm install
    
  2. Add a .env file to your server directory that includes InStore, Composable Commerce, and MongoDB environment variables from the tables below. You can use our sample.env file as a template.

InStore environment variables

ParameterDescription
WEBHOOK_VERIFICATIONVerification key that you defined in the InStore Center on the Integration Settings tab for the environment.
CALLBACK_KEYCallback key that is defined in the InStore Center on the Integration Settings tab for the environment.
CUSTOM_PAYMENT_VERIFICATION_KEYIf you configure a custom payment processor, the verification keys for the payment processor must match the value you define for this variable.
WHITELISTED_DOMAINSComma-separated list of all frontend apps that connect to the integration server, including your hosted colleague app. This is required for cross-origin resource sharing (CORS) support. For example, add http://localhost:8080 for the local instance of the Modular Store app.
SERVER_HOSTURL for the InStore API server, for example https://api.us-east-2.aws.commercetools.com/. It is provided by commercetools.
IN_STORE_LINEITEM_TYPEValue of the key you defined for this custom type. The value must match the value set for this field in the InStore Center on the Project Settings tab.
IN_STORE_ORDER_TYPEValue of the key you defined for this custom type. The value must match the value set for this field in the InStore Center on the Project Settings tab.

Composable Commerce environment variables

ParameterDescription
CTP_PROJECT_KEYComposable Commerce project key
CTP_CLIENT_IDComposable Commerce client ID
CTP_CLIENT_SECRETComposable Commerce API client secret
CTP_AUTH_URLComposable Commerce authorization URL
CTP_HOSTComposable Commerce API URL
CTP_SCOPESComposable Commerce scopes

MongoDB environment variables

The following variables are used for user management in the demo instance:

ParameterDescription
DB_NAMEIntegration database name
MONGO_USERUsername
MONGO_PASSWORDPassword
MONGO_HOSTDatabase cluster address
  1. (Optional) Update the PORT. The port number defaults to 5001.
  2. Start the application from your local directory using npm start.

Populate the InStore Center with integration server data

After establishing the integration server URL, enter it in the InStore Center so the frontend can communicate with the integration server.

On the Integration Settings tab of the Environment page, the following fields require the integration server URL as a prefix:
  • Webhook URL
  • Cart Retrieval URL
  • Token Retrieval URL
  • Key Sync URL
  • Return Cart Retrieval URL