@vulog/aima-user 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.
Files changed (2) hide show
  1. package/README.md +438 -0
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -1 +1,439 @@
1
1
  # @vulog/aima-user
2
+
3
+ User management module for the AIMA platform. This module provides comprehensive functionality to manage users, profiles, billing groups, and user-related operations.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @vulog/aima-client @vulog/aima-core @vulog/aima-user
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Initialize Client
14
+
15
+ ```javascript
16
+ import { getClient } from '@vulog/aima-client';
17
+ import {
18
+ createUser,
19
+ findUser,
20
+ getUserById,
21
+ updateUser,
22
+ createBusinessProfile,
23
+ getFleetBillingGroups
24
+ } from '@vulog/aima-user';
25
+
26
+ const client = getClient({
27
+ apiKey: 'your-api-key',
28
+ baseUrl: 'https://your-api-base-url',
29
+ clientId: 'your-client-id',
30
+ clientSecret: 'your-client-secret',
31
+ fleetId: 'your-fleet-id',
32
+ });
33
+ ```
34
+
35
+ ## API Reference
36
+
37
+ ### User Management
38
+
39
+ #### createUser
40
+
41
+ Create a new user account.
42
+
43
+ ```javascript
44
+ const user = await createUser(client, {
45
+ userName: 'john.doe',
46
+ password: 'securePassword123',
47
+ locale: 'en_US',
48
+ email: 'john.doe@example.com',
49
+ dataPrivacyConsent: true,
50
+ profilingConsent: false,
51
+ marketingConsent: true,
52
+ phoneNumber: '+1234567890'
53
+ }, {
54
+ tcApproval: true,
55
+ skipUserNotification: false
56
+ });
57
+ ```
58
+
59
+ **Parameters:**
60
+ - `client`: AIMA client instance
61
+ - `userData`: User creation data
62
+ - `userName`: Unique username
63
+ - `password`: User password
64
+ - `locale`: Locale code (e.g., 'en_US', 'fr_FR')
65
+ - `email`: User email address
66
+ - `dataPrivacyConsent`: Data privacy consent (optional)
67
+ - `profilingConsent`: Profiling consent (optional)
68
+ - `marketingConsent`: Marketing consent (optional)
69
+ - `phoneNumber`: Phone number (optional)
70
+ - `options`: Creation options (optional)
71
+ - `tcApproval`: Terms and conditions approval (default: true)
72
+ - `skipUserNotification`: Skip user notification (default: false)
73
+
74
+ #### findUser
75
+
76
+ Search for users by various criteria.
77
+
78
+ ```javascript
79
+ const users = await findUser(client, {
80
+ email: 'john.doe@example.com',
81
+ userName: 'john.doe',
82
+ phoneNumber: '+1234567890'
83
+ });
84
+ ```
85
+
86
+ **Parameters:**
87
+ - `client`: AIMA client instance
88
+ - `searchCriteria`: Search criteria object
89
+ - `email`: Email address to search
90
+ - `userName`: Username to search
91
+ - `phoneNumber`: Phone number to search
92
+
93
+ #### getUserById
94
+
95
+ Retrieve user by ID.
96
+
97
+ ```javascript
98
+ const user = await getUserById(client, 'user-uuid-here');
99
+ ```
100
+
101
+ **Parameters:**
102
+ - `client`: AIMA client instance
103
+ - `userId`: User UUID
104
+
105
+ #### updateUser
106
+
107
+ Update user information.
108
+
109
+ ```javascript
110
+ const updatedUser = await updateUser(client, 'user-uuid-here', {
111
+ email: 'new.email@example.com',
112
+ phoneNumber: '+0987654321',
113
+ locale: 'fr_FR'
114
+ });
115
+ ```
116
+
117
+ **Parameters:**
118
+ - `client`: AIMA client instance
119
+ - `userId`: User UUID
120
+ - `updateData`: Data to update
121
+
122
+ ### Profile Management
123
+
124
+ #### createBusinessProfile
125
+
126
+ Create a business profile for a user.
127
+
128
+ ```javascript
129
+ const businessProfile = await createBusinessProfile(client, {
130
+ entityId: 'user-uuid-here',
131
+ companyName: 'Acme Corp',
132
+ vatNumber: 'VAT123456789',
133
+ address: {
134
+ street: '123 Main St',
135
+ city: 'New York',
136
+ postalCode: '10001',
137
+ country: 'US'
138
+ }
139
+ });
140
+ ```
141
+
142
+ #### getProfilePersonalInfoById
143
+
144
+ Get personal information for a user profile.
145
+
146
+ ```javascript
147
+ const personalInfo = await getProfilePersonalInfoById(client, 'user-uuid-here');
148
+ ```
149
+
150
+ #### updateProfilePersonalInfo
151
+
152
+ Update personal information for a user profile.
153
+
154
+ ```javascript
155
+ const updatedInfo = await updateProfilePersonalInfo(client, 'user-uuid-here', {
156
+ firstName: 'John',
157
+ lastName: 'Doe',
158
+ dateOfBirth: '1990-01-01',
159
+ address: {
160
+ street: '456 Oak Ave',
161
+ city: 'Los Angeles',
162
+ postalCode: '90210',
163
+ country: 'US'
164
+ }
165
+ });
166
+ ```
167
+
168
+ ### Billing and Groups
169
+
170
+ #### getFleetBillingGroups
171
+
172
+ Retrieve billing groups for the fleet.
173
+
174
+ ```javascript
175
+ const billingGroups = await getFleetBillingGroups(client);
176
+ ```
177
+
178
+ #### assignBillingGroup
179
+
180
+ Assign a user to a billing group.
181
+
182
+ ```javascript
183
+ const result = await assignBillingGroup(client, {
184
+ entityId: 'user-uuid-here',
185
+ billingGroupId: 'billing-group-id-here'
186
+ });
187
+ ```
188
+
189
+ ### Terms and Conditions
190
+
191
+ #### acceptTAndC
192
+
193
+ Accept terms and conditions for a user.
194
+
195
+ ```javascript
196
+ const result = await acceptTAndC(client, {
197
+ entityId: 'user-uuid-here',
198
+ version: '1.0',
199
+ acceptedAt: new Date().toISOString()
200
+ });
201
+ ```
202
+
203
+ ### Service Management
204
+
205
+ #### setServicesStatus
206
+
207
+ Set service status for a user.
208
+
209
+ ```javascript
210
+ const result = await setServicesStatus(client, {
211
+ entityId: 'user-uuid-here',
212
+ services: {
213
+ 'SERVICE_A': true,
214
+ 'SERVICE_B': false,
215
+ 'SERVICE_C': true
216
+ }
217
+ });
218
+ ```
219
+
220
+ ## Types
221
+
222
+ ### User
223
+
224
+ ```typescript
225
+ interface User {
226
+ id: string;
227
+ userName: string;
228
+ email: string;
229
+ phoneNumber?: string;
230
+ locale: string;
231
+ status: 'ACTIVE' | 'INACTIVE' | 'SUSPENDED' | 'DELETED';
232
+ dataPrivacyConsent: boolean;
233
+ profilingConsent: boolean;
234
+ marketingConsent: boolean;
235
+ createdAt: string;
236
+ updatedAt: string;
237
+ lastLoginAt?: string;
238
+ }
239
+ ```
240
+
241
+ ### BusinessProfile
242
+
243
+ ```typescript
244
+ interface BusinessProfile {
245
+ id: string;
246
+ entityId: string;
247
+ companyName: string;
248
+ vatNumber: string;
249
+ address: {
250
+ street: string;
251
+ city: string;
252
+ postalCode: string;
253
+ country: string;
254
+ };
255
+ createdAt: string;
256
+ updatedAt: string;
257
+ }
258
+ ```
259
+
260
+ ### BillingGroup
261
+
262
+ ```typescript
263
+ interface BillingGroup {
264
+ id: string;
265
+ name: string;
266
+ description: string;
267
+ memberCount: number;
268
+ billingRules: any[];
269
+ createdAt: string;
270
+ updatedAt: string;
271
+ }
272
+ ```
273
+
274
+ ## Error Handling
275
+
276
+ All functions include validation using Zod schemas and will throw appropriate errors if:
277
+ - Required parameters are missing
278
+ - Invalid user IDs are provided
279
+ - Email format is invalid
280
+ - Locale format is invalid
281
+ - Network errors occur
282
+
283
+ ## Examples
284
+
285
+ ### Complete User Management Workflow
286
+
287
+ ```javascript
288
+ import { getClient } from '@vulog/aima-client';
289
+ import {
290
+ createUser,
291
+ findUser,
292
+ getUserById,
293
+ updateUser,
294
+ createBusinessProfile,
295
+ getFleetBillingGroups
296
+ } from '@vulog/aima-user';
297
+
298
+ const client = getClient({
299
+ apiKey: 'your-api-key',
300
+ baseUrl: 'https://your-api-base-url',
301
+ clientId: 'your-client-id',
302
+ clientSecret: 'your-client-secret',
303
+ fleetId: 'your-fleet-id',
304
+ });
305
+
306
+ async function userManagementWorkflow() {
307
+ try {
308
+ // Create a new user
309
+ const newUser = await createUser(client, {
310
+ userName: 'jane.doe',
311
+ password: 'securePassword123',
312
+ locale: 'en_US',
313
+ email: 'jane.doe@example.com',
314
+ dataPrivacyConsent: true,
315
+ profilingConsent: false,
316
+ marketingConsent: true,
317
+ phoneNumber: '+1234567890'
318
+ });
319
+
320
+ console.log('User created:', newUser);
321
+
322
+ // Find user by email
323
+ const foundUsers = await findUser(client, {
324
+ email: 'jane.doe@example.com'
325
+ });
326
+ console.log('Found users:', foundUsers);
327
+
328
+ // Get user by ID
329
+ const user = await getUserById(client, newUser.id);
330
+ console.log('User details:', user);
331
+
332
+ // Update user
333
+ const updatedUser = await updateUser(client, newUser.id, {
334
+ phoneNumber: '+0987654321',
335
+ locale: 'fr_FR'
336
+ });
337
+ console.log('User updated:', updatedUser);
338
+
339
+ // Create business profile
340
+ const businessProfile = await createBusinessProfile(client, {
341
+ entityId: newUser.id,
342
+ companyName: 'Doe Enterprises',
343
+ vatNumber: 'VAT987654321',
344
+ address: {
345
+ street: '789 Business Blvd',
346
+ city: 'San Francisco',
347
+ postalCode: '94105',
348
+ country: 'US'
349
+ }
350
+ });
351
+ console.log('Business profile created:', businessProfile);
352
+
353
+ // Get billing groups
354
+ const billingGroups = await getFleetBillingGroups(client);
355
+ console.log('Billing groups:', billingGroups);
356
+
357
+ return { newUser, updatedUser, businessProfile, billingGroups };
358
+ } catch (error) {
359
+ console.error('User management error:', error);
360
+ throw error;
361
+ }
362
+ }
363
+ ```
364
+
365
+ ### User Search and Filtering
366
+
367
+ ```javascript
368
+ async function searchUsers(client, searchTerm) {
369
+ try {
370
+ // Search by email
371
+ const emailResults = await findUser(client, { email: searchTerm });
372
+
373
+ // Search by username
374
+ const usernameResults = await findUser(client, { userName: searchTerm });
375
+
376
+ // Search by phone number
377
+ const phoneResults = await findUser(client, { phoneNumber: searchTerm });
378
+
379
+ // Combine and deduplicate results
380
+ const allResults = [...emailResults, ...usernameResults, ...phoneResults];
381
+ const uniqueResults = allResults.filter((user, index, self) =>
382
+ index === self.findIndex(u => u.id === user.id)
383
+ );
384
+
385
+ console.log(`Found ${uniqueResults.length} unique users for "${searchTerm}"`);
386
+ return uniqueResults;
387
+ } catch (error) {
388
+ console.error('User search error:', error);
389
+ throw error;
390
+ }
391
+ }
392
+ ```
393
+
394
+ ### User Analytics
395
+
396
+ ```javascript
397
+ async function analyzeUsers(client) {
398
+ try {
399
+ // This would require a function to get all users
400
+ // For now, we'll demonstrate with individual user lookups
401
+ const sampleUserIds = ['user1', 'user2', 'user3']; // Replace with actual IDs
402
+
403
+ const users = await Promise.all(
404
+ sampleUserIds.map(id => getUserById(client, id).catch(() => null))
405
+ );
406
+
407
+ const validUsers = users.filter(user => user !== null);
408
+
409
+ const analysis = {
410
+ totalUsers: validUsers.length,
411
+ activeUsers: validUsers.filter(u => u.status === 'ACTIVE').length,
412
+ inactiveUsers: validUsers.filter(u => u.status === 'INACTIVE').length,
413
+ suspendedUsers: validUsers.filter(u => u.status === 'SUSPENDED').length,
414
+ consentStats: {
415
+ dataPrivacy: validUsers.filter(u => u.dataPrivacyConsent).length,
416
+ profiling: validUsers.filter(u => u.profilingConsent).length,
417
+ marketing: validUsers.filter(u => u.marketingConsent).length
418
+ },
419
+ localeDistribution: validUsers.reduce((acc, user) => {
420
+ acc[user.locale] = (acc[user.locale] || 0) + 1;
421
+ return acc;
422
+ }, {})
423
+ };
424
+
425
+ console.log('User Analysis:');
426
+ console.log(`Total Users: ${analysis.totalUsers}`);
427
+ console.log(`Active: ${analysis.activeUsers}`);
428
+ console.log(`Inactive: ${analysis.inactiveUsers}`);
429
+ console.log(`Suspended: ${analysis.suspendedUsers}`);
430
+ console.log('Consent Stats:', analysis.consentStats);
431
+ console.log('Locale Distribution:', analysis.localeDistribution);
432
+
433
+ return analysis;
434
+ } catch (error) {
435
+ console.error('User analysis error:', error);
436
+ throw error;
437
+ }
438
+ }
439
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vulog/aima-user",
3
- "version": "1.1.88",
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,9 +19,9 @@
19
19
  "author": "Vulog",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@vulog/aima-client": "1.1.88",
23
- "@vulog/aima-config": "1.1.88",
24
- "@vulog/aima-core": "1.1.88"
22
+ "@vulog/aima-client": "1.1.91",
23
+ "@vulog/aima-config": "1.1.91",
24
+ "@vulog/aima-core": "1.1.91"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "zod": "^3.25.76"