@@ -11,11 +11,13 @@ Headlines Toolkit ecosystem.
11
11
12
12
This package contains the `HtEmailRepository`, which acts as an abstraction
13
13
layer over an `HtEmailClient` implementation (from the `ht_email_client`
14
- package). Its primary purpose is to provide a clean interface for email-related
15
- tasks while ensuring consistent error handling according to the project's
16
- standards (propagating `HtHttpException` subtypes from `ht_shared`).
14
+ package). Its primary purpose is to provide a clean, business-focused interface
15
+ for email-related tasks while ensuring consistent error handling.
17
16
18
- Currently, it focuses on sending One-Time Password (OTP) emails.
17
+ The repository translates business-specific requests (e.g., "send an OTP")
18
+ into generic, template-based calls to the underlying `HtEmailClient`,
19
+ decoupling the application's core logic from the specifics of email
20
+ formatting and delivery.
19
21
20
22
## Getting Started
21
23
@@ -38,23 +40,27 @@ import 'package:ht_email_repository/ht_email_repository.dart';
38
40
## Features
39
41
40
42
* Provides the `HtEmailRepository` class.
41
- * Offers a `sendOtpEmail` method to facilitate sending OTPs via an injected
42
- `HtEmailClient`.
43
+ * Offers a `sendOtpEmail` method that abstracts the process of sending an
44
+ OTP. It calls the underlying client's `sendTransactionalEmail` method,
45
+ passing the required template ID and data.
43
46
44
47
## Usage
45
48
46
49
To use this repository, you need to provide an instance of a concrete
47
- `HtEmailClient` implementation during instantiation.
50
+ `HtEmailClient` implementation during instantiation. The consumer of the
51
+ repository is responsible for providing the template ID.
48
52
49
53
```dart
50
- // Example (assuming you have an HtEmailClient instance named 'myEmailClient' )
54
+ // Example (in a service that has access to config )
51
55
final emailRepository = HtEmailRepository(emailClient: myEmailClient);
56
+ const otpTemplateId = 'd-123456789'; // This would come from config
52
57
53
58
// Now you can use the repository methods
54
59
try {
55
60
await emailRepository.sendOtpEmail(
56
61
recipientEmail: '
[email protected] ',
57
- otpCode: '123456',****
62
+ otpCode: '123456',
63
+ templateId: otpTemplateId,
58
64
);
59
65
print('OTP email sent successfully!');
60
66
} on HtHttpException catch (e) {
0 commit comments