Skip to content

SDK 12.2.0: triggers.ensureBrewEvent for Brew-event triggers (brew-v2#2071) - #66

Merged
thedogwiththedataonit merged 2 commits into
mainfrom
claude/brew-event-triggers
Oct 15, 2026
Merged

thedogwiththedataonit merged 2 commits into
mainfrom
claude/brew-event-triggers

Conversation

@thedogwiththedataonit

@thedogwiththedataonit thedogwiththedataonit commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What

GetBrew/brew-v2#2071 adds Brew events: triggers Brew starts itself. The first is contact.unsubscribed, a contact unsubscribing with an email's link or their mail app's one-click button. This mirrors it in the SDK.

const trigger = await brew.automations.triggers.ensureBrewEvent({
  event: 'contact.unsubscribed',
  scope: 'domain', // or 'all' (no domainId)
  domainId: 'jd7f0c2a8w1x9m4n6p3q5r8s2t', // a marketing domain from brew.domains.list()
})
trigger.created // true the first time, false afterwards
  • triggers.ensureBrewEvent(input, options?) wraps POST /v1/automations/triggers/brew-events. It returns the brand's trigger for one scope, creating it the first time, plus created. Like every POST it carries an auto idempotency key, so a retry replays.
  • Exports: EnsureBrewEventTriggerInput, EnsureBrewEventTriggerResponse and BrewEventTriggerConfig.
  • Bundled spec and generated types:
    • Trigger provider and trigger-instance source gain brew_event.
    • Trigger rows gain an optional brewEvent.
    • ApiErrorCode gains TRIGGER_NOT_FIREABLE.
  • Docs: docs/automations.md gets an "Unsubscribe triggers" section, and the fire JSDoc names the 409 TRIGGER_NOT_FIREABLE refusal.

Spec vendoring

The bundled openapi/public-api-v1.yaml is this repo's main copy plus exactly brew-v2#2071's spec diff, applied with patch. Brew-v2 main also carries the consent-source integration change, which stays with #62 so the two PRs don't overlap. The result is byte-identical to the vendored copies in the CLI and docs PRs.

Merge order and version

Validation

  • TDD: tests/resources/automations/triggers/brew-events.test.ts failed first (4/4), then passed. It covers the 201 create, the 200 existing row, a typed DOMAIN_PURPOSE_NOT_ALLOWED and raw: true.
  • bun tsc, bun lint, bun run format:check, bun run test (108 files, 649 tests) and bun run build pass.
  • node scripts/generate-types.mjs is a no-op on the committed types, which is CI's freshness guard.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; removing the unused spec backup is a non-blocking cleanup.

Summary

Adds triggers.ensureBrewEvent for unsubscribe triggers, with exported types, generated API types, and tests.

  • Automation builders can set up triggers for contact unsubscribes.

Diagram

sequenceDiagram
  participant Caller
  participant SDK
  participant Brew API
  Caller->>SDK: triggers.ensureBrewEvent(input, options?)
  SDK->>Brew API: POST /v1/automations/triggers/brew-events
  alt Trigger created
    Brew API-->>SDK: 201, row with created=true
  else Trigger already exists
    Brew API-->>SDK: 200, row with created=false
  end
  SDK-->>Caller: Trigger row or raw response
Loading

Reviews (2) · Last reviewed commit: "Release as 12.2.0; spec delta for Brew-e..." · Reviewed by Greptile

…#2071)

GetBrew/brew-v2#2071 adds triggers Brew starts itself, the first being a
contact unsubscribing. This mirrors that API:

- `brew.automations.triggers.ensureBrewEvent({ event, scope, domainId? })`
  wraps `POST /v1/automations/triggers/brew-events`, the get-or-create
  for one scope, and returns the row plus `created`.
- Exports `EnsureBrewEventTriggerInput`, `EnsureBrewEventTriggerResponse`
  and `BrewEventTriggerConfig`.
- The bundled spec takes exactly brew-v2#2071's spec change; the
  consent-source sync stays with #62. Generated types are regenerated.
  Trigger `provider` and instance `source` gain `brew_event`, and the error
  codes gain `TRIGGER_NOT_FIREABLE`.
- `docs/automations.md` gets an "Unsubscribe triggers" section, and the
  `fire` JSDoc names the 409.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- 12.2.0, the next free version: this lands before the open 12.2.0 and
  12.3.0 branches, which renumber when they merge.
- Vendored spec delta from brew-v2#2071: the test operation says a
  Brew-event automation's test runs on Brew's sample with passed fields
  laid over it, and unsubscribe.reasons is required. Types regenerated.
- Docs and changelog: the sample overlay, and that mail from another
  marketing domain reaches the contact only while they are still on it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thedogwiththedataonit thedogwiththedataonit changed the title SDK 12.4.0: triggers.ensureBrewEvent for Brew-event triggers (brew-v2#2071) SDK 12.2.0: triggers.ensureBrewEvent for Brew-event triggers (brew-v2#2071) Oct 14, 2026
@greptile-apps

greptile-apps Bot commented Oct 14, 2026

Copy link
Copy Markdown

Comments Outside Diff

These findings could not be posted inline.

  • P2 Backup keeps a stale spec openapi/public-api-v1.yaml.orig:4 ▶

    openapi/public-api-v1.yaml.orig adds a 67,829-line copy of the old spec. Its examples still mark reasons as optional, while the corrected spec marks it as required. Nothing reads this backup, so it leaves contributors with two conflicting copies to sort through. Remove the unused backup.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@thedogwiththedataonit
thedogwiththedataonit merged commit fe05393 into main Oct 15, 2026
2 checks passed
thedogwiththedataonit added a commit to GetBrew/brew-cli that referenced this pull request Oct 15, 2026
* CLI 0.16.0: automations triggers ensure-brew-event (brew-v2#2071)

GetBrew/brew-v2#2071 adds triggers Brew starts itself, the first being a
contact unsubscribing. GetBrew/typescript-sdk#66 exposes them as
`triggers.ensureBrewEvent`. This adds the command:

- `brew-cli automations triggers ensure-brew-event --scope domain
  --domain-id <id>` or `--scope all` gets or creates the brand's trigger
  for that scope and prints the row with `created`. `--event` defaults to
  `contact.unsubscribed`. Scope/domain mistakes exit 2 before any request,
  and `--idempotency-key` replays a retry.
- The bundled spec takes exactly brew-v2#2071's spec change; the
  consent-source sync stays with #51. Generated types and the command
  reference are regenerated.

Needs @brew.new/sdk ^12.4.0. Until that is on npm, typecheck and parity
fail in CI. Once it publishes: `bun add @brew.new/sdk@^12.4.0`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Needs SDK 12.2.0; spec delta for Brew-event test runs

- The SDK PR now releases as 12.2.0 (the next free version).
- Vendored spec delta from brew-v2#2071 (Brew-event test runs lay passed
  fields over Brew's sample; unsubscribe.reasons is required). Types
  regenerated.
- SKILL.md counts 145 commands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Depend on @brew.new/sdk ^12.2.0 (triggers.ensureBrewEvent)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant