@vulog/aima-notifier 1.1.88 → 1.1.91
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 +273 -18
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,32 +1,287 @@
|
|
|
1
1
|
# @vulog/aima-notifier
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Notification management module for the AIMA platform. This module provides functionality to send emails and other notifications to users.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Call the AiMA notifier component to send an email
|
|
5
|
+
## Installation
|
|
8
6
|
|
|
7
|
+
```bash
|
|
8
|
+
npm install @vulog/aima-client @vulog/aima-core @vulog/aima-notifier
|
|
9
9
|
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Initialize Client
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
10
16
|
import { getClient } from '@vulog/aima-client';
|
|
11
17
|
import { sendEmail } from '@vulog/aima-notifier';
|
|
12
18
|
|
|
13
19
|
const client = getClient({
|
|
14
|
-
apiKey: '
|
|
15
|
-
baseUrl: '
|
|
16
|
-
clientId: '
|
|
17
|
-
clientSecret: '
|
|
18
|
-
fleetId: '
|
|
20
|
+
apiKey: 'your-api-key',
|
|
21
|
+
baseUrl: 'https://your-api-base-url',
|
|
22
|
+
clientId: 'your-client-id',
|
|
23
|
+
clientSecret: 'your-client-secret',
|
|
24
|
+
fleetId: 'your-fleet-id',
|
|
19
25
|
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## API Reference
|
|
20
29
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
30
|
+
### sendEmail
|
|
31
|
+
|
|
32
|
+
Send an email notification to users.
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
const result = await sendEmail(client, {
|
|
36
|
+
bodyData: {
|
|
37
|
+
userName: 'John Doe',
|
|
38
|
+
vehicleId: 'vehicle-123',
|
|
39
|
+
tripId: 'trip-456'
|
|
40
|
+
},
|
|
26
41
|
lang: 'en_GB',
|
|
27
|
-
to: ['
|
|
28
|
-
type: '
|
|
29
|
-
};
|
|
42
|
+
to: ['user@example.com', 'admin@example.com'],
|
|
43
|
+
type: 'trip_confirmation'
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**Parameters:**
|
|
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
|
|
54
|
+
|
|
55
|
+
**Returns:** Email sending result object
|
|
56
|
+
|
|
57
|
+
## Types
|
|
58
|
+
|
|
59
|
+
### SendEmailData
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
interface SendEmailData {
|
|
63
|
+
[key: string]: any; // Dynamic data for email template
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### SendEmailParam
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
interface SendEmailParam {
|
|
71
|
+
bodyData: SendEmailData;
|
|
72
|
+
lang: string;
|
|
73
|
+
to: string[];
|
|
74
|
+
type: string;
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Supported Email Types
|
|
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
|
|
30
240
|
|
|
31
|
-
|
|
241
|
+
```javascript
|
|
242
|
+
async function testEmailTemplates(client) {
|
|
243
|
+
try {
|
|
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
|
+
}
|
|
286
|
+
}
|
|
32
287
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vulog/aima-notifier",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.91",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"author": "Vulog",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@vulog/aima-client": "1.1.
|
|
23
|
-
"@vulog/aima-core": "1.1.
|
|
22
|
+
"@vulog/aima-client": "1.1.91",
|
|
23
|
+
"@vulog/aima-core": "1.1.91"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"zod": "^3.25.76"
|