@vulog/aima-user 1.2.37 → 1.2.39
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 +4 -4
- package/dist/index.d.cts +47 -41
- package/dist/index.d.mts +47 -41
- package/dist/index.mjs +4 -4
- package/package.json +5 -5
- package/src/createBusinessProfile.test.ts +258 -0
- package/src/createBusinessProfile.ts +3 -3
- package/src/getFleetBillingGroups.ts +2 -2
- package/src/getUsers.ts +2 -2
- package/tsconfig.json +1 -8
- package/vitest.config.ts +1 -8
package/dist/index.cjs
CHANGED
|
@@ -60,8 +60,8 @@ const createBusinessProfile = async (client, userId, businessId, data) => {
|
|
|
60
60
|
businessId,
|
|
61
61
|
data
|
|
62
62
|
});
|
|
63
|
-
if (!result.success) throw new TypeError("Invalid
|
|
64
|
-
return client.post(`/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/business/${businessId}/user/${userId}`, result.data).then(({ data: p }) => p);
|
|
63
|
+
if (!result.success) throw new TypeError("Invalid arguments", { cause: result.error.issues });
|
|
64
|
+
return client.post(`/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/business/${businessId}/user/${userId}`, result.data.data).then(({ data: p }) => p);
|
|
65
65
|
};
|
|
66
66
|
//#endregion
|
|
67
67
|
//#region src/createUser.ts
|
|
@@ -388,7 +388,7 @@ const getEntity = async (client, entityId) => {
|
|
|
388
388
|
//#endregion
|
|
389
389
|
//#region src/getFleetBillingGroups.ts
|
|
390
390
|
const getFleetBillingGroups = async (client, options) => {
|
|
391
|
-
const resultOptions = (0, _vulog_aima_core.createPaginableOptionsSchema)().
|
|
391
|
+
const resultOptions = (0, _vulog_aima_core.createPaginableOptionsSchema)().safeParse(options ?? {});
|
|
392
392
|
if (!resultOptions.success) throw new TypeError("Invalid options", { cause: resultOptions.error.issues });
|
|
393
393
|
const finalOptions = resultOptions.data;
|
|
394
394
|
const searchParams = new URLSearchParams();
|
|
@@ -437,7 +437,7 @@ const sortSchema = zod.z.enum([
|
|
|
437
437
|
"updateDate"
|
|
438
438
|
]);
|
|
439
439
|
const getUsers = async (client, options) => {
|
|
440
|
-
const resultOptions = (0, _vulog_aima_core.createPaginableOptionsSchema)(userFiltersSchema.default({}), sortSchema.optional().default("registrationDate")).
|
|
440
|
+
const resultOptions = (0, _vulog_aima_core.createPaginableOptionsSchema)(userFiltersSchema.default({}), sortSchema.optional().default("registrationDate")).safeParse(options ?? {});
|
|
441
441
|
if (!resultOptions.success) throw new TypeError("Invalid options", { cause: resultOptions.error.issues });
|
|
442
442
|
const finalOptions = resultOptions.data;
|
|
443
443
|
const searchParams = new URLSearchParams();
|
package/dist/index.d.cts
CHANGED
|
@@ -105,10 +105,26 @@ type UserUpdateBody = Partial<Omit<User, 'id' | 'fleetId' | 'agreements' | 'prof
|
|
|
105
105
|
declare const personalInformationUserTypes: readonly ["IDENTITY", "USERNAME", "BIRTH", "NATIONALITY", "NOTES", "GENDER", "PERSONAL_COMPANY", "FISCAL", "ADDRESS", "MEMBERSHIP"];
|
|
106
106
|
declare const personalInformationUserPaths: readonly ["/identity/firstName", "/identity/lastName", "/identity/middleName", "/identity/preferredName", "/birth/birthDate", "/birth/countryBirth", "/birth/provinceBirth", "/birth/cityBirth", "/nationality", "/notes", "/gender", "/personalCompany/companyName", "/personalCompany/companyVat", "/personalCompany/companyAddress/streetName", "/personalCompany/companyAddress/city", "/personalCompany/companyAddress/postalCode", "/personalCompany/companyAddress/region", "/personalCompany/companyAddress/country", "/personalCompany/companyAddress/number", "/personalCompany/companyAddress/addressAdditionalInformation", "/fiscalInformation/fiscal", "/fiscalInformation/personalVatNumber", "/fiscalInformation/sdi", "/fiscalInformation/pecAddress", "/fiscalInformation/marketReference", "/address/streetName", "/address/city", "/address/postalCode", "/address/region", "/address/country", "/address/number", "/address/addressAdditionalInformation", "/membership"];
|
|
107
107
|
type PersonalInformationUserType = (typeof personalInformationUserTypes)[number];
|
|
108
|
-
declare const personalInformationUserTypeSchema: z.ZodEnum<
|
|
108
|
+
declare const personalInformationUserTypeSchema: z.ZodEnum<{
|
|
109
|
+
IDENTITY: "IDENTITY";
|
|
110
|
+
USERNAME: "USERNAME";
|
|
111
|
+
BIRTH: "BIRTH";
|
|
112
|
+
NATIONALITY: "NATIONALITY";
|
|
113
|
+
NOTES: "NOTES";
|
|
114
|
+
GENDER: "GENDER";
|
|
115
|
+
PERSONAL_COMPANY: "PERSONAL_COMPANY";
|
|
116
|
+
FISCAL: "FISCAL";
|
|
117
|
+
ADDRESS: "ADDRESS";
|
|
118
|
+
MEMBERSHIP: "MEMBERSHIP";
|
|
119
|
+
}>;
|
|
109
120
|
declare const personalInformationProfileTypes: readonly ["ID_NUMBER", "PHONE_NUMBER", "EMAIL", "BILLING_ADDRESS"];
|
|
110
121
|
type PersonalInformationProfileType = (typeof personalInformationProfileTypes)[number];
|
|
111
|
-
declare const personalInformationProfileTypeSchema: z.ZodEnum<
|
|
122
|
+
declare const personalInformationProfileTypeSchema: z.ZodEnum<{
|
|
123
|
+
ID_NUMBER: "ID_NUMBER";
|
|
124
|
+
PHONE_NUMBER: "PHONE_NUMBER";
|
|
125
|
+
EMAIL: "EMAIL";
|
|
126
|
+
BILLING_ADDRESS: "BILLING_ADDRESS";
|
|
127
|
+
}>;
|
|
112
128
|
type PersonalInformationIdentity = {
|
|
113
129
|
firstName?: string;
|
|
114
130
|
lastName?: string;
|
|
@@ -195,7 +211,7 @@ type CreateBusinessProfile = {
|
|
|
195
211
|
emailConsent: boolean;
|
|
196
212
|
email: string;
|
|
197
213
|
requestId: string;
|
|
198
|
-
costCenterId
|
|
214
|
+
costCenterId?: string | null;
|
|
199
215
|
};
|
|
200
216
|
declare const createBusinessProfile: (client: Client, userId: string, businessId: string, data: CreateBusinessProfile) => Promise<UserProfile>;
|
|
201
217
|
//#endregion
|
|
@@ -254,33 +270,16 @@ declare const schema: z.ZodObject<{
|
|
|
254
270
|
actions: z.ZodArray<z.ZodObject<{
|
|
255
271
|
reasonForChange: z.ZodString;
|
|
256
272
|
serviceId: z.ZodString;
|
|
257
|
-
status: z.ZodEnum<
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}, "strip", z.ZodTypeAny, {
|
|
268
|
-
disableEmailNotification: boolean;
|
|
269
|
-
operatorProfileId: string;
|
|
270
|
-
actions: {
|
|
271
|
-
status: "PENDING" | "INCOMPLETE" | "SUSPENDED" | "REJECTED" | "APPROVED" | "UNREGISTERED";
|
|
272
|
-
serviceId: string;
|
|
273
|
-
reasonForChange: string;
|
|
274
|
-
}[];
|
|
275
|
-
}, {
|
|
276
|
-
disableEmailNotification: boolean;
|
|
277
|
-
operatorProfileId: string;
|
|
278
|
-
actions: {
|
|
279
|
-
status: "PENDING" | "INCOMPLETE" | "SUSPENDED" | "REJECTED" | "APPROVED" | "UNREGISTERED";
|
|
280
|
-
serviceId: string;
|
|
281
|
-
reasonForChange: string;
|
|
282
|
-
}[];
|
|
283
|
-
}>;
|
|
273
|
+
status: z.ZodEnum<{
|
|
274
|
+
PENDING: "PENDING";
|
|
275
|
+
INCOMPLETE: "INCOMPLETE";
|
|
276
|
+
SUSPENDED: "SUSPENDED";
|
|
277
|
+
REJECTED: "REJECTED";
|
|
278
|
+
APPROVED: "APPROVED";
|
|
279
|
+
UNREGISTERED: "UNREGISTERED";
|
|
280
|
+
}>;
|
|
281
|
+
}, z.core.$strip>>;
|
|
282
|
+
}, z.core.$strip>;
|
|
284
283
|
type ServicesUpdate = z.infer<typeof schema>;
|
|
285
284
|
declare const setServicesStatus: (client: Client, profileId: string, servicesUpdate: ServicesUpdate) => Promise<void>;
|
|
286
285
|
//#endregion
|
|
@@ -310,19 +309,26 @@ declare const getUsersByIds: (client: Client, ids: string[]) => Promise<User[]>;
|
|
|
310
309
|
//#endregion
|
|
311
310
|
//#region src/getUsers.d.ts
|
|
312
311
|
declare const userFiltersSchema: z.ZodObject<{
|
|
313
|
-
status: z.ZodOptional<z.ZodEnum<
|
|
314
|
-
|
|
312
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
313
|
+
PENDING: "PENDING";
|
|
314
|
+
INCOMPLETE: "INCOMPLETE";
|
|
315
|
+
SUSPENDED: "SUSPENDED";
|
|
316
|
+
REJECTED: "REJECTED";
|
|
317
|
+
APPROVED: "APPROVED";
|
|
318
|
+
}>>;
|
|
319
|
+
profileType: z.ZodOptional<z.ZodEnum<{
|
|
320
|
+
Single: "Single";
|
|
321
|
+
Business: "Business";
|
|
322
|
+
}>>;
|
|
315
323
|
serviceId: z.ZodOptional<z.ZodString>;
|
|
316
|
-
},
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
serviceId?: string | undefined;
|
|
324
|
+
}, z.core.$strip>;
|
|
325
|
+
declare const sortSchema: z.ZodEnum<{
|
|
326
|
+
registrationDate: "registrationDate";
|
|
327
|
+
userName: "userName";
|
|
328
|
+
firstName: "firstName";
|
|
329
|
+
lastName: "lastName";
|
|
330
|
+
updateDate: "updateDate";
|
|
324
331
|
}>;
|
|
325
|
-
declare const sortSchema: z.ZodEnum<["registrationDate", "userName", "firstName", "lastName", "updateDate"]>;
|
|
326
332
|
type UserSort = z.infer<typeof sortSchema>;
|
|
327
333
|
type UserFilters = z.infer<typeof userFiltersSchema>;
|
|
328
334
|
declare const getUsers: (client: Client, options?: PaginableOptions<UserFilters, UserSort>) => Promise<PaginableResponse<UserStatus>>;
|
package/dist/index.d.mts
CHANGED
|
@@ -105,10 +105,26 @@ type UserUpdateBody = Partial<Omit<User, 'id' | 'fleetId' | 'agreements' | 'prof
|
|
|
105
105
|
declare const personalInformationUserTypes: readonly ["IDENTITY", "USERNAME", "BIRTH", "NATIONALITY", "NOTES", "GENDER", "PERSONAL_COMPANY", "FISCAL", "ADDRESS", "MEMBERSHIP"];
|
|
106
106
|
declare const personalInformationUserPaths: readonly ["/identity/firstName", "/identity/lastName", "/identity/middleName", "/identity/preferredName", "/birth/birthDate", "/birth/countryBirth", "/birth/provinceBirth", "/birth/cityBirth", "/nationality", "/notes", "/gender", "/personalCompany/companyName", "/personalCompany/companyVat", "/personalCompany/companyAddress/streetName", "/personalCompany/companyAddress/city", "/personalCompany/companyAddress/postalCode", "/personalCompany/companyAddress/region", "/personalCompany/companyAddress/country", "/personalCompany/companyAddress/number", "/personalCompany/companyAddress/addressAdditionalInformation", "/fiscalInformation/fiscal", "/fiscalInformation/personalVatNumber", "/fiscalInformation/sdi", "/fiscalInformation/pecAddress", "/fiscalInformation/marketReference", "/address/streetName", "/address/city", "/address/postalCode", "/address/region", "/address/country", "/address/number", "/address/addressAdditionalInformation", "/membership"];
|
|
107
107
|
type PersonalInformationUserType = (typeof personalInformationUserTypes)[number];
|
|
108
|
-
declare const personalInformationUserTypeSchema: z.ZodEnum<
|
|
108
|
+
declare const personalInformationUserTypeSchema: z.ZodEnum<{
|
|
109
|
+
IDENTITY: "IDENTITY";
|
|
110
|
+
USERNAME: "USERNAME";
|
|
111
|
+
BIRTH: "BIRTH";
|
|
112
|
+
NATIONALITY: "NATIONALITY";
|
|
113
|
+
NOTES: "NOTES";
|
|
114
|
+
GENDER: "GENDER";
|
|
115
|
+
PERSONAL_COMPANY: "PERSONAL_COMPANY";
|
|
116
|
+
FISCAL: "FISCAL";
|
|
117
|
+
ADDRESS: "ADDRESS";
|
|
118
|
+
MEMBERSHIP: "MEMBERSHIP";
|
|
119
|
+
}>;
|
|
109
120
|
declare const personalInformationProfileTypes: readonly ["ID_NUMBER", "PHONE_NUMBER", "EMAIL", "BILLING_ADDRESS"];
|
|
110
121
|
type PersonalInformationProfileType = (typeof personalInformationProfileTypes)[number];
|
|
111
|
-
declare const personalInformationProfileTypeSchema: z.ZodEnum<
|
|
122
|
+
declare const personalInformationProfileTypeSchema: z.ZodEnum<{
|
|
123
|
+
ID_NUMBER: "ID_NUMBER";
|
|
124
|
+
PHONE_NUMBER: "PHONE_NUMBER";
|
|
125
|
+
EMAIL: "EMAIL";
|
|
126
|
+
BILLING_ADDRESS: "BILLING_ADDRESS";
|
|
127
|
+
}>;
|
|
112
128
|
type PersonalInformationIdentity = {
|
|
113
129
|
firstName?: string;
|
|
114
130
|
lastName?: string;
|
|
@@ -195,7 +211,7 @@ type CreateBusinessProfile = {
|
|
|
195
211
|
emailConsent: boolean;
|
|
196
212
|
email: string;
|
|
197
213
|
requestId: string;
|
|
198
|
-
costCenterId
|
|
214
|
+
costCenterId?: string | null;
|
|
199
215
|
};
|
|
200
216
|
declare const createBusinessProfile: (client: Client, userId: string, businessId: string, data: CreateBusinessProfile) => Promise<UserProfile>;
|
|
201
217
|
//#endregion
|
|
@@ -254,33 +270,16 @@ declare const schema: z.ZodObject<{
|
|
|
254
270
|
actions: z.ZodArray<z.ZodObject<{
|
|
255
271
|
reasonForChange: z.ZodString;
|
|
256
272
|
serviceId: z.ZodString;
|
|
257
|
-
status: z.ZodEnum<
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}, "strip", z.ZodTypeAny, {
|
|
268
|
-
disableEmailNotification: boolean;
|
|
269
|
-
operatorProfileId: string;
|
|
270
|
-
actions: {
|
|
271
|
-
status: "PENDING" | "INCOMPLETE" | "SUSPENDED" | "REJECTED" | "APPROVED" | "UNREGISTERED";
|
|
272
|
-
serviceId: string;
|
|
273
|
-
reasonForChange: string;
|
|
274
|
-
}[];
|
|
275
|
-
}, {
|
|
276
|
-
disableEmailNotification: boolean;
|
|
277
|
-
operatorProfileId: string;
|
|
278
|
-
actions: {
|
|
279
|
-
status: "PENDING" | "INCOMPLETE" | "SUSPENDED" | "REJECTED" | "APPROVED" | "UNREGISTERED";
|
|
280
|
-
serviceId: string;
|
|
281
|
-
reasonForChange: string;
|
|
282
|
-
}[];
|
|
283
|
-
}>;
|
|
273
|
+
status: z.ZodEnum<{
|
|
274
|
+
PENDING: "PENDING";
|
|
275
|
+
INCOMPLETE: "INCOMPLETE";
|
|
276
|
+
SUSPENDED: "SUSPENDED";
|
|
277
|
+
REJECTED: "REJECTED";
|
|
278
|
+
APPROVED: "APPROVED";
|
|
279
|
+
UNREGISTERED: "UNREGISTERED";
|
|
280
|
+
}>;
|
|
281
|
+
}, z.core.$strip>>;
|
|
282
|
+
}, z.core.$strip>;
|
|
284
283
|
type ServicesUpdate = z.infer<typeof schema>;
|
|
285
284
|
declare const setServicesStatus: (client: Client, profileId: string, servicesUpdate: ServicesUpdate) => Promise<void>;
|
|
286
285
|
//#endregion
|
|
@@ -310,19 +309,26 @@ declare const getUsersByIds: (client: Client, ids: string[]) => Promise<User[]>;
|
|
|
310
309
|
//#endregion
|
|
311
310
|
//#region src/getUsers.d.ts
|
|
312
311
|
declare const userFiltersSchema: z.ZodObject<{
|
|
313
|
-
status: z.ZodOptional<z.ZodEnum<
|
|
314
|
-
|
|
312
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
313
|
+
PENDING: "PENDING";
|
|
314
|
+
INCOMPLETE: "INCOMPLETE";
|
|
315
|
+
SUSPENDED: "SUSPENDED";
|
|
316
|
+
REJECTED: "REJECTED";
|
|
317
|
+
APPROVED: "APPROVED";
|
|
318
|
+
}>>;
|
|
319
|
+
profileType: z.ZodOptional<z.ZodEnum<{
|
|
320
|
+
Single: "Single";
|
|
321
|
+
Business: "Business";
|
|
322
|
+
}>>;
|
|
315
323
|
serviceId: z.ZodOptional<z.ZodString>;
|
|
316
|
-
},
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
serviceId?: string | undefined;
|
|
324
|
+
}, z.core.$strip>;
|
|
325
|
+
declare const sortSchema: z.ZodEnum<{
|
|
326
|
+
registrationDate: "registrationDate";
|
|
327
|
+
userName: "userName";
|
|
328
|
+
firstName: "firstName";
|
|
329
|
+
lastName: "lastName";
|
|
330
|
+
updateDate: "updateDate";
|
|
324
331
|
}>;
|
|
325
|
-
declare const sortSchema: z.ZodEnum<["registrationDate", "userName", "firstName", "lastName", "updateDate"]>;
|
|
326
332
|
type UserSort = z.infer<typeof sortSchema>;
|
|
327
333
|
type UserFilters = z.infer<typeof userFiltersSchema>;
|
|
328
334
|
declare const getUsers: (client: Client, options?: PaginableOptions<UserFilters, UserSort>) => Promise<PaginableResponse<UserStatus>>;
|
package/dist/index.mjs
CHANGED
|
@@ -59,8 +59,8 @@ const createBusinessProfile = async (client, userId, businessId, data) => {
|
|
|
59
59
|
businessId,
|
|
60
60
|
data
|
|
61
61
|
});
|
|
62
|
-
if (!result.success) throw new TypeError("Invalid
|
|
63
|
-
return client.post(`/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/business/${businessId}/user/${userId}`, result.data).then(({ data: p }) => p);
|
|
62
|
+
if (!result.success) throw new TypeError("Invalid arguments", { cause: result.error.issues });
|
|
63
|
+
return client.post(`/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/business/${businessId}/user/${userId}`, result.data.data).then(({ data: p }) => p);
|
|
64
64
|
};
|
|
65
65
|
//#endregion
|
|
66
66
|
//#region src/createUser.ts
|
|
@@ -387,7 +387,7 @@ const getEntity = async (client, entityId) => {
|
|
|
387
387
|
//#endregion
|
|
388
388
|
//#region src/getFleetBillingGroups.ts
|
|
389
389
|
const getFleetBillingGroups = async (client, options) => {
|
|
390
|
-
const resultOptions = createPaginableOptionsSchema().
|
|
390
|
+
const resultOptions = createPaginableOptionsSchema().safeParse(options ?? {});
|
|
391
391
|
if (!resultOptions.success) throw new TypeError("Invalid options", { cause: resultOptions.error.issues });
|
|
392
392
|
const finalOptions = resultOptions.data;
|
|
393
393
|
const searchParams = new URLSearchParams();
|
|
@@ -436,7 +436,7 @@ const sortSchema = z.enum([
|
|
|
436
436
|
"updateDate"
|
|
437
437
|
]);
|
|
438
438
|
const getUsers = async (client, options) => {
|
|
439
|
-
const resultOptions = createPaginableOptionsSchema(userFiltersSchema.default({}), sortSchema.optional().default("registrationDate")).
|
|
439
|
+
const resultOptions = createPaginableOptionsSchema(userFiltersSchema.default({}), sortSchema.optional().default("registrationDate")).safeParse(options ?? {});
|
|
440
440
|
if (!resultOptions.success) throw new TypeError("Invalid options", { cause: resultOptions.error.issues });
|
|
441
441
|
const finalOptions = resultOptions.data;
|
|
442
442
|
const searchParams = new URLSearchParams();
|
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.39",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.cts",
|
|
@@ -32,12 +32,12 @@
|
|
|
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.39",
|
|
36
|
+
"@vulog/aima-config": "1.2.39",
|
|
37
|
+
"@vulog/aima-core": "1.2.39"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"zod": "^3.
|
|
40
|
+
"zod": "^4.3.6"
|
|
41
41
|
},
|
|
42
42
|
"description": ""
|
|
43
43
|
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { describe, test, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { Client } from '@vulog/aima-client';
|
|
3
|
+
import { createBusinessProfile } from './createBusinessProfile';
|
|
4
|
+
|
|
5
|
+
describe('createBusinessProfile', () => {
|
|
6
|
+
const FLEET_ID = 'HOURCAR-USMSP';
|
|
7
|
+
const USER_ID = '8a274a9c-f5ac-4258-abe1-6c892b6c0b4b';
|
|
8
|
+
const BUSINESS_ID = '051323b4-0f23-4b8d-88b5-d653d20df8ca';
|
|
9
|
+
const REQUEST_ID = '8ee558c1-863e-48cb-9338-e5612ed08d51';
|
|
10
|
+
|
|
11
|
+
const postMock = vi.fn();
|
|
12
|
+
const client = {
|
|
13
|
+
post: postMock,
|
|
14
|
+
clientOptions: {
|
|
15
|
+
fleetId: FLEET_ID,
|
|
16
|
+
},
|
|
17
|
+
} as unknown as Client;
|
|
18
|
+
|
|
19
|
+
const mockUserProfile = {
|
|
20
|
+
id: '4e0bcb24-8f1a-45b0-9a6b-0817886fa195',
|
|
21
|
+
creationDate: '2026-03-18T13:17:14.208+00:00',
|
|
22
|
+
entityId: 'entity-id',
|
|
23
|
+
entityName: 'default',
|
|
24
|
+
status: 'APPROVED' as const,
|
|
25
|
+
type: 'Business' as const,
|
|
26
|
+
emailConsent: true,
|
|
27
|
+
services: [],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
postMock.mockReset();
|
|
32
|
+
postMock.mockResolvedValue({ data: mockUserProfile });
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('calls POST with correct URL', async () => {
|
|
36
|
+
const data = {
|
|
37
|
+
emailConsent: true,
|
|
38
|
+
email: 'contact@company.com',
|
|
39
|
+
requestId: REQUEST_ID,
|
|
40
|
+
costCenterId: undefined,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
await createBusinessProfile(client, USER_ID, BUSINESS_ID, data);
|
|
44
|
+
|
|
45
|
+
expect(postMock).toHaveBeenCalledTimes(1);
|
|
46
|
+
const [url] = postMock.mock.calls[0];
|
|
47
|
+
expect(url).toBe(
|
|
48
|
+
`/boapi/proxy/business/fleets/${FLEET_ID}/business/${BUSINESS_ID}/user/${USER_ID}`
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('sends flat profile body (email, emailConsent, requestId) - no userId/businessId in body', async () => {
|
|
53
|
+
const email = 'business.contact@example.com';
|
|
54
|
+
const data = {
|
|
55
|
+
emailConsent: true,
|
|
56
|
+
email,
|
|
57
|
+
requestId: REQUEST_ID,
|
|
58
|
+
costCenterId: undefined,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
await createBusinessProfile(client, USER_ID, BUSINESS_ID, data);
|
|
62
|
+
|
|
63
|
+
const [, body] = postMock.mock.calls[0];
|
|
64
|
+
expect(body).not.toHaveProperty('userId');
|
|
65
|
+
expect(body).not.toHaveProperty('businessId');
|
|
66
|
+
expect(body).not.toHaveProperty('data');
|
|
67
|
+
expect(body).toHaveProperty('email', email);
|
|
68
|
+
expect(body).toHaveProperty('emailConsent', true);
|
|
69
|
+
expect(body).toHaveProperty('requestId', REQUEST_ID);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('sends costCenterId when provided', async () => {
|
|
73
|
+
const costCenterId = '018ab2b6-71b2-4c76-90bd-6e8d3f26861c';
|
|
74
|
+
const data = {
|
|
75
|
+
emailConsent: false,
|
|
76
|
+
email: 'biz@example.com',
|
|
77
|
+
requestId: REQUEST_ID,
|
|
78
|
+
costCenterId,
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
await createBusinessProfile(client, USER_ID, BUSINESS_ID, data);
|
|
82
|
+
|
|
83
|
+
const [, body] = postMock.mock.calls[0];
|
|
84
|
+
expect(body).toEqual({
|
|
85
|
+
emailConsent: false,
|
|
86
|
+
email: 'biz@example.com',
|
|
87
|
+
requestId: REQUEST_ID,
|
|
88
|
+
costCenterId,
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('omits costCenterId from body when undefined', async () => {
|
|
93
|
+
const data = {
|
|
94
|
+
emailConsent: true,
|
|
95
|
+
email: 'minimal@test.org',
|
|
96
|
+
requestId: REQUEST_ID,
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
await createBusinessProfile(client, USER_ID, BUSINESS_ID, data);
|
|
100
|
+
|
|
101
|
+
const [, body] = postMock.mock.calls[0];
|
|
102
|
+
expect(body).toHaveProperty('email', 'minimal@test.org');
|
|
103
|
+
expect(body).toHaveProperty('requestId', REQUEST_ID);
|
|
104
|
+
expect(body).toHaveProperty('emailConsent', true);
|
|
105
|
+
expect(body).not.toHaveProperty('costCenterId');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('returns response data as UserProfile', async () => {
|
|
109
|
+
const data = {
|
|
110
|
+
emailConsent: true,
|
|
111
|
+
email: 'return@test.com',
|
|
112
|
+
requestId: REQUEST_ID,
|
|
113
|
+
costCenterId: undefined,
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const result = await createBusinessProfile(
|
|
117
|
+
client,
|
|
118
|
+
USER_ID,
|
|
119
|
+
BUSINESS_ID,
|
|
120
|
+
data
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
expect(result).toEqual(mockUserProfile);
|
|
124
|
+
expect(result.id).toBe(mockUserProfile.id);
|
|
125
|
+
expect(result.status).toBe('APPROVED');
|
|
126
|
+
expect(result.type).toBe('Business');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('throws TypeError when email is invalid', async () => {
|
|
130
|
+
const data = {
|
|
131
|
+
emailConsent: true,
|
|
132
|
+
email: 'not-an-email',
|
|
133
|
+
requestId: REQUEST_ID,
|
|
134
|
+
costCenterId: undefined,
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
await expect(
|
|
138
|
+
createBusinessProfile(client, USER_ID, BUSINESS_ID, data)
|
|
139
|
+
).rejects.toThrow(TypeError);
|
|
140
|
+
|
|
141
|
+
expect(postMock).not.toHaveBeenCalled();
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test('throws TypeError when email is empty', async () => {
|
|
145
|
+
const data = {
|
|
146
|
+
emailConsent: true,
|
|
147
|
+
email: '',
|
|
148
|
+
requestId: REQUEST_ID,
|
|
149
|
+
costCenterId: undefined,
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
await expect(
|
|
153
|
+
createBusinessProfile(client, USER_ID, BUSINESS_ID, data)
|
|
154
|
+
).rejects.toThrow(TypeError);
|
|
155
|
+
|
|
156
|
+
expect(postMock).not.toHaveBeenCalled();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test('throws TypeError when userId is not a valid UUID', async () => {
|
|
160
|
+
const data = {
|
|
161
|
+
emailConsent: true,
|
|
162
|
+
email: 'valid@example.com',
|
|
163
|
+
requestId: REQUEST_ID,
|
|
164
|
+
costCenterId: undefined,
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
await expect(
|
|
168
|
+
createBusinessProfile(client, 'not-a-uuid', BUSINESS_ID, data)
|
|
169
|
+
).rejects.toThrow(TypeError);
|
|
170
|
+
|
|
171
|
+
expect(postMock).not.toHaveBeenCalled();
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test('throws TypeError when businessId is not a valid UUID', async () => {
|
|
175
|
+
const data = {
|
|
176
|
+
emailConsent: true,
|
|
177
|
+
email: 'valid@example.com',
|
|
178
|
+
requestId: REQUEST_ID,
|
|
179
|
+
costCenterId: undefined,
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
await expect(
|
|
183
|
+
createBusinessProfile(client, USER_ID, 'invalid-business', data)
|
|
184
|
+
).rejects.toThrow(TypeError);
|
|
185
|
+
|
|
186
|
+
expect(postMock).not.toHaveBeenCalled();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test('throws TypeError when requestId is not a valid UUID', async () => {
|
|
190
|
+
const data = {
|
|
191
|
+
emailConsent: true,
|
|
192
|
+
email: 'valid@example.com',
|
|
193
|
+
requestId: 'not-a-uuid',
|
|
194
|
+
costCenterId: undefined,
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
await expect(
|
|
198
|
+
createBusinessProfile(client, USER_ID, BUSINESS_ID, data)
|
|
199
|
+
).rejects.toThrow(TypeError);
|
|
200
|
+
|
|
201
|
+
expect(postMock).not.toHaveBeenCalled();
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test('throws TypeError when costCenterId is not a valid UUID when provided', async () => {
|
|
205
|
+
const data = {
|
|
206
|
+
emailConsent: true,
|
|
207
|
+
email: 'valid@example.com',
|
|
208
|
+
requestId: REQUEST_ID,
|
|
209
|
+
costCenterId: 'not-a-uuid',
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
await expect(
|
|
213
|
+
createBusinessProfile(client, USER_ID, BUSINESS_ID, data)
|
|
214
|
+
).rejects.toThrow(TypeError);
|
|
215
|
+
|
|
216
|
+
expect(postMock).not.toHaveBeenCalled();
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
test('error cause includes Zod issues for invalid input', async () => {
|
|
220
|
+
const data = {
|
|
221
|
+
emailConsent: true,
|
|
222
|
+
email: 'bad-email',
|
|
223
|
+
requestId: REQUEST_ID,
|
|
224
|
+
costCenterId: undefined,
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
try {
|
|
228
|
+
await createBusinessProfile(client, USER_ID, BUSINESS_ID, data);
|
|
229
|
+
} catch (err) {
|
|
230
|
+
expect(err).toBeInstanceOf(TypeError);
|
|
231
|
+
expect((err as Error).cause).toBeDefined();
|
|
232
|
+
expect(Array.isArray((err as Error).cause)).toBe(true);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
test('sends various valid email formats in body', async () => {
|
|
237
|
+
const emails = [
|
|
238
|
+
'user@example.com',
|
|
239
|
+
'user+tag@sub.domain.co.uk',
|
|
240
|
+
'tneels+biz04@vulog.com',
|
|
241
|
+
];
|
|
242
|
+
|
|
243
|
+
for (const email of emails) {
|
|
244
|
+
postMock.mockClear();
|
|
245
|
+
const data = {
|
|
246
|
+
emailConsent: true,
|
|
247
|
+
email,
|
|
248
|
+
requestId: REQUEST_ID,
|
|
249
|
+
costCenterId: undefined,
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
await createBusinessProfile(client, USER_ID, BUSINESS_ID, data);
|
|
253
|
+
|
|
254
|
+
const [, body] = postMock.mock.calls[0];
|
|
255
|
+
expect(body.email).toBe(email);
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
});
|
|
@@ -7,7 +7,7 @@ export type CreateBusinessProfile = {
|
|
|
7
7
|
emailConsent: boolean;
|
|
8
8
|
email: string;
|
|
9
9
|
requestId: string;
|
|
10
|
-
costCenterId
|
|
10
|
+
costCenterId?: string | null;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
const createBusinessProfileSchema = z.object({
|
|
@@ -33,7 +33,7 @@ export const createBusinessProfile = async (
|
|
|
33
33
|
data,
|
|
34
34
|
});
|
|
35
35
|
if (!result.success) {
|
|
36
|
-
throw new TypeError('Invalid
|
|
36
|
+
throw new TypeError('Invalid arguments', {
|
|
37
37
|
cause: result.error.issues,
|
|
38
38
|
});
|
|
39
39
|
}
|
|
@@ -41,7 +41,7 @@ export const createBusinessProfile = async (
|
|
|
41
41
|
return client
|
|
42
42
|
.post(
|
|
43
43
|
`/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/business/${businessId}/user/${userId}`,
|
|
44
|
-
result.data
|
|
44
|
+
result.data.data
|
|
45
45
|
)
|
|
46
46
|
.then(({ data: p }) => p);
|
|
47
47
|
};
|
|
@@ -8,9 +8,9 @@ export const getFleetBillingGroups = async (
|
|
|
8
8
|
client: Client,
|
|
9
9
|
options?: PaginableOptions
|
|
10
10
|
): Promise<PaginableResponse<BillingGroup>> => {
|
|
11
|
-
const PaginableOptionsSchema = createPaginableOptionsSchema()
|
|
11
|
+
const PaginableOptionsSchema = createPaginableOptionsSchema();
|
|
12
12
|
|
|
13
|
-
const resultOptions = PaginableOptionsSchema.safeParse(options);
|
|
13
|
+
const resultOptions = PaginableOptionsSchema.safeParse(options ?? {});
|
|
14
14
|
if (!resultOptions.success) {
|
|
15
15
|
throw new TypeError('Invalid options', {
|
|
16
16
|
cause: resultOptions.error.issues,
|
package/src/getUsers.ts
CHANGED
|
@@ -26,9 +26,9 @@ export const getUsers = async (
|
|
|
26
26
|
const paginableOptionsSchema = createPaginableOptionsSchema(
|
|
27
27
|
userFiltersSchema.default({}),
|
|
28
28
|
sortSchema.optional().default('registrationDate')
|
|
29
|
-
)
|
|
29
|
+
);
|
|
30
30
|
|
|
31
|
-
const resultOptions = paginableOptionsSchema.safeParse(options);
|
|
31
|
+
const resultOptions = paginableOptionsSchema.safeParse(options ?? {});
|
|
32
32
|
if (!resultOptions.success) {
|
|
33
33
|
throw new TypeError('Invalid options', {
|
|
34
34
|
cause: resultOptions.error.issues,
|
package/tsconfig.json
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
2
3
|
"include": ["src"],
|
|
3
4
|
"exclude": ["**/*.test.ts"],
|
|
4
5
|
"compilerOptions": {
|
|
5
|
-
"module": "esnext",
|
|
6
|
-
"target": "esnext",
|
|
7
|
-
"lib": ["esnext"],
|
|
8
|
-
"declaration": true,
|
|
9
|
-
"strict": true,
|
|
10
|
-
"moduleResolution": "node",
|
|
11
|
-
"skipLibCheck": true,
|
|
12
|
-
"esModuleInterop": true,
|
|
13
6
|
"outDir": "dist",
|
|
14
7
|
"rootDir": "src"
|
|
15
8
|
}
|