Skip to content

feat: add support for templates delete command - #82

Closed
rlueder wants to merge 4 commits into
ActiveCampaign:mainfrom
rlueder:main
Closed

rlueder wants to merge 4 commits into
ActiveCampaign:mainfrom
rlueder:main

Conversation

@rlueder

@rlueder rlueder commented Sep 30, 2023 •

Copy link
Copy Markdown

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.

$ postmark templates delete

> postmark templates delete
? Please enter your server token ••••••••••••••••••••••••••••••••••••
? Choose how you want to delete templates: Delete templates by id
? Enter template id(s) - separated by commas if multiple: 33336536, 33336535, 33336549
All finished! 3 templates have been deleted.
> postmark templates delete
? Please enter your server token ••••••••••••••••••••••••••••••••••••
? Choose how you want to delete templates: Delete all templates
? Which template type do you want to delete? Templates
? Delete ALL templates? Are you sure? yes
? Enter "delete all templates" to confirm: delete all templates
All finished! 80 templates have been deleted.
> postmark templates delete
? Please enter your server token ••••••••••••••••••••••••••••••••••••
? Choose how you want to delete templates: Delete all templates
? Which template type do you want to delete? Layouts
? Delete ALL templates? Are you sure? yes
? Enter "delete all templates" to confirm: delete all templates
All finished! 4 templates have been deleted.

@rlueder rlueder changed the title feat: add support for delete command feat: add support for templates delete command Oct 1, 2023
@rlueder

rlueder commented Jan 23, 2024 •

Copy link
Copy Markdown
Author

@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!

@tomek-ac tomek-ac left a comment

Copy link
Copy Markdown
Contributor

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.
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Comment on lines +57 to +60
/**
* if the user has selected to delete templates by id
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
* if the user has selected to delete templates by id
*/

This doesn't add much, the code is self-explanatory.

Comment on lines +62 to +63
// TODO we probably want an actual validation
// against ids/aliases that exist in the server

Copy link
Copy Markdown
Contributor

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.

Comment on lines +88 to +91
/**
* if the user has selected to delete all templates
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
* 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,

@tomek-ac tomek-ac Feb 1, 2024 •

Copy link
Copy Markdown
Contributor

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?

Suggested change
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?`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.");

Copy link
Copy Markdown
Contributor

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.

Comment on lines +174 to +177
const response = await client.getTemplates({
count: 300,
templateType,
});

Copy link
Copy Markdown
Contributor

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;

Copy link
Copy Markdown
Contributor

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?

Comment on lines +1 to +2
/* eslint-disable @typescript-eslint/member-delimiter-style */

Copy link
Copy Markdown
Contributor

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.

Suggested change
/* eslint-disable @typescript-eslint/member-delimiter-style */

@rlueder rlueder closed this Jul 13, 2024
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.

2 participants