fix(readme): Update documentation to include usage of creation object reference and update API details.
This commit is contained in:
parent
31f0789648
commit
70a6ad040a
@ -1,5 +1,12 @@
|
||||
# Changelog
|
||||
|
||||
## 2025-05-07 - 2.0.1 - fix(readme)
|
||||
Update documentation to include usage of creation object reference and update API details.
|
||||
|
||||
- Added a new section explaining how to use the creationObjectRef in Smartmail.
|
||||
- Included detailed examples on retrieving and using the creation object reference.
|
||||
- Updated the API reference to document the getCreationObject method.
|
||||
|
||||
## 2025-05-07 - 2.0.0 - BREAKING CHANGE(smartmail)
|
||||
Improve email validation and Smartmail features: add detailed validation for email parts, caching for MX lookups, multi-recipient support, custom headers, and update dependency imports and build scripts.
|
||||
|
||||
|
47
readme.md
47
readme.md
@ -95,6 +95,51 @@ const email = new Smartmail({
|
||||
});
|
||||
```
|
||||
|
||||
### Using Creation Object Reference
|
||||
|
||||
The Smartmail constructor accepts a generic type parameter that lets you associate any additional data with your email, accessible later via the `getCreationObject()` method. This is useful for tracking, referencing original data sources, or maintaining context:
|
||||
|
||||
```typescript
|
||||
// Define your custom reference type
|
||||
interface OrderNotification {
|
||||
orderId: string;
|
||||
customerName: string;
|
||||
items: string[];
|
||||
total: number;
|
||||
}
|
||||
|
||||
// Create email with typed creation object reference
|
||||
const orderEmail = new Smartmail<OrderNotification>({
|
||||
from: 'orders@example.com',
|
||||
to: ['customer@example.com'],
|
||||
subject: 'Your Order #{{orderId}} Confirmation',
|
||||
body: 'Thank you for your order, {{customerName}}!',
|
||||
// Store the full order data as reference
|
||||
creationObjectRef: {
|
||||
orderId: '12345',
|
||||
customerName: 'John Smith',
|
||||
items: ['Product A', 'Product B'],
|
||||
total: 99.95
|
||||
}
|
||||
});
|
||||
|
||||
// Later, retrieve the original reference data
|
||||
const orderData = orderEmail.getCreationObject();
|
||||
console.log(`Processing email for order ${orderData.orderId}`);
|
||||
console.log(`Order total: $${orderData.total}`);
|
||||
|
||||
// Use the reference data for templating
|
||||
const subject = orderEmail.getSubject(orderData); // "Your Order #12345 Confirmation"
|
||||
const body = orderEmail.getBody(orderData); // "Thank you for your order, John Smith!"
|
||||
```
|
||||
|
||||
This powerful feature allows you to:
|
||||
- Maintain a link to original data sources
|
||||
- Pass the email object between systems while preserving context
|
||||
- Avoid duplicating data between email content and your application
|
||||
- Use the reference data to fill template variables
|
||||
- Access metadata about the email that doesn't get included in the actual message
|
||||
|
||||
### Adding Recipients
|
||||
|
||||
```typescript
|
||||
@ -222,6 +267,7 @@ console.log(mimeObj);
|
||||
- `headers`: Optional key-value pairs of custom headers
|
||||
- `priority`: 'high' | 'normal' | 'low' (default: 'normal')
|
||||
- `validateEmails`: Boolean (default: false) - Validate all emails
|
||||
- `creationObjectRef`: Optional reference data of any type (generic T) - Store arbitrary data with the email
|
||||
|
||||
#### Methods
|
||||
- `addRecipient(email, type?)`: Add a single recipient (to/cc/bcc)
|
||||
@ -234,6 +280,7 @@ console.log(mimeObj);
|
||||
- `getHtmlBody(data?)`: Get processed HTML body
|
||||
- `validateAllEmails()`: Validate all email addresses
|
||||
- `toMimeFormat(data?)`: Convert to MIME format object
|
||||
- `getCreationObject()`: Get the stored reference data of type T
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartmail',
|
||||
version: '2.0.0',
|
||||
version: '2.0.1',
|
||||
description: 'A unified format for representing and dealing with emails, with support for attachments and email validation.'
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user