Convert an existing integration to a Connector
This step-by-step guide explains how to convert an existing integration into a Connector. It outlines the modifications needed to ensure that the project aligns with the new Connector requirements.
The guide covers various aspects such as the Connector specification file (
connect.yaml), determining the appropriate application type, implementing the proper folder structure, and constructing the necessary automation scripts for managing extensions and subscriptions.
To convert an existing repository to a valid Connector you must create and configure a connect.yaml file. connect.yaml is required and is the starting point of each Connector repository.
connect.yaml contains the descriptions and configurations of each application to be deployed, and is later used in the certification process of the Connector.
Example connect.yaml file
You can use the following example connect.yaml file as a reference to create your own.
See the following table for explanations of each attribute.
|Yes||The root key of the file containing an array of the applications that we want to deploy in our Connector. In this file example, two applications named |
|Yes||Identifier of the application deployment. This is important as the deployment's output URL, topic, and schedule are fetched based on this reference.|
|Yes||The type of application to deploy. Connectors currently support three application types: |
|Yes (job type applications)||This configuration is only required for |
|No||Displays the configuration for the Connector's scripts. You will need this field if you need to create and use commercetools API Extensions and Subscriptions.|
|No||An object of configurations to be used in the Connector as schema validation. This is an array containing |
After gaining an understanding of the required application types for the Connector and creating connect.yaml, it is essential to adhere to a project structure that aligns with it.
Structure your project
In the context of Connect, each application is treated independently and it is necessary to isolate each application in a separate folder, as each one will be provisioned in a slightly different manner based on its application type.
Each folder must contain the value specified in the
Using the previous
connect.yaml example, we should have the following directory structure:
Choose an application type
Connect supports three types of applications:
Services allow you to handle API Extensions. A possible use case is to validate newly created resources and apply additional updates, such as calculating custom shipping costs for a cart or adding mandatory items.
Events allow you to handle asynchronous events triggered by your Subscriptions. You can use event applications to notify your customers after a successful payment or if a product is back in stock.
Jobs allow you to execute server-side logic on a regular schedule that you define using cron expressions like
schedule: 0 0 * * *. You can use job applications to do work that happens on a periodic basis, such as updating a resource every minute, generating a nightly report, or sending an automated weekly email newsletter.
Implement Connect applications
Every application receives the necessary configuration as defined in connect.yaml, which is provided through environment variables.
Additionally, each Connect application must ensure that it exposes an HTTP server at 8080, encompassing all the required integration endpoints, as in the following examples:
You must include the following scripts in package.json.
|Automates the build process of the project to generate production-ready code.|
|The entry point of the application, responsible for initializing the server listening on port 8080.|
Adding automation scripts
You can define scripts in connect.yaml which run on different deployment stages, which allows Connect to create and modify those resources.
postDeploy runs after a successful deployment of the Connect application and is useful when you need to set up an API Extension or Subscription required to trigger your Connector endpoint.
postDeploy has access to extra environment variables depending on the application type.
|Environment variable||Application type||Description|
|Service||The public URL of the Connect application, should be used when setting up the API Extension in the Composable Commerce API.|
|Event||Google Cloud Platform (GCP) project ID. Should be used when setting up the Subscription in the Composable Commerce API.|
|Event||GCP Pub/Sub topic name. Should be used when setting up the Subscription in the Composable Commerce API .|
preUndeploy runs before the Connector is undeployed and is useful when deleting unused resources from the Composable Commerce API.
Example service application
Example event application
Testing your Connect application
It is mandatory to include tests for your Connect application. This is to ensure that your application codebase has a good level of quality to guarantee proper functionality and maintainability.
We recommend using a tool like Jest, which allows you to use multiple useful assertions and mocks, and gather code coverage.