Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

commercetools Connect Proxy

This project is a commercetools Connect-hosted event proxy for teams that already run their business logic outside Connect.

It creates and manages a commercetools Subscription (in postDeploy), receives events through the Connect-managed queue/topic delivery pipeline, and forwards each event to an external API (for example, a webhook receiver in Vercel).

What This Is For

Use this connector when:

  • your core logic lives in an existing monorepo or API outside commercetools Connect
  • you still want commercetools events (messages and/or changes) delivered reliably
  • you want Connect to host only the thin forwarding layer

The Express event app does not contain domain business logic. Its job is to transform and forward events.

High-Level Flow

  1. postDeploy creates/updates a commercetools Subscription that points to Connect-managed messaging infrastructure.
  2. commercetools publishes matching events to that destination.
  3. The Connect event app (/event) receives the queued message.
  4. The app forwards the payload to API_ENDPOINT with HMAC headers.
  5. The app response controls queue acknowledgement and retries.

Retry and Acknowledgement Behavior

The proxy performs a single forward attempt per delivery attempt.

  • Retryable downstream failures (429, 5xx, transport/network failures) return non-2xx from the app, so Connect/GCP retries.
  • Non-retryable downstream 4xx responses are acknowledged to avoid retry storms.
  • Incoming Pub/Sub HTTP envelopes are accepted up to 1 MB; larger requests return 413.

This keeps retry ownership in the queue layer instead of in-process retry loops.

Subscription Key Strategy

Each deployment must provide SUBSCRIPTION_SUFFIX.

The connector builds the final subscription key as:

ct-event-proxy-subscription-<SUBSCRIPTION_SUFFIX>

Why: this prevents multiple deployments in the same commercetools project from overwriting each other's subscription.

Example suffixes:

  • dev-a
  • dev-b
  • staging
  • prod

Connect-managed credentials

connect.yaml declares inheritAs.apiClient.scopes: [manage_subscriptions]. Connect creates the runtime API Client and injects its credentials into the application and deployment hooks. Installers do not create, copy or retain this client's ID or secret. The management client that installs the Connector needs manage_api_clients:{projectKey} in addition to its Connect deployment permission.

The generated runtime client only needs:

  • manage_subscriptions:{projectKey}

Configuration

Defined in connect.yaml.

Standard configuration:

  • API_ENDPOINT (required): external webhook/API URL to receive forwarded events
  • SUBSCRIPTION_SUFFIX (required): unique suffix per deployment in the same project
  • SUBSCRIPTION_CONFIG (optional): JSON for messages and changes filters
  • ADDITIONAL_HEADERS (optional): JSON headers appended to outbound webhook request

Secured configuration supplied by the installer:

  • WEBHOOK_SECRET (required): used for HMAC signature headers on forwarded requests

Connect supplies CTP_API_URL, CTP_AUTH_URL, CTP_PROJECT_KEY, CTP_CLIENT_ID, CTP_CLIENT_SECRET and CTP_SCOPE. Do not declare or supply these as installation configuration. The application uses the injected API/auth URLs, so no region setting is needed.

The receiver must use the same webhook secret as this installation. When changing the endpoint or event selection, redeploy the existing installation and run its postDeploy hook. The hook updates the existing Subscription; changing message types does not require another runtime client.

Local Development (Event App)

From event/:

For local execution outside Connect, fill event/.env using the fields in event/.env.example. Connect supplies the commerce fields in hosted deployments.

nvm install
nvm use
corepack enable
yarn install --frozen-lockfile
yarn build
yarn test
yarn test:smoke
yarn start:dev

yarn test:smoke builds the application and tests it over real local HTTP connections with a local webhook receiver and dummy credentials. It checks event forwarding, HMAC signatures, additional headers, and retry/acknowledgement responses without contacting commercetools or an external webhook.

Notes

  • postDeploy creates/updates only this deployment's subscription key.
  • preUndeploy deletes only this deployment's subscription key.
  • If you deploy the connector more than once to the same project, always use different SUBSCRIPTION_SUFFIX values.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages