@vulog/aima-notifier 1.2.45 → 1.2.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -249
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,27 +1,29 @@
|
|
|
1
1
|
# @vulog/aima-notifier
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Email notification sending.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
```
|
|
8
|
-
npm install @vulog/aima-
|
|
7
|
+
```sh
|
|
8
|
+
npm install @vulog/aima-notifier @vulog/aima-client @vulog/aima-core
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
```javascript
|
|
13
|
+
```ts
|
|
16
14
|
import { getClient } from '@vulog/aima-client';
|
|
17
15
|
import { sendEmail } from '@vulog/aima-notifier';
|
|
18
16
|
|
|
19
|
-
const client = getClient({
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
const client = getClient({ /* client options */ });
|
|
18
|
+
|
|
19
|
+
await sendEmail(client, {
|
|
20
|
+
to: ['user@example.com'],
|
|
21
|
+
type: 'trip_confirmation',
|
|
22
|
+
lang: 'en',
|
|
23
|
+
bodyData: {
|
|
24
|
+
userName: 'Jane Doe',
|
|
25
|
+
tripId: 'trip-uuid',
|
|
26
|
+
},
|
|
25
27
|
});
|
|
26
28
|
```
|
|
27
29
|
|
|
@@ -29,44 +31,22 @@ const client = getClient({
|
|
|
29
31
|
|
|
30
32
|
### sendEmail
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
```javascript
|
|
35
|
-
const result = await sendEmail(client, {
|
|
36
|
-
bodyData: {
|
|
37
|
-
userName: 'John Doe',
|
|
38
|
-
vehicleId: 'vehicle-123',
|
|
39
|
-
tripId: 'trip-456'
|
|
40
|
-
},
|
|
41
|
-
lang: 'en_GB',
|
|
42
|
-
to: ['user@example.com', 'admin@example.com'],
|
|
43
|
-
type: 'trip_confirmation'
|
|
44
|
-
});
|
|
34
|
+
```ts
|
|
35
|
+
sendEmail(client: Client, data: SendEmailParam): Promise<void>
|
|
45
36
|
```
|
|
46
37
|
|
|
47
|
-
|
|
48
|
-
- `client`: AIMA client instance
|
|
49
|
-
- `emailData`: Email configuration object
|
|
50
|
-
- `bodyData`: Dynamic data to include in the email template
|
|
51
|
-
- `lang`: Language code (e.g., 'en_GB', 'fr_FR', 'es_ES')
|
|
52
|
-
- `to`: Array of recipient email addresses
|
|
53
|
-
- `type`: Email template type
|
|
38
|
+
Sends an email using a notifier service template. Recipient addresses in `to[]` are validated as valid email addresses.
|
|
54
39
|
|
|
55
|
-
**
|
|
40
|
+
**Params:** `client` — Authenticated AIMA client; `data` — email payload
|
|
41
|
+
**Returns:** `Promise<void>`
|
|
56
42
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
### SendEmailData
|
|
43
|
+
> The `type` field is a free-form string. Available template names depend on the notifier service configuration, not on this SDK.
|
|
60
44
|
|
|
61
|
-
|
|
62
|
-
interface SendEmailData {
|
|
63
|
-
[key: string]: any; // Dynamic data for email template
|
|
64
|
-
}
|
|
65
|
-
```
|
|
45
|
+
## Types
|
|
66
46
|
|
|
67
47
|
### SendEmailParam
|
|
68
48
|
|
|
69
|
-
```
|
|
49
|
+
```ts
|
|
70
50
|
interface SendEmailParam {
|
|
71
51
|
bodyData: SendEmailData;
|
|
72
52
|
lang: string;
|
|
@@ -75,213 +55,10 @@ interface SendEmailParam {
|
|
|
75
55
|
}
|
|
76
56
|
```
|
|
77
57
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
Common email template types include:
|
|
81
|
-
- `welcome`: Welcome email for new users
|
|
82
|
-
- `trip_confirmation`: Trip booking confirmation
|
|
83
|
-
- `trip_reminder`: Trip reminder notification
|
|
84
|
-
- `payment_receipt`: Payment confirmation
|
|
85
|
-
- `password_reset`: Password reset instructions
|
|
86
|
-
- `account_verification`: Account verification email
|
|
87
|
-
- `trip_completed`: Trip completion summary
|
|
88
|
-
- `vehicle_alert`: Vehicle-related alerts
|
|
89
|
-
- `billing_notification`: Billing and invoice notifications
|
|
90
|
-
|
|
91
|
-
## Error Handling
|
|
92
|
-
|
|
93
|
-
The function will throw appropriate errors if:
|
|
94
|
-
- Required parameters are missing
|
|
95
|
-
- Invalid email addresses are provided
|
|
96
|
-
- Email template type is not supported
|
|
97
|
-
- Network errors occur
|
|
98
|
-
|
|
99
|
-
## Examples
|
|
100
|
-
|
|
101
|
-
### Basic Email Sending
|
|
102
|
-
|
|
103
|
-
```javascript
|
|
104
|
-
import { getClient } from '@vulog/aima-client';
|
|
105
|
-
import { sendEmail } from '@vulog/aima-notifier';
|
|
106
|
-
|
|
107
|
-
const client = getClient({
|
|
108
|
-
apiKey: 'your-api-key',
|
|
109
|
-
baseUrl: 'https://your-api-base-url',
|
|
110
|
-
clientId: 'your-client-id',
|
|
111
|
-
clientSecret: 'your-client-secret',
|
|
112
|
-
fleetId: 'your-fleet-id',
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
async function sendBasicEmail() {
|
|
116
|
-
try {
|
|
117
|
-
const result = await sendEmail(client, {
|
|
118
|
-
bodyData: {
|
|
119
|
-
userName: 'John Doe',
|
|
120
|
-
message: 'Welcome to our service!'
|
|
121
|
-
},
|
|
122
|
-
lang: 'en_GB',
|
|
123
|
-
to: ['john.doe@example.com'],
|
|
124
|
-
type: 'welcome'
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
console.log('Email sent successfully:', result);
|
|
128
|
-
return result;
|
|
129
|
-
} catch (error) {
|
|
130
|
-
console.error('Email sending error:', error);
|
|
131
|
-
throw error;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
### Trip Confirmation Email
|
|
137
|
-
|
|
138
|
-
```javascript
|
|
139
|
-
async function sendTripConfirmation(client, userEmail, tripData) {
|
|
140
|
-
try {
|
|
141
|
-
const result = await sendEmail(client, {
|
|
142
|
-
bodyData: {
|
|
143
|
-
userName: tripData.userName,
|
|
144
|
-
vehicleName: tripData.vehicleName,
|
|
145
|
-
vehiclePlate: tripData.vehiclePlate,
|
|
146
|
-
startTime: tripData.startTime,
|
|
147
|
-
endTime: tripData.endTime,
|
|
148
|
-
startLocation: tripData.startLocation,
|
|
149
|
-
endLocation: tripData.endLocation,
|
|
150
|
-
totalCost: tripData.totalCost,
|
|
151
|
-
currency: tripData.currency
|
|
152
|
-
},
|
|
153
|
-
lang: tripData.locale || 'en_GB',
|
|
154
|
-
to: [userEmail],
|
|
155
|
-
type: 'trip_confirmation'
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
console.log('Trip confirmation email sent:', result);
|
|
159
|
-
return result;
|
|
160
|
-
} catch (error) {
|
|
161
|
-
console.error('Trip confirmation email error:', error);
|
|
162
|
-
throw error;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
### Multi-language Email Support
|
|
168
|
-
|
|
169
|
-
```javascript
|
|
170
|
-
async function sendLocalizedEmail(client, userEmail, userLocale, emailType, data) {
|
|
171
|
-
try {
|
|
172
|
-
// Map common locales to supported language codes
|
|
173
|
-
const localeMap = {
|
|
174
|
-
'en': 'en_GB',
|
|
175
|
-
'en-US': 'en_GB',
|
|
176
|
-
'en-GB': 'en_GB',
|
|
177
|
-
'fr': 'fr_FR',
|
|
178
|
-
'fr-FR': 'fr_FR',
|
|
179
|
-
'es': 'es_ES',
|
|
180
|
-
'es-ES': 'es_ES',
|
|
181
|
-
'de': 'de_DE',
|
|
182
|
-
'de-DE': 'de_DE'
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
const lang = localeMap[userLocale] || 'en_GB';
|
|
186
|
-
|
|
187
|
-
const result = await sendEmail(client, {
|
|
188
|
-
bodyData: data,
|
|
189
|
-
lang: lang,
|
|
190
|
-
to: [userEmail],
|
|
191
|
-
type: emailType
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
console.log(`Email sent in ${lang}:`, result);
|
|
195
|
-
return result;
|
|
196
|
-
} catch (error) {
|
|
197
|
-
console.error('Localized email error:', error);
|
|
198
|
-
throw error;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
### Bulk Email Sending
|
|
204
|
-
|
|
205
|
-
```javascript
|
|
206
|
-
async function sendBulkEmails(client, recipients, emailType, data) {
|
|
207
|
-
try {
|
|
208
|
-
const results = await Promise.all(
|
|
209
|
-
recipients.map(recipient =>
|
|
210
|
-
sendEmail(client, {
|
|
211
|
-
bodyData: {
|
|
212
|
-
...data,
|
|
213
|
-
userName: recipient.name,
|
|
214
|
-
userEmail: recipient.email
|
|
215
|
-
},
|
|
216
|
-
lang: recipient.locale || 'en_GB',
|
|
217
|
-
to: [recipient.email],
|
|
218
|
-
type: emailType
|
|
219
|
-
}).catch(error => {
|
|
220
|
-
console.error(`Failed to send email to ${recipient.email}:`, error);
|
|
221
|
-
return { error, recipient };
|
|
222
|
-
})
|
|
223
|
-
)
|
|
224
|
-
);
|
|
225
|
-
|
|
226
|
-
const successful = results.filter(r => !r.error);
|
|
227
|
-
const failed = results.filter(r => r.error);
|
|
228
|
-
|
|
229
|
-
console.log(`Bulk email results: ${successful.length} successful, ${failed.length} failed`);
|
|
230
|
-
|
|
231
|
-
return { successful, failed };
|
|
232
|
-
} catch (error) {
|
|
233
|
-
console.error('Bulk email error:', error);
|
|
234
|
-
throw error;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
### Email Template Testing
|
|
58
|
+
### SendEmailData
|
|
240
59
|
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
const testTemplates = [
|
|
245
|
-
'welcome',
|
|
246
|
-
'trip_confirmation',
|
|
247
|
-
'payment_receipt',
|
|
248
|
-
'password_reset',
|
|
249
|
-
'account_verification'
|
|
250
|
-
];
|
|
251
|
-
|
|
252
|
-
const testData = {
|
|
253
|
-
userName: 'Test User',
|
|
254
|
-
vehicleName: 'Test Vehicle',
|
|
255
|
-
vehiclePlate: 'TEST-123',
|
|
256
|
-
startTime: '2024-01-01T10:00:00Z',
|
|
257
|
-
endTime: '2024-01-01T11:00:00Z',
|
|
258
|
-
totalCost: 15.50,
|
|
259
|
-
currency: 'EUR'
|
|
260
|
-
};
|
|
261
|
-
|
|
262
|
-
const results = [];
|
|
263
|
-
|
|
264
|
-
for (const template of testTemplates) {
|
|
265
|
-
try {
|
|
266
|
-
const result = await sendEmail(client, {
|
|
267
|
-
bodyData: testData,
|
|
268
|
-
lang: 'en_GB',
|
|
269
|
-
to: ['test@example.com'],
|
|
270
|
-
type: template
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
results.push({ template, status: 'success', result });
|
|
274
|
-
console.log(`✅ Template ${template} sent successfully`);
|
|
275
|
-
} catch (error) {
|
|
276
|
-
results.push({ template, status: 'error', error: error.message });
|
|
277
|
-
console.log(`❌ Template ${template} failed:`, error.message);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
return results;
|
|
282
|
-
} catch (error) {
|
|
283
|
-
console.error('Email template testing error:', error);
|
|
284
|
-
throw error;
|
|
285
|
-
}
|
|
60
|
+
```ts
|
|
61
|
+
interface SendEmailData {
|
|
62
|
+
[key: string]: any;
|
|
286
63
|
}
|
|
287
64
|
```
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vulog/aima-notifier",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.47",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.cts",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"author": "Vulog",
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@vulog/aima-client": "1.2.
|
|
36
|
-
"@vulog/aima-core": "1.2.
|
|
35
|
+
"@vulog/aima-client": "1.2.47",
|
|
36
|
+
"@vulog/aima-core": "1.2.47"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"zod": "^4.3.6"
|