-
Notifications
You must be signed in to change notification settings - Fork 8
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
feat: add support for templates delete
command
#82
Conversation
6dd7fbf
to
0f3ba45
Compare
templates delete
command
@derekrushforth @tomek-ac just checking in on this PR, I used it again a couple of weeks ago and it worked pretty well. Would love to have this be part of the library instead of having to run my own fork. Let me know if you need anything else to get this merged. Thanks! |
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.
Thanks for working on this @rlueder! I left a few suggestions for you to consider.
Besides that here is a few other things that would need to be addressed before merging:
- the delete command can be run in non-interactive mode in CI/CD
- we have integration tests for this code
- the "delete" command is listed when running
postmark templates
- we will need to update our wiki to explain how to use it. For this please prepare a separate Markdown file as part of the PR.
/** | ||
* Ask user a series of questions before deleting templates. | ||
*/ | ||
|
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.
/** | ||
* if the user has selected to delete templates by id | ||
*/ | ||
|
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.
/** | |
* if the user has selected to delete templates by id | |
*/ |
This doesn't add much, the code is self-explanatory.
// TODO we probably want an actual validation | ||
// against ids/aliases that exist in the server |
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.
I'd say we don't need to validate that. Ideally running the command with a non-existing ID should display a warning.
/** | ||
* if the user has selected to delete all templates | ||
*/ | ||
|
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.
/** | |
* if the user has selected to delete all templates | |
*/ |
again, the code is self-explanatory. Comments are most valuable when they explain the "why" leaving the "what" to the code.
const userInput = await input({ | ||
message: | ||
"Enter template id(s)/alias(es) - separate with commas if multiple:", | ||
validate: validateUserInput, |
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.
Maybe we could inline the validation if it's so simple?
validate: validateUserInput, | |
validate: (s) => s.trim().length > 0, // don't allow empty input |
if (templateType) { | ||
confirmed = await confirm({ | ||
default: false, | ||
message: `Delete ALL templates? Are you sure?`, |
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.
message: `Delete ALL templates? Are you sure?`, | |
message: 'Delete ALL templates? Are you sure?', |
|
||
if (!totalCount) { | ||
spinner.stop(); | ||
return fatalError("There are no templates on this server."); |
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.
We probably shouldn't exit with an error if there are no templates on the server. I guess this would only happen if the user requested to delete all the servers. In such case the user's intention is to not have templates so when there are not any, then we should be good.
const response = await client.getTemplates({ | ||
count: 300, | ||
templateType, | ||
}); |
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.
In 99% of the cases we would get all the templates with this call as Postmark allows for 100 templates per Server by default. But to make it a bit more resilient and correct, we should fetch all the templates, not the only first batch. We'd need a loop to fill the templates
array.
|
||
try { | ||
let templates = []; | ||
let totalCount = 0; |
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.
Can't we use templates.length
instead of adding another variable?
/* eslint-disable @typescript-eslint/member-delimiter-style */ | ||
|
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.
Please follow the local conventions.
/* eslint-disable @typescript-eslint/member-delimiter-style */ |
This is an implementation of a
postmark templates delete
command, allowing users to delete by id or alias (one or multiple) or all templates from their server.