Repository navigation
CLI: explicit STOP confirmation preference commands #50
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
6 commits
Select commit
Hold shift + click to select a range
3b66f3a
feat: add explicit STOP confirmation commands
purpshell c9d41b6
Merge remote-tracking branch 'origin/dev' into codex/campaign-stop-co…
purpshell 89d520e
Report malformed STOP preferences as validation errors
purpshell 22c163a
Merge dev; pin @polymorfa/sdk 0.1.0-dev.20261005233122
purpshell 7d84fe9
Report unexpected STOP confirmation responses as validation errors
purpshell 0f89fd2
Merge dev; keep the SDK pin with STOP confirmations (0.1.0-dev.202610…
purpshell 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,17 @@ | ||
| import {BaseCommand} from '../../../base-command.js' | ||
| import { | ||
| readConfirmationSummary, | ||
| renderConfirmationSummary, | ||
| } from '../../../services/stop-confirmations.js' | ||
|
|
||
| export default class ConfirmationSummary extends BaseCommand { | ||
| static override description = | ||
| 'Read 30-day STOP acknowledgement outcome counts. Provider acceptance does not confirm delivery.' | ||
| async run(): Promise<void> { | ||
| const {flags} = await this.parse(ConfirmationSummary) | ||
| const result = await readConfirmationSummary( | ||
| await this.platformClient(flags), | ||
| ) | ||
| this.writeValue(result, renderConfirmationSummary(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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import {Flags} from '@oclif/core' | ||
| import {BaseCommand} from '../../../base-command.js' | ||
| import { | ||
| confirmationPreference, | ||
| renderConfirmationSettings, | ||
| updateConfirmationSettings, | ||
| } from '../../../services/stop-confirmations.js' | ||
|
|
||
| export default class ConfirmationSettingsUpdate extends BaseCommand { | ||
| static override description = | ||
| 'Save an optional STOP acknowledgement preference using the observed team and revision. Enabling requires beta access and an explicit language. This write is never retried automatically; read settings after an uncertain save.' | ||
| static override examples = [ | ||
| '<%= config.bin %> <%= command.id %> --team-id TEAM_UUID --revision 0 --no-enabled', | ||
| '<%= config.bin %> <%= command.id %> --team-id TEAM_UUID --revision 1 --enabled --locale pt-BR', | ||
| ] | ||
| static override flags = { | ||
| enabled: Flags.boolean({ | ||
| allowNo: true, | ||
| required: true, | ||
| description: | ||
| 'Explicitly enable acknowledgements or pass --no-enabled to disable. Suppression stays in place.', | ||
| }), | ||
| locale: Flags.string({ | ||
| options: ['en', 'pt-BR', 'es'], | ||
| description: | ||
| 'Acknowledgement language; required when enabling. No language is inferred.', | ||
| }), | ||
| revision: Flags.integer({ | ||
| required: true, | ||
| min: 0, | ||
| max: 2147483646, | ||
| description: | ||
| 'Observed settings revision from confirmations view. Stale revisions fail with 409.', | ||
| }), | ||
| 'team-id': Flags.string({ | ||
| required: true, | ||
| description: | ||
| 'Team UUID returned by confirmations view; must match the authenticated team.', | ||
| }), | ||
| } | ||
| async run(): Promise<void> { | ||
| const {flags} = await this.parse(ConfirmationSettingsUpdate) | ||
| const body = confirmationPreference(flags) | ||
| const result = await updateConfirmationSettings( | ||
| await this.platformClient(flags), | ||
| body, | ||
| ) | ||
| this.writeValue(result, renderConfirmationSettings(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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import {BaseCommand} from '../../../base-command.js' | ||
| import { | ||
| readConfirmationSettings, | ||
| renderConfirmationSettings, | ||
| } from '../../../services/stop-confirmations.js' | ||
|
|
||
| export default class ConfirmationSettingsView extends BaseCommand { | ||
| static override description = | ||
| 'Read the team’s optional STOP acknowledgement preference. Disabled by default; enabling requires beta access.' | ||
| async run(): Promise<void> { | ||
| const {flags} = await this.parse(ConfirmationSettingsView) | ||
| const result = await readConfirmationSettings( | ||
| await this.platformClient(flags), | ||
| ) | ||
| this.writeValue(result, renderConfirmationSettings(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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| import { | ||
| PolymorfaValidationError, | ||
| type ClientInstance, | ||
| type StopConfirmationSettings, | ||
| type StopConfirmationSummary, | ||
| type UpdateStopConfirmationSettingsRequest, | ||
| type ResponseMetadata, | ||
| } from '@polymorfa/sdk' | ||
| import {z} from 'zod' | ||
|
|
||
| const Locale = z.enum(['en', 'pt-BR', 'es']) | ||
| const Preference = z | ||
| .object({ | ||
| teamId: z.uuid(), | ||
| enabled: z.boolean(), | ||
| locale: Locale.nullable(), | ||
| revision: z.number().int().min(0).max(2147483646), | ||
| }) | ||
| .strict() | ||
| .refine( | ||
| (value) => !value.enabled || value.locale !== null, | ||
| 'Select --locale when enabling confirmations.', | ||
| ) | ||
| const Settings = z | ||
| .object({ | ||
| teamId: z.uuid(), | ||
| enabled: z.boolean(), | ||
| locale: Locale.nullable(), | ||
| revision: z.number().int().nonnegative(), | ||
| textRevision: z.literal(1), | ||
| acknowledgement: z.string().nullable(), | ||
| updatedAt: z.number().nullable(), | ||
| }) | ||
| .strict() | ||
| const Summary = z | ||
| .object({ | ||
| enabled: z.boolean(), | ||
| counts: z | ||
| .object({ | ||
| queued: z.number().int().nonnegative(), | ||
| admitted: z.number().int().nonnegative(), | ||
| completed: z.number().int().nonnegative(), | ||
| failed: z.number().int().nonnegative(), | ||
| unknown: z.number().int().nonnegative(), | ||
| }) | ||
| .strict(), | ||
| }) | ||
| .strict() | ||
|
|
||
| type Client = ClientInstance<'organization'> | ||
| function parseResponse<T>( | ||
| schema: z.ZodType<T>, | ||
| value: unknown, | ||
| message: string, | ||
| ): T { | ||
| const parsed = schema.safeParse(value) | ||
| if (!parsed.success) | ||
| throw new PolymorfaValidationError(message, { | ||
| code: 'invalid_confirmation_response', | ||
| }) | ||
| return parsed.data | ||
| } | ||
| const UNEXPECTED_READ = | ||
| 'The STOP confirmation response did not match the expected shape. Update the CLI.' | ||
| function result<T>(data: T, metadata: ResponseMetadata) { | ||
| return { | ||
| data, | ||
| metadata: { | ||
| attempts: metadata.attempts, | ||
| status: metadata.status, | ||
| ...(metadata.requestId === undefined | ||
| ? {} | ||
| : {requestId: metadata.requestId}), | ||
| ...(metadata.apiVersion === undefined | ||
| ? {} | ||
| : {apiVersion: metadata.apiVersion}), | ||
| }, | ||
| } | ||
| } | ||
| export async function readConfirmationSettings(client: Client) { | ||
| const response = await client.optOuts.getConfirmationSettings() | ||
| return result( | ||
| parseResponse(Settings, response.data.data, UNEXPECTED_READ), | ||
| response.metadata, | ||
| ) | ||
| } | ||
| export async function readConfirmationSummary(client: Client) { | ||
| const response = await client.optOuts.getConfirmationSummary() | ||
| return result( | ||
| parseResponse(Summary, response.data.data, UNEXPECTED_READ), | ||
| response.metadata, | ||
| ) | ||
| } | ||
| export function confirmationPreference(flags: { | ||
| enabled: boolean | ||
| 'team-id': string | ||
| revision: number | ||
| locale?: string | undefined | ||
| }): UpdateStopConfirmationSettingsRequest { | ||
| const parsed = Preference.safeParse({ | ||
| teamId: flags['team-id'], | ||
| enabled: flags.enabled, | ||
| locale: flags.locale ?? null, | ||
| revision: flags.revision, | ||
| }) | ||
| if (!parsed.success) | ||
| throw new PolymorfaValidationError( | ||
| 'Invalid STOP confirmation preference. Check the team UUID, revision, and language.', | ||
| {code: 'invalid_confirmation_preference'}, | ||
| ) | ||
| return parsed.data as UpdateStopConfirmationSettingsRequest | ||
| } | ||
| export async function updateConfirmationSettings( | ||
| client: Client, | ||
| body: UpdateStopConfirmationSettingsRequest, | ||
| ) { | ||
| const response = await client.optOuts.updateConfirmationSettings(body, { | ||
| maxNetworkRetries: 0, | ||
| }) | ||
| // The save already ran; an unexpected body does not prove it failed. | ||
| return result( | ||
| parseResponse( | ||
| Settings, | ||
| response.data.data, | ||
| 'The STOP confirmation response did not match the expected shape. Run `polymorfa optout confirmations view` to check whether the preference was saved.', | ||
| ), | ||
| response.metadata, | ||
| ) | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| export function renderConfirmationSettings( | ||
| settings: StopConfirmationSettings, | ||
| ): string { | ||
| return [ | ||
| `Team\t${settings.teamId}`, | ||
| `Enabled\t${settings.enabled}`, | ||
| `Language\t${settings.locale ?? 'Not selected'}`, | ||
| `Revision\t${settings.revision}`, | ||
| `Acknowledgement\t${settings.acknowledgement ?? 'Not selected'}`, | ||
| ].join('\n') | ||
| } | ||
| export function renderConfirmationSummary( | ||
| summary: StopConfirmationSummary, | ||
| ): string { | ||
| return [ | ||
| `Enabled\t${summary.enabled}`, | ||
| 'Outcomes in the last 30 days', | ||
| `Queued\t${summary.counts.queued}`, | ||
| `Admitted\t${summary.counts.admitted}`, | ||
| `Provider accepted\t${summary.counts.completed}`, | ||
| `Skipped or rejected\t${summary.counts.failed}`, | ||
| `Unknown\t${summary.counts.unknown}`, | ||
| 'Provider acceptance does not confirm delivery. Unknown outcomes must not be resent; suppression remains recorded.', | ||
| ].join('\n') | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.