@vulog/aima-user 1.2.34 → 1.2.35
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/dist/index.cjs +8 -0
- package/dist/index.d.cts +4 -1
- package/dist/index.d.mts +4 -1
- package/dist/index.mjs +8 -1
- package/package.json +4 -4
- package/src/getUserByEmail.test.ts +61 -0
- package/src/getUserByEmail.ts +19 -0
- package/src/index.ts +1 -0
package/dist/index.cjs
CHANGED
|
@@ -210,6 +210,13 @@ const getUserById = async (client, id, addAccountStatus = false) => {
|
|
|
210
210
|
return user;
|
|
211
211
|
};
|
|
212
212
|
//#endregion
|
|
213
|
+
//#region src/getUserByEmail.ts
|
|
214
|
+
const getUserByEmail = async (client, email) => {
|
|
215
|
+
const result = zod.z.string().trim().min(1).email().safeParse(email);
|
|
216
|
+
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
217
|
+
return client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/usernames/${encodeURIComponent(result.data)}`).then(({ data }) => data);
|
|
218
|
+
};
|
|
219
|
+
//#endregion
|
|
213
220
|
//#region src/getUserPersonalInfoById.ts
|
|
214
221
|
const argsSchema$2 = zod.z.object({
|
|
215
222
|
id: zod.z.string().trim().min(1).uuid(),
|
|
@@ -464,6 +471,7 @@ exports.getFleetBillingGroups = getFleetBillingGroups;
|
|
|
464
471
|
exports.getLabelsForUser = getLabelsForUser;
|
|
465
472
|
exports.getProfilePersonalInfoById = getProfilePersonalInfoById;
|
|
466
473
|
exports.getRegistrationOverview = getRegistrationOverview;
|
|
474
|
+
exports.getUserByEmail = getUserByEmail;
|
|
467
475
|
exports.getUserById = getUserById;
|
|
468
476
|
exports.getUserPersonalInfoById = getUserPersonalInfoById;
|
|
469
477
|
exports.getUsers = getUsers;
|
package/dist/index.d.cts
CHANGED
|
@@ -233,6 +233,9 @@ declare const getRegistrationOverview: (client: Client, userId: string) => Promi
|
|
|
233
233
|
//#region src/getUserById.d.ts
|
|
234
234
|
declare const getUserById: (client: Client, id: string, addAccountStatus?: boolean) => Promise<User>;
|
|
235
235
|
//#endregion
|
|
236
|
+
//#region src/getUserByEmail.d.ts
|
|
237
|
+
declare const getUserByEmail: (client: Client, email: string) => Promise<User>;
|
|
238
|
+
//#endregion
|
|
236
239
|
//#region src/getUserPersonalInfoById.d.ts
|
|
237
240
|
declare const getUserPersonalInfoById: (client: Client, id: string, types: PersonalInformationUserType[]) => Promise<PersonalInformationUser>;
|
|
238
241
|
//#endregion
|
|
@@ -324,4 +327,4 @@ type UserSort = z.infer<typeof sortSchema>;
|
|
|
324
327
|
type UserFilters = z.infer<typeof userFiltersSchema>;
|
|
325
328
|
declare const getUsers: (client: Client, options?: PaginableOptions<UserFilters, UserSort>) => Promise<PaginableResponse<UserStatus>>;
|
|
326
329
|
//#endregion
|
|
327
|
-
export { AccountStatus, Address, BillingGroup, CreateBusinessProfile, CreateUser, CreateUserOptions, Entity, FiscalInformation, IndividualBusiness, Label, PersonalCompany, PersonalInformationBirth, PersonalInformationIdentity, PersonalInformationProfile, PersonalInformationProfileType, PersonalInformationUser, PersonalInformationUserType, Profile, ProfilePaths, ProfileServiceRegistration, ProfileStatus, ProfileType, ResponseFind, SearchType, ServiceRegistrationWithReason, ServiceStatus, ServicesRegistrationList, ServicesUpdate, User, UserAgreement, UserFilters, UserFull, UserPaths, UserProfile, UserServiceRegistration, UserSort, UserStatus, UserUpdateBody, acceptTAndC, accountStatus, addLabelForUser, assignBillingGroup, createBusinessProfile, createUser, findUser, getEntity, getFleetBillingGroups, getLabelsForUser, getProfilePersonalInfoById, getRegistrationOverview, getUserById, getUserPersonalInfoById, getUsers, getUsersByIds, getUsersPIByIds, personalInformationProfileTypeSchema, personalInformationProfileTypes, personalInformationUserPaths, personalInformationUserTypeSchema, personalInformationUserTypes, registerUserToService, removeLabelForUser, setServicesStatus, unassignBillingGroup, updateProfilePersonalInfo, updateUser, updateUserPersonalInfo };
|
|
330
|
+
export { AccountStatus, Address, BillingGroup, CreateBusinessProfile, CreateUser, CreateUserOptions, Entity, FiscalInformation, IndividualBusiness, Label, PersonalCompany, PersonalInformationBirth, PersonalInformationIdentity, PersonalInformationProfile, PersonalInformationProfileType, PersonalInformationUser, PersonalInformationUserType, Profile, ProfilePaths, ProfileServiceRegistration, ProfileStatus, ProfileType, ResponseFind, SearchType, ServiceRegistrationWithReason, ServiceStatus, ServicesRegistrationList, ServicesUpdate, User, UserAgreement, UserFilters, UserFull, UserPaths, UserProfile, UserServiceRegistration, UserSort, UserStatus, UserUpdateBody, acceptTAndC, accountStatus, addLabelForUser, assignBillingGroup, createBusinessProfile, createUser, findUser, getEntity, getFleetBillingGroups, getLabelsForUser, getProfilePersonalInfoById, getRegistrationOverview, getUserByEmail, getUserById, getUserPersonalInfoById, getUsers, getUsersByIds, getUsersPIByIds, personalInformationProfileTypeSchema, personalInformationProfileTypes, personalInformationUserPaths, personalInformationUserTypeSchema, personalInformationUserTypes, registerUserToService, removeLabelForUser, setServicesStatus, unassignBillingGroup, updateProfilePersonalInfo, updateUser, updateUserPersonalInfo };
|
package/dist/index.d.mts
CHANGED
|
@@ -233,6 +233,9 @@ declare const getRegistrationOverview: (client: Client, userId: string) => Promi
|
|
|
233
233
|
//#region src/getUserById.d.ts
|
|
234
234
|
declare const getUserById: (client: Client, id: string, addAccountStatus?: boolean) => Promise<User>;
|
|
235
235
|
//#endregion
|
|
236
|
+
//#region src/getUserByEmail.d.ts
|
|
237
|
+
declare const getUserByEmail: (client: Client, email: string) => Promise<User>;
|
|
238
|
+
//#endregion
|
|
236
239
|
//#region src/getUserPersonalInfoById.d.ts
|
|
237
240
|
declare const getUserPersonalInfoById: (client: Client, id: string, types: PersonalInformationUserType[]) => Promise<PersonalInformationUser>;
|
|
238
241
|
//#endregion
|
|
@@ -324,4 +327,4 @@ type UserSort = z.infer<typeof sortSchema>;
|
|
|
324
327
|
type UserFilters = z.infer<typeof userFiltersSchema>;
|
|
325
328
|
declare const getUsers: (client: Client, options?: PaginableOptions<UserFilters, UserSort>) => Promise<PaginableResponse<UserStatus>>;
|
|
326
329
|
//#endregion
|
|
327
|
-
export { AccountStatus, Address, BillingGroup, CreateBusinessProfile, CreateUser, CreateUserOptions, Entity, FiscalInformation, IndividualBusiness, Label, PersonalCompany, PersonalInformationBirth, PersonalInformationIdentity, PersonalInformationProfile, PersonalInformationProfileType, PersonalInformationUser, PersonalInformationUserType, Profile, ProfilePaths, ProfileServiceRegistration, ProfileStatus, ProfileType, ResponseFind, SearchType, ServiceRegistrationWithReason, ServiceStatus, ServicesRegistrationList, ServicesUpdate, User, UserAgreement, UserFilters, UserFull, UserPaths, UserProfile, UserServiceRegistration, UserSort, UserStatus, UserUpdateBody, acceptTAndC, accountStatus, addLabelForUser, assignBillingGroup, createBusinessProfile, createUser, findUser, getEntity, getFleetBillingGroups, getLabelsForUser, getProfilePersonalInfoById, getRegistrationOverview, getUserById, getUserPersonalInfoById, getUsers, getUsersByIds, getUsersPIByIds, personalInformationProfileTypeSchema, personalInformationProfileTypes, personalInformationUserPaths, personalInformationUserTypeSchema, personalInformationUserTypes, registerUserToService, removeLabelForUser, setServicesStatus, unassignBillingGroup, updateProfilePersonalInfo, updateUser, updateUserPersonalInfo };
|
|
330
|
+
export { AccountStatus, Address, BillingGroup, CreateBusinessProfile, CreateUser, CreateUserOptions, Entity, FiscalInformation, IndividualBusiness, Label, PersonalCompany, PersonalInformationBirth, PersonalInformationIdentity, PersonalInformationProfile, PersonalInformationProfileType, PersonalInformationUser, PersonalInformationUserType, Profile, ProfilePaths, ProfileServiceRegistration, ProfileStatus, ProfileType, ResponseFind, SearchType, ServiceRegistrationWithReason, ServiceStatus, ServicesRegistrationList, ServicesUpdate, User, UserAgreement, UserFilters, UserFull, UserPaths, UserProfile, UserServiceRegistration, UserSort, UserStatus, UserUpdateBody, acceptTAndC, accountStatus, addLabelForUser, assignBillingGroup, createBusinessProfile, createUser, findUser, getEntity, getFleetBillingGroups, getLabelsForUser, getProfilePersonalInfoById, getRegistrationOverview, getUserByEmail, getUserById, getUserPersonalInfoById, getUsers, getUsersByIds, getUsersPIByIds, personalInformationProfileTypeSchema, personalInformationProfileTypes, personalInformationUserPaths, personalInformationUserTypeSchema, personalInformationUserTypes, registerUserToService, removeLabelForUser, setServicesStatus, unassignBillingGroup, updateProfilePersonalInfo, updateUser, updateUserPersonalInfo };
|
package/dist/index.mjs
CHANGED
|
@@ -209,6 +209,13 @@ const getUserById = async (client, id, addAccountStatus = false) => {
|
|
|
209
209
|
return user;
|
|
210
210
|
};
|
|
211
211
|
//#endregion
|
|
212
|
+
//#region src/getUserByEmail.ts
|
|
213
|
+
const getUserByEmail = async (client, email) => {
|
|
214
|
+
const result = z.string().trim().min(1).email().safeParse(email);
|
|
215
|
+
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
216
|
+
return client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/usernames/${encodeURIComponent(result.data)}`).then(({ data }) => data);
|
|
217
|
+
};
|
|
218
|
+
//#endregion
|
|
212
219
|
//#region src/getUserPersonalInfoById.ts
|
|
213
220
|
const argsSchema$2 = z.object({
|
|
214
221
|
id: z.string().trim().min(1).uuid(),
|
|
@@ -451,4 +458,4 @@ const getUsers = async (client, options) => {
|
|
|
451
458
|
});
|
|
452
459
|
};
|
|
453
460
|
//#endregion
|
|
454
|
-
export { acceptTAndC, accountStatus, addLabelForUser, assignBillingGroup, createBusinessProfile, createUser, findUser, getEntity, getFleetBillingGroups, getLabelsForUser, getProfilePersonalInfoById, getRegistrationOverview, getUserById, getUserPersonalInfoById, getUsers, getUsersByIds, getUsersPIByIds, personalInformationProfileTypeSchema, personalInformationProfileTypes, personalInformationUserPaths, personalInformationUserTypeSchema, personalInformationUserTypes, registerUserToService, removeLabelForUser, setServicesStatus, unassignBillingGroup, updateProfilePersonalInfo, updateUser, updateUserPersonalInfo };
|
|
461
|
+
export { acceptTAndC, accountStatus, addLabelForUser, assignBillingGroup, createBusinessProfile, createUser, findUser, getEntity, getFleetBillingGroups, getLabelsForUser, getProfilePersonalInfoById, getRegistrationOverview, getUserByEmail, getUserById, getUserPersonalInfoById, getUsers, getUsersByIds, getUsersPIByIds, personalInformationProfileTypeSchema, personalInformationProfileTypes, personalInformationUserPaths, personalInformationUserTypeSchema, personalInformationUserTypes, registerUserToService, removeLabelForUser, setServicesStatus, unassignBillingGroup, updateProfilePersonalInfo, updateUser, updateUserPersonalInfo };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vulog/aima-user",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.35",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.cts",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"author": "Vulog",
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@vulog/aima-client": "1.2.
|
|
36
|
-
"@vulog/aima-config": "1.2.
|
|
37
|
-
"@vulog/aima-core": "1.2.
|
|
35
|
+
"@vulog/aima-client": "1.2.35",
|
|
36
|
+
"@vulog/aima-config": "1.2.35",
|
|
37
|
+
"@vulog/aima-core": "1.2.35"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"zod": "^3.25.76"
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { describe, test, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { Client } from '@vulog/aima-client';
|
|
3
|
+
import { getUserByEmail } from './getUserByEmail';
|
|
4
|
+
|
|
5
|
+
describe('getUserByEmail', () => {
|
|
6
|
+
const FLEET_ID = 'FLEET_ID';
|
|
7
|
+
const getMock = vi.fn();
|
|
8
|
+
const client = {
|
|
9
|
+
get: getMock,
|
|
10
|
+
clientOptions: {
|
|
11
|
+
fleetId: FLEET_ID,
|
|
12
|
+
},
|
|
13
|
+
} as unknown as Client;
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
getMock.mockReset();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('throws Invalid args when email is invalid', async () => {
|
|
20
|
+
await expect(getUserByEmail(client, 'not-an-email')).rejects.toThrow(TypeError);
|
|
21
|
+
await expect(getUserByEmail(client, 'not-an-email')).rejects.toMatchObject({
|
|
22
|
+
message: 'Invalid args',
|
|
23
|
+
});
|
|
24
|
+
expect(getMock).not.toHaveBeenCalled();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('throws Invalid args when email is empty', async () => {
|
|
28
|
+
await expect(getUserByEmail(client, '')).rejects.toThrow(TypeError);
|
|
29
|
+
expect(getMock).not.toHaveBeenCalled();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('calls GET with correct URL (email encoded) and returns user', async () => {
|
|
33
|
+
const email = 'user+tag@example.com';
|
|
34
|
+
const userData = {
|
|
35
|
+
id: '20fb98a3-b60d-491a-9359-62e55f51fcb9',
|
|
36
|
+
fleetId: FLEET_ID,
|
|
37
|
+
registrationDate: '2024-01-15T10:00:00Z',
|
|
38
|
+
locale: 'en_GB',
|
|
39
|
+
agreements: [],
|
|
40
|
+
profiles: [],
|
|
41
|
+
dataPrivacyConsent: true,
|
|
42
|
+
marketingConsent: false,
|
|
43
|
+
surveyConsent: false,
|
|
44
|
+
shareDataConsent: false,
|
|
45
|
+
surveyConsentUpdateDate: '',
|
|
46
|
+
shareDataConsentUpdateDate: '',
|
|
47
|
+
profilingConsent: false,
|
|
48
|
+
profilingConsentUpdateDate: '',
|
|
49
|
+
};
|
|
50
|
+
getMock.mockResolvedValueOnce({ data: userData });
|
|
51
|
+
|
|
52
|
+
const result = await getUserByEmail(client, email);
|
|
53
|
+
|
|
54
|
+
expect(getMock).toHaveBeenCalledTimes(1);
|
|
55
|
+
expect(getMock).toHaveBeenCalledWith(
|
|
56
|
+
`/boapi/proxy/user/fleets/${FLEET_ID}/usernames/${encodeURIComponent(email)}`
|
|
57
|
+
);
|
|
58
|
+
expect(result).toEqual(userData);
|
|
59
|
+
expect(result.id).toBe(userData.id);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Client } from '@vulog/aima-client';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
import { User } from './types';
|
|
5
|
+
|
|
6
|
+
export const getUserByEmail = async (client: Client, email: string): Promise<User> => {
|
|
7
|
+
const result = z.string().trim().min(1).email().safeParse(email);
|
|
8
|
+
if (!result.success) {
|
|
9
|
+
throw new TypeError('Invalid args', {
|
|
10
|
+
cause: result.error.issues,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return client
|
|
15
|
+
.get<User>(
|
|
16
|
+
`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/usernames/${encodeURIComponent(result.data)}`
|
|
17
|
+
)
|
|
18
|
+
.then(({ data }) => data);
|
|
19
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from './findUser';
|
|
|
7
7
|
export * from './getProfilePersonalInfoById';
|
|
8
8
|
export * from './getRegistrationOverview';
|
|
9
9
|
export * from './getUserById';
|
|
10
|
+
export * from './getUserByEmail';
|
|
10
11
|
export * from './getUserPersonalInfoById';
|
|
11
12
|
export * from './getUsersPIByIds';
|
|
12
13
|
export * from './label';
|