fix(email-connectors): validate Mailchimp datacenter segment and require non-empty listId in upsertSubscriber

Open Beginner friendly
#65 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
api, backend

Research direction

Start with packages/email-connectors/src/adapters/mailchimp.adapter.ts, focusing on extractDatacenter and upsertSubscriber as identified in the issue. Check the existing adapter behavior and related tests, if present. Done means valid API keys still work, invalid datacenter segments produce a clear error, and an empty list ID returns the specified failure result.

Written by the indexing model from the issue text.

Description

backend good first issue
Problem Description

In packages/email-connectors/src/adapters/mailchimp.adapter.ts:

  1. extractDatacenter (lines 12-18) reads parts[1] instead of the trailing segment (parts[parts.length - 1]) and does not validate that the datacenter matches Mailchimp's format (/^[a-z]{2}\d+$/i, e.g., us14), allowing malformed keys to inject arbitrary host prefixes into https://${dc}.api.mailchimp.com/3.0 or silently fall back to us1.
  2. upsertSubscriber (lines 90-106) does not guard against an empty listId, resulting in a malformed PUT /lists//members/... request (404).

Expected Behavior
  1. extractDatacenter extracts the last hyphen-separated segment and validates /^[a-z]{2}\d+$/i, throwing a clear error on invalid Mailchimp API keys.
  2. upsertSubscriber returns { success: false, error: 'Mailchimp list ID is required.' } when listId is empty.
  3. All valid Mailchimp API keys (<key>-<dc>) continue to work identically.

Where to Look
  • packages/email-connectors/src/adapters/mailchimp.adapter.ts (extractDatacenter lines 12-18, upsertSubscriber lines 90-106)

Solution / Implementation Guide
  1. In extractDatacenter(apiKey: string):
    • Trim apiKey, split on '-', take const dc = parts[parts.length - 1]?.trim(), and validate /^[a-z]{2}\d+$/i.test(dc) (throw an Error('Invalid Mailchimp API key format (expected <key>-<dc>)') if invalid).
  2. In upsertSubscriber:
    • Add an early guard if (!listId?.trim()) return { success: false, error: 'Mailchimp list ID is required.' }; before building the request URL.
Dominant language
TypeScript
Stars
2
Forks
1
Avg merge
6m
Merged PRs (30d)
27

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sumamakhan761/tryinstance

All issues in sumamakhan761/tryinstance

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.