Skip to content

Commit

Permalink
build: ts errors fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
wildduck2 committed Aug 9, 2024
1 parent c027163 commit 3607a42
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 13 deletions.
58 changes: 49 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ A powerful and flexible toolkit for building, validating, and processing emails
- **Attachment Handling**: Add, validate, and format email attachments.
- **Encoding Utilities**: Encode content in Base64 for attachments.
- **Validation**: Ensure email content, headers, and attachments are valid with built-in validation schemas.
- **Custom Error Handling**: Handle email-related errors with a custom `EmailError` class.

## Installation

Expand All @@ -34,23 +35,22 @@ const header = new EmailBuilderHeader();
header
.setFrom("ahmed <ahmed@gmail.com>")
.setTo("ahmed <ahmed@gmail.com>")
.setCc("ahmed <ahmed@gmai.com>")
.setBcc("ahmed <ahmed@gmai.com>")
.setSubject("this is wild duck email test subject")
.setCc("ahmed <ahmed@gmail.com>")
.setBcc("ahmed <ahmed@gmail.com>")
.setSubject("This is a test email subject")
.setInReplyTo("ahmed@gmail.com")
.setMIMEVersion("1.0")
.setContentTransferEncoding("quoted-printable")
.setContentType("text/html")
.setCharset("utf8");
.setCharset("utf-8");
```

### Email Attachment

Add attachments to your email:

```typescript
import { EmailBuilderAttachment } from "@ahmedayob/email-toolkit";
import { Base64 } from "@ahmedayob/email-toolkit";
import { EmailBuilderAttachment, Base64 } from "@ahmedayob/email-toolkit";

const attachment = new EmailBuilderAttachment();
attachment.addAttachment({
Expand All @@ -63,7 +63,9 @@ attachment.addAttachment({
filename: "test.txt",
mimeType: "text/plain",
attachmentId: "1234",
attachmentContent: Base64.encodeToBase64("test"),
attachmentContent: Base64.encodeToBase64(
"This is the content of the attachment."
),
});
```

Expand All @@ -75,12 +77,41 @@ Combine headers and attachments to create the final email:
import { EmailBuilder } from "@ahmedayob/email-toolkit";

const email = new EmailBuilder();
email.messagebody = "this is message body";
email.messagebody = "<p>This is the message body</p>";

const finalEmail = email.getRawMessage(header.headers, attachment.attachments);
console.log(finalEmail);
```

### Encoding and Signature

Generate base64-encoded messages and email signatures:

```typescript
import { EmailBuilder } from "@ahmedayob/email-toolkit";

const email = new EmailBuilder();
email.messagebody = "<p>This is the message body</p>";

const encodedMessage = email.getEncodedMessage(
header.headers,
attachment.attachments
);
console.log(encodedMessage);

email.setSignature({
url: "https://github.com/wildduck2",
name: "Ahmed Ayob",
});

const signature = email.getSignature({
from: "ahmed@example.com",
url: "https://github.com/wildduck2",
name: "Ahmed Ayob",
});
console.log(signature.join("\n"));
```

## API

### `EmailBuilderHeader`
Expand All @@ -105,11 +136,20 @@ console.log(finalEmail);

- **messagebody**: Sets the body of the email.
- **getRawMessage**(headers: HeadersType, attachments?: AttachmentType[]): Gets the raw email message.
- **getEncodedMessage**(headers: HeadersType, attachments?: AttachmentType[]): Gets the base64-encoded email message.
- **getSignature**(signatureDetails: GetSignatureType): Generates a formatted signature block.
- **setSignature**(signatureDetails: NonNullableType<Omit<GetSignatureType, "from">>): Sets the email signature details.

### `Base64`

- **encodeToBase64**(data: string): Encodes data to Base64.

### `EmailError`

- **name**: The name of the error.
- **description**: A description of the error.
- **constructor**({ message, description }: { message: string; description: string }): Constructs a new `EmailError`.

## Validation

Validation schemas are available to ensure data correctness:
Expand All @@ -123,7 +163,7 @@ Validation schemas are available to ensure data correctness:

## Contributing

Contributions are welcome! Please open issues and pull requests on the [GitHub repository](https://github.com/wildduck2/email-toolkit).
Contributions are welcome! Please open issues and pull requests on the [GitHub repository](https://github.com/ahmedayob/email-toolkit).

## License

Expand Down
2 changes: 1 addition & 1 deletion src/EmailBiulderHeader/__test__/EmailBuilderHeader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe("EmailBuilderHeader", () => {
});

it('should set the "In-Reply-To" header', () => {
const inReplyTo = "message-id@example.com";
const inReplyTo = "<message-id@example.com>";
emailBuilderHeader.setInReplyTo(inReplyTo);
const headers = emailBuilderHeader.getHeaders();
expect(headers["In-Reply-To"]).toBe(inReplyTo);
Expand Down
2 changes: 1 addition & 1 deletion src/EmailBuilder/EmailBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class EmailBuilder implements EmailBuilderClass {
*
* @type {ApplicationSignature}
*/
applicationSignature: ApplicationSignature = {
applicationSignature: Omit<ApplicationSignature, "from"> = {
url: "https://github.com/wildduck2",
name: "ahmed ayob",
};
Expand Down
2 changes: 1 addition & 1 deletion src/EmailBuilder/__test__/EmailBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ describe("EmailBuilder", () => {
});

it("should set the email signature correctly", () => {
const signatureData: NonNullableType<GetSignatureType> = {
const signatureData: NonNullableType<Omit<GetSignatureType, "from">> = {
url: "https://example.com",
name: "Example App",
};
Expand Down
2 changes: 1 addition & 1 deletion src/zod/zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const HeadersTypeSchema = z.object({
* The email address that this message is a reply to.
* @type {string | undefined}
*/
"In-Reply-To": z.string().email().optional(),
"In-Reply-To": z.string().optional(),

/**
* The content type of the email.
Expand Down

0 comments on commit 3607a42

Please sign in to comment.