Repository navigation
Add campaign reschedule CLI command #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import {Args, Flags} from '@oclif/core' | ||
| import {PolymorfaValidationError} from '@polymorfa/sdk' | ||
|
|
||
| import {BaseCommand} from '../../base-command.js' | ||
| import {idempotencyKey} from '../../input/idempotency.js' | ||
| import { | ||
| parseCampaignSchedule, | ||
| renderCampaignOperation, | ||
| rescheduleCampaign, | ||
| } from '../../services/campaigns.js' | ||
|
|
||
| export default class CampaignReschedule extends BaseCommand { | ||
| static override args = { | ||
| campaign: Args.string({description: 'Campaign ID.', required: true}), | ||
| } | ||
|
|
||
| static override description = | ||
| 'Change a launched campaign start time before it begins sending, or start it now.' | ||
|
|
||
| static override flags = { | ||
| 'idempotency-key': Flags.string({ | ||
| description: | ||
| 'Idempotency-Key header. Generated per invocation when omitted; reuse an explicit key across process retries (24-hour retention).', | ||
| }), | ||
| now: Flags.boolean({ | ||
| description: 'Start the scheduled campaign now.', | ||
| }), | ||
| 'project-slug': Flags.string({ | ||
| description: 'Project slug in the Messaging API path.', | ||
| required: true, | ||
| }), | ||
| 'scheduled-at': Flags.string({ | ||
| description: | ||
| 'New start time as epoch milliseconds or an ISO 8601 instant.', | ||
| }), | ||
| } | ||
|
|
||
| async run(): Promise<void> { | ||
| const {args, flags} = await this.parse(CampaignReschedule) | ||
| if (flags.now === (flags['scheduled-at'] !== undefined)) { | ||
| throw new PolymorfaValidationError( | ||
| 'Specify exactly one of --scheduled-at or --now.', | ||
| {code: 'invalid_campaign_schedule'}, | ||
| ) | ||
| } | ||
|
|
||
| const scheduledAt = flags.now | ||
| ? null | ||
| : parseCampaignSchedule(flags['scheduled-at']) | ||
| if (scheduledAt === undefined) { | ||
| throw new PolymorfaValidationError( | ||
| 'Specify exactly one of --scheduled-at or --now.', | ||
| {code: 'invalid_campaign_schedule'}, | ||
| ) | ||
| } | ||
| if ( | ||
| scheduledAt !== null && | ||
| (scheduledAt <= 0 || scheduledAt > 8_640_000_000_000_000) | ||
| ) { | ||
| throw new PolymorfaValidationError( | ||
| 'Scheduled time must be a positive, representable Unix timestamp in milliseconds.', | ||
| {code: 'invalid_campaign_schedule'}, | ||
| ) | ||
| } | ||
|
|
||
| const result = await rescheduleCampaign( | ||
| await this.messagingClient(flags, {serverApiKeyOnly: 'Campaign'}), | ||
| flags['project-slug'], | ||
| args.campaign, | ||
| scheduledAt, | ||
| {idempotencyKey: idempotencyKey(flags['idempotency-key'])}, | ||
| ) | ||
| this.writeValue( | ||
| result, | ||
| renderCampaignOperation('reschedule', result.data), | ||
| flags, | ||
| ) | ||
| } | ||
| } | ||
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
--scheduled-atcontains an impossible date such as2026-02-31T12:00:00Z,parseCampaignSchedulerelies onDate.parse, which normalizes it to March 3 rather than rejecting it. The command therefore sends a valid but unintended timestamp, so a user can silently reschedule a campaign to the wrong day; validate that the parsed calendar components match the supplied ISO instant before transport.Useful? React with 👍 / 👎.