feat(scheduled): scheduled emails get their own type, a list method, and getScheduled works again - #19
Merged
Conversation
…fix for getScheduled The API changed shape for scheduled emails and this catches the SDK up. `getScheduled()` currently throws against the live API for every scheduled email, so this is a fix first and a feature second. Two things in the new response broke the old `TransmissionDetail`: - `transmission_id` is null until the email is actually sent, which a non-nullable `string` property cannot hold (TypeError). - `state` now uses `scheduled`, `sending`, `sent`, `cancelled` and `failed`. `sending`, `sent` and `cancelled` are not in `TransmissionState` (ValueError). Rather than widen `TransmissionDetail`, which `find()` also returns and which real users consume for sent emails, scheduled emails get their own `ScheduledEmail` type and `ScheduledEmailState` enum. `TransmissionDetail`, `TransmissionState` and `find()` are untouched, so anyone who does not schedule emails sees no change at all. `schedule()`, `getScheduled()` and `cancelScheduled()` now return `ScheduledEmail`. `cancelScheduled()` previously returned void; callers that ignore the return value are unaffected. Also adds `listScheduled()` for the new `GET /emails/scheduled`, with the filter, response, collection and pagination classes the other list endpoints use. Cancelling returns the cancelled email, which `TransporterContract::delete()` cannot express because it returns void. Widening that method would break every custom transporter, so this follows the `SupportsRequestHeaders` pattern: a separate optional `SupportsDeleteWithResponse` interface, with a fallback that cancels and then reads the email back. The two ids are deliberately distinct on the DTO. `requestId` (`sch_...`) identifies the scheduled email for its whole life; `transmissionId` is the provider's id, null until the email is sent, and the value that appears on webhook events. Verified end to end against a live API: schedule, read back, list, cancel, read back again, and a second cancel refused with 409. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Catches the SDK up with the scheduled-email API change.
getScheduled()throws against the live API today, so this is a fix first and a feature second.What broke
Two things in the new response could not fit the old
TransmissionDetail:I confirmed this by running the released 2.7.0 code against the exact payloads the API now returns — a
TypeErrorfor an unsent email and aValueErrorfor a cancelled one. Every call togetScheduled()fails; there is no state that works.schedule()andcancelScheduled()kept working, because they only read fields that still exist.Why a new type instead of widening the old one
TransmissionDetailis also whatfind()returns for sent emails, and that endpoint is unchanged. Making itstransmissionIdnullable and adding enum cases would have pushed astring|nulland newmatcharms onto users who never schedule anything.So scheduled emails get their own
ScheduledEmailandScheduledEmailState.TransmissionDetail,TransmissionStateandfind()are untouched — anyone not scheduling emails sees no change.Changes
New
Dto\Email\ScheduledEmail— both ids, state,accepted/rejected,tag,failureReason,events, plusisCancellable(),isSent(),isCancelled()Enums\ScheduledEmailState—Scheduled,Sending,Sent,Cancelled,FailedEmailService::listScheduled()for the newGET /emails/scheduled, with the filter, response, collection and pagination classes the other list endpoints useContracts\SupportsDeleteWithResponseChanged — only the three scheduling methods.
schedule(),getScheduled()andcancelScheduled()now returnScheduledEmail.cancelScheduled()previously returnedvoid; callers ignoring the return value are unaffected.The two ids
They answer different questions, and conflating them is the likeliest integration bug:
requestId(sch_...) identifies the scheduled email for its whole life. This is whatgetScheduled()andcancelScheduled()take.transmissionIdis the provider's id.nulluntil the email is sent, and the value that appears on webhook events.Anyone who stored the id from
schedule()to match webhooks needstransmissionIdfrom a later read. The changelog says so prominently.One design note for review
Cancelling returns the cancelled email, but
TransporterContract::delete()returnsvoidand widening it would break every custom transporter. So this follows the pattern the package already documents forSupportsRequestHeaders: a separate optional interface, with a fallback that cancels and then reads the email back in a second request. Both paths have a test.Verification
example-phpsuite passes against production:schedule(),listScheduled()andgetScheduled()all green (its cancel test is marked destructive and stays skipped). Test emails created during that run were cancelled afterwards.Not in this PR
lettr-laravelallows^2.7.0, so publishing 2.8.0 will pull it in there. Its test fake returns the old three-field array and would throw. That fix is ready separately and should land before this is tagged. Its own users are unaffected —/testsisexport-ignore.🤖 Generated with Claude Code