From 70a6ad040a009bcb85b47a17750b9daff96c002b Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Wed, 7 May 2025 13:50:10 +0000 Subject: [PATCH] fix(readme): Update documentation to include usage of creation object reference and update API details. --- changelog.md | 7 ++++++ readme.md | 47 ++++++++++++++++++++++++++++++++++++++++ ts/00_commitinfo_data.ts | 2 +- 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 87788ed..123998e 100644 --- a/changelog.md +++ b/changelog.md @@ -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. diff --git a/readme.md b/readme.md index 7adc2bc..6d34bc1 100644 --- a/readme.md +++ b/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({ + 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 diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 2eb58af..1739321 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -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.' }