-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from fterh/info-command
Support alias info command
- Loading branch information
Showing
27 changed files
with
945 additions
and
439 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -30,6 +30,7 @@ Changelog can be found under Releases. | |
2. **Reply anonymously:** Reply to emails from your alias without revealing your personal email address. | ||
3. **Attachments:** Attachments are supported on incoming and outgoing emails (subject to size limits - see below). | ||
4. **Email commands:** Manage your aliases through email directly - no separate app or website required. | ||
5. **Usage stats:** Easily check the usage stats of each alias. | ||
|
||
### Receiving emails | ||
|
||
|
@@ -78,6 +79,19 @@ Dev note: This reads up to a maximum of 1MB of data (due to AWS's limitations). | |
|
||
Email `[email protected]` with the alias as the title (case-sensitive). You will receive the operation outcome (success/failure) as a reply. | ||
|
||
### Usage stats | ||
|
||
Email `[email protected]` with the alias as the title (case-sensitive). | ||
You will receive usage information for the particular alias. | ||
|
||
Supported usage stats: | ||
|
||
- Alias creation date | ||
- Emails received | ||
- Emails sent | ||
- Date of last received email | ||
- Date of last sent email | ||
|
||
#### Update an alias | ||
|
||
Coming soon - not supported yet. | ||
|
@@ -109,9 +123,13 @@ If you want to build new features or tweak existing features, you can set up a p | |
|
||
1. Ensure that the `DEV_SUBDOMAIN` environment variable is set in `.env` (e.g. `test`). | ||
2. Run `yarn run deploy-dev`. | ||
This creates a parallel development CloudFormation stack. | ||
This creates a parallel development CloudFormation stack. | ||
3. Add a new receipt rule in SES **before your production rule** to trigger your development S3 bucket. | ||
For "recipients", enter the same test subdomain as you set in step 1 (e.g. `test.yourverifieddomain.com`). | ||
Preferably, name your rule descriptively (e.g. `dev`). | ||
For "recipients", enter the same test subdomain as you set in step 1 (e.g. `test.yourverifieddomain.com`). | ||
Preferably, name your rule descriptively (e.g. `dev`). | ||
|
||
Note: You need to update your DNS records for `test.yourverifieddomain.com` as you did when verifying your domain for AWS SES. | ||
|
||
## Migration | ||
|
||
To run migration scripts, first compile using `tsc scripts/migrate_vX.ts`, then run using `node scripts/migrate_vX.js`. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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 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 |
---|---|---|
@@ -1,33 +1,17 @@ | ||
import { DynamoDB } from "aws-sdk"; | ||
import { ParsedMail } from "mailparser"; | ||
import aliasExists from "../aliasExists"; | ||
import { email, operationalDomain } from "../env"; | ||
import { Commands } from "../commandSet"; | ||
import generateAlias from "../generateAlias"; | ||
import Alias from "../models/Alias"; | ||
import sendEmail from "../sendEmail"; | ||
import storeAliasDescriptionRecord from "../storeAliasDescriptionRecord"; | ||
|
||
export default async (parsedMail: ParsedMail): Promise<void> => { | ||
const docClient = new DynamoDB.DocumentClient(); // Avoid re-initializing | ||
|
||
const description = parsedMail.subject; | ||
|
||
let generatedAlias: string; | ||
do { | ||
generatedAlias = generateAlias(); | ||
} while (await aliasExists(generatedAlias, docClient)); | ||
console.log( | ||
`Generated alias=${generatedAlias} for description=${description}` | ||
); | ||
|
||
console.log("Attempting to store alias-description record"); | ||
storeAliasDescriptionRecord(generatedAlias, description, docClient); | ||
console.log("Successfully stored alias-description record"); | ||
const alias = await Alias.generateAlias(description); | ||
|
||
await sendEmail({ | ||
from: `${Commands.Generate}@${operationalDomain}`, | ||
to: [email], | ||
subject: `Generated alias: ${generatedAlias}`, | ||
text: `You have generated ${generatedAlias}@${operationalDomain} for "${description}".` | ||
subject: `Generated alias: ${alias.value}`, | ||
text: `You have generated ${alias.value}@${operationalDomain} for "${alias.description}".` | ||
}); | ||
}; |
This file contains 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 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,49 @@ | ||
import { ParsedMail } from "mailparser"; | ||
import { Commands } from "../commandSet"; | ||
import { email, operationalDomain } from "../env"; | ||
import Alias from "../models/Alias"; | ||
import sendEmail from "../sendEmail"; | ||
|
||
const commandEmailAddress = `${Commands.Info}@${operationalDomain}`; | ||
|
||
export const prepareAliasInfoText = (alias: Alias): string => { | ||
let res = ""; | ||
|
||
res += `Alias: ${alias.value}@${operationalDomain}\n`; | ||
res += `Description: ${alias.description}\n`; | ||
res += `Created: ${alias.creationDate ? alias.creationDate : "Unknown"}\n`; | ||
res += `Emails received: ${alias.countReceived}\n`; | ||
res += `Emails sent: ${alias.countSent}\n`; | ||
res += `Email last received on: ${ | ||
alias.lastReceivedDate ? alias.lastReceivedDate : "-" | ||
}\n`; | ||
res += `Email last sent on: ${ | ||
alias.lastSentDate ? alias.lastSentDate : "-" | ||
}\n\n`; | ||
|
||
res += `Information generated on ${new Date()}`; | ||
|
||
return res; | ||
}; | ||
|
||
export default async (parsedMail: ParsedMail): Promise<void> => { | ||
const aliasValue = parsedMail.subject; | ||
const alias = await Alias.getAlias(aliasValue); | ||
|
||
if (alias === undefined) { | ||
await sendEmail({ | ||
from: commandEmailAddress, | ||
to: email, | ||
subject: `Info: ${aliasValue}@${operationalDomain} does not exist`, | ||
text: "-" | ||
}); | ||
return; | ||
} | ||
|
||
await sendEmail({ | ||
from: commandEmailAddress, | ||
to: email, | ||
subject: `Info: ${aliasValue}@${operationalDomain}`, | ||
text: prepareAliasInfoText(alias) | ||
}); | ||
}; |
This file contains 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 |
---|---|---|
@@ -1,65 +1,35 @@ | ||
import { DynamoDB } from "aws-sdk"; | ||
import config from "../config"; | ||
import { email, operationalDomain } from "../env"; | ||
import { Commands } from "../commandSet"; | ||
import Alias from "../models/Alias"; | ||
import sendEmail from "../sendEmail"; | ||
|
||
export default async (): Promise<void> => { | ||
const docClient = new DynamoDB.DocumentClient(); | ||
const docParams: DynamoDB.DocumentClient.ScanInput = { | ||
TableName: config.tableName | ||
}; | ||
const getAliasesResults = await Alias.getAllAliases(); | ||
|
||
const records: DynamoDB.DocumentClient.ScanOutput = await docClient | ||
.scan(docParams) | ||
.promise(); | ||
|
||
console.log("Successfully scanned database for records"); | ||
|
||
if (records.Items && records.Items.length === 0) { | ||
return await sendEmail({ | ||
if (getAliasesResults.aliases.length === 0) { | ||
await sendEmail({ | ||
from: `${Commands.List}@${operationalDomain}`, | ||
to: [email], | ||
subject: `Alias list (${new Date()})`, | ||
subject: `Alias list (generated on: ${new Date()})`, | ||
text: "No aliases found." | ||
}); | ||
} | ||
|
||
let mightHaveMoreRecords = false; | ||
let hasMalformedRecords = false; | ||
|
||
if (records.LastEvaluatedKey) { | ||
mightHaveMoreRecords = true; | ||
console.log( | ||
"Scan results' LastEvaluatedKey is not undefined; there might be more records in the results set" | ||
); | ||
return; | ||
} | ||
|
||
let output = "Alias : Description\n"; | ||
records.Items?.forEach(item => { | ||
if (item.description === undefined) { | ||
hasMalformedRecords = true; | ||
return console.log( | ||
`Record with alias=${item.alias} is missing the "description" attribute. Skipping.` | ||
); | ||
} | ||
output += `${item.alias} : ${item.description}\n`; | ||
getAliasesResults.aliases.forEach(alias => { | ||
output += `${alias.value} : ${alias.description}\n`; | ||
}); | ||
|
||
if (mightHaveMoreRecords) { | ||
if (getAliasesResults.lastEvaluatedKey !== undefined) { | ||
output += | ||
"There might be more records in the results set. Check the logs and database for more information."; | ||
} | ||
|
||
if (hasMalformedRecords) { | ||
output += | ||
"The database contains malformed records. Check the logs and database for more information."; | ||
} | ||
|
||
await sendEmail({ | ||
from: `${Commands.List}@${operationalDomain}`, | ||
to: [email], | ||
subject: `Alias list (${new Date()})`, | ||
subject: `Alias list (generated on: ${new Date()})`, | ||
text: output | ||
}); | ||
}; |
This file contains 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.