@vulog/aima-user
Version:
483 lines (465 loc) • 15.1 kB
JavaScript
// src/acceptTAndC.ts
import { z } from "zod";
var schema = z.object({
userId: z.string().uuid(),
cityId: z.string().uuid()
});
var acceptTAndC = async (client, userId, cityId) => {
const result = schema.safeParse({ userId, cityId });
if (!result.success) {
throw new TypeError("Invalid args", {
cause: result.error.issues
});
}
await client.post(
`boapi/proxy/user/fleets/${client.clientOptions.fleetId}/cities/${cityId}/users/${userId}/agreements`
);
};
// src/assignBillingGroup.ts
import { z as z2 } from "zod";
var schema2 = z2.object({
entityId: z2.string().trim().min(1).uuid(),
billingGroupId: z2.string().trim().min(1).uuid()
});
var assignBillingGroup = async (client, entityId, billingGroupId) => {
const result = schema2.safeParse({ entityId, billingGroupId });
if (!result.success) {
throw new TypeError("Invalid args", {
cause: result.error.issues
});
}
await client.post(
`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/billingGroup/${result.data.billingGroupId}/entities/${result.data.entityId}`
);
};
// src/createBusinessProfile.ts
import { z as z3 } from "zod";
var createBusinessProfileSchema = z3.object({
userId: z3.string().nonempty().uuid(),
businessId: z3.string().nonempty().uuid(),
data: z3.object({
emailConsent: z3.boolean(),
email: z3.string().email(),
requestId: z3.string().nonempty().uuid(),
costCenterId: z3.string().uuid().nullish()
})
});
var createBusinessProfile = async (client, userId, businessId, data) => {
const result = createBusinessProfileSchema.safeParse({
userId,
businessId,
data
});
if (!result.success) {
throw new TypeError("Invalid argd", {
cause: result.error.issues
});
}
return client.post(
`/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/business/${businessId}/user/${userId}`,
result.data
).then(({ data: p }) => p);
};
// src/createUser.ts
import { z as z4 } from "zod";
var createUserSchema = z4.object({
userName: z4.string().min(1),
password: z4.string().min(1),
locale: z4.string().length(5),
email: z4.string().min(1).email(),
dataPrivacyConsent: z4.boolean().optional(),
profilingConsent: z4.boolean().optional(),
marketingConsent: z4.boolean().optional(),
phoneNumber: z4.string().optional()
});
var createUserOptionsSchema = z4.object({
tcApproval: z4.boolean().default(true),
skipUserNotification: z4.boolean().default(false)
}).default({
tcApproval: true,
skipUserNotification: false
});
var createUser = async (client, user, option) => {
const resultUser = createUserSchema.safeParse(user);
if (!resultUser.success) {
throw new TypeError("Invalid user", {
cause: resultUser.error.issues
});
}
const resultOptions = createUserOptionsSchema.safeParse(option);
if (!resultOptions.success) {
throw new TypeError("Invalid options", {
cause: resultOptions.error.issues
});
}
const searchParams = new URLSearchParams();
searchParams.append("tcApproval", resultOptions.data.tcApproval.toString());
searchParams.append("skipUserNotification", resultOptions.data.skipUserNotification.toString());
return client.post(
`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/userDefault?${searchParams.toString()}`,
resultUser.data
).then(({ data }) => data);
};
// src/findUser.ts
import { z as z6 } from "zod";
// src/types.ts
import { z as z5 } from "zod";
var accountStatus = ["INCOMPLETE", "PENDING", "APPROVED", "REJECTED", "SUSPENDED", "ARCHIVED"];
var personalInformationUserTypes = [
"IDENTITY",
"USERNAME",
"BIRTH",
"NATIONALITY",
"NOTES",
"GENDER",
"PERSONAL_COMPANY",
"FISCAL",
"ADDRESS",
"MEMBERSHIP"
];
var personalInformationUserPaths = [
"/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"
];
var personalInformationUserTypeSchema = z5.enum(personalInformationUserTypes);
var personalInformationProfileTypes = ["ID_NUMBER", "PHONE_NUMBER", "EMAIL", "BILLING_ADDRESS"];
var personalInformationProfileTypeSchema = z5.enum(personalInformationProfileTypes);
// src/findUser.ts
var searchTypes = ["email", "username", "phoneNumber"];
var querySchema = z6.object({
searchType: z6.enum(searchTypes),
searchQuery: z6.string().min(1),
types: z6.array(personalInformationUserTypeSchema).min(1)
});
var findUser = async (client, searchType, searchQuery, types) => {
const result = querySchema.safeParse({
searchType,
searchQuery,
types
});
if (!result.success) {
throw new TypeError("Invalid arguments", {
cause: result.error.issues
});
}
return client.post(
`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/pi/find?types=${result.data.types.join(",")}`,
{
[result.data.searchType]: result.data.searchQuery
}
).then(({ data }) => data);
};
// src/getProfilePersonalInfoById.ts
import { z as z7 } from "zod";
var argsSchema = z7.object({
userId: z7.string().trim().min(1).uuid(),
profileId: z7.string().trim().min(1).uuid(),
types: z7.array(personalInformationProfileTypeSchema).min(1)
});
var getProfilePersonalInfoById = async (client, userId, profileId, types) => {
const result = argsSchema.safeParse({ userId, profileId, types });
if (!result.success) {
throw new TypeError("Invalid args", {
cause: result.error.issues
});
}
return client.get(
`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${result.data.userId}/profiles/${result.data.profileId}/pi?types=${result.data.types.join(",")}`
).then(({ data }) => data);
};
// src/getRegistrationOverview.ts
import { z as z8 } from "zod";
var getRegistrationOverview = async (client, userId) => {
const result = z8.string().uuid().safeParse(userId);
if (!result.success) {
throw new TypeError("Invalid userId", {
cause: result.error.issues
});
}
return client.get(`boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/services`).then(({ data: { userId: uid, ...data } }) => data);
};
// src/getUserById.ts
import { z as z9 } from "zod";
var getUserById = async (client, id, addAccountStatus = false) => {
const result = z9.string().trim().min(1).uuid().safeParse(id);
if (!result.success) {
throw new TypeError("Invalid id", {
cause: result.error.issues
});
}
const user = await client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${id}/status`).then(({ data }) => data);
if (addAccountStatus) {
user.accountStatus = await client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${id}`).then(({ data: { accountStatus: accountStatus2 } }) => accountStatus2);
}
return user;
};
// src/getUserPersonalInfoById.ts
import { z as z10 } from "zod";
var argsSchema2 = z10.object({
id: z10.string().trim().min(1).uuid(),
types: z10.array(personalInformationUserTypeSchema).min(1)
});
var getUserPersonalInfoById = async (client, id, types) => {
const result = argsSchema2.safeParse({ id, types });
if (!result.success) {
throw new TypeError("Invalid args", {
cause: result.error.issues
});
}
return client.get(
`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${result.data.id}/pi?types=${result.data.types.join(",")}`
).then(({ data }) => data);
};
// src/getUsersPIByIds.ts
import { z as z11 } from "zod";
var argsSchema3 = z11.object({
ids: z11.array(z11.string().trim().min(1).uuid()).min(1),
types: z11.array(personalInformationUserTypeSchema).min(1)
});
var getUsersPIByIds = async (client, ids, types) => {
const result = argsSchema3.safeParse({ ids, types });
if (!result.success) {
throw new TypeError("Invalid args", {
cause: result.error.issues
});
}
return client.post(
`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/pi/list?${result.data.types.map((type) => `types=${type}`).join("&")}`,
{
userIds: result.data.ids
}
).then(({ data }) => data);
};
// src/label.ts
import { z as z12 } from "zod";
var schema3 = z12.object({
userId: z12.string().uuid()
});
var schemaData = z12.object({
userId: z12.string().uuid(),
labelId: z12.number().positive()
});
var getLabelsForUser = async (client, userId) => {
const result = schema3.safeParse({ userId });
if (!result.success) {
throw new TypeError("Invalid args", {
cause: result.error.issues
});
}
return client.get(`boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/userLabels`).then(({ data }) => data);
};
var addLabelForUser = async (client, userId, labelId) => {
const result = schemaData.safeParse({ userId, labelId });
if (!result.success) {
throw new TypeError("Invalid args", {
cause: result.error.issues
});
}
await client.post(`boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/userLabels`, {
labelId
});
};
var removeLabelForUser = async (client, userId, labelId) => {
const result = schemaData.safeParse({ userId, labelId });
if (!result.success) {
throw new TypeError("Invalid args", {
cause: result.error.issues
});
}
await client.delete(
`boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/userLabels/${labelId}`
);
};
// src/setServicesStatus.ts
import { z as z13 } from "zod";
var registrationStatus = ["APPROVED", "INCOMPLETE", "PENDING", "REJECTED", "SUSPENDED", "UNREGISTERED"];
var schema4 = z13.object({
disableEmailNotification: z13.boolean(),
operatorProfileId: z13.string().uuid(),
actions: z13.array(
z13.object({
reasonForChange: z13.string(),
serviceId: z13.string().uuid(),
status: z13.enum(registrationStatus)
})
).min(1)
});
var setServicesStatus = async (client, profileId, servicesUpdate) => {
const resultProfileId = z13.string().uuid().safeParse(profileId);
if (!resultProfileId.success) {
throw new TypeError("Invalid profileId", {
cause: resultProfileId.error.issues
});
}
const resultServices = schema4.safeParse(servicesUpdate);
if (!resultServices.success) {
throw new TypeError("Invalid servicesUpdate", {
cause: resultServices.error.issues
});
}
await client.post(
`boapi/proxy/user/fleets/${client.clientOptions.fleetId}/profiles/${profileId}/serviceRegistrations`,
servicesUpdate
);
};
// src/updateProfilePersonalInfo.ts
import { z as z14 } from "zod";
var paths = ["/phoneNumber", "/email"];
var schema5 = z14.object({
userId: z14.string().trim().min(1).uuid(),
profileId: z14.string().trim().min(1).uuid(),
actions: z14.array(
z14.union([
z14.object({
op: z14.enum(["add", "replace"]),
path: z14.enum(paths),
value: z14.string().min(1)
}),
z14.object({
op: z14.literal("remove"),
path: z14.enum(paths)
})
])
).min(1)
});
var updateProfilePersonalInfo = async (client, userId, profileId, actions) => {
const result = schema5.safeParse({ userId, profileId, actions });
if (!result.success) {
throw new TypeError("Invalid args", {
cause: result.error.issues
});
}
await client.patch(
`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/profiles/${profileId}/pi`,
actions,
{
headers: {
"Content-Type": "application/json-patch+json"
}
}
);
};
// src/updateUser.ts
import { z as z15 } from "zod";
var schema6 = z15.object({
id: z15.string().trim().min(1).uuid(),
user: z15.object({
locale: z15.string(),
accountStatus: z15.enum(accountStatus),
dataPrivacyConsent: z15.boolean(),
marketingConsent: z15.boolean(),
surveyConsent: z15.boolean(),
shareDataConsent: z15.boolean(),
profilingConsent: z15.boolean(),
membershipNumber: z15.string()
}).partial()
});
var updateUser = async (client, id, user) => {
const result = schema6.safeParse({ id, user });
if (!result.success) {
throw new TypeError("Invalid args", {
cause: result.error.issues
});
}
return client.post(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${id}`, user).then(({ data }) => data);
};
// src/updateUserPersonalInfo.ts
import { z as z16 } from "zod";
var schema7 = z16.object({
userId: z16.string().trim().min(1).uuid(),
actions: z16.array(
z16.union([
z16.object({
op: z16.enum(["add", "replace"]),
path: z16.enum(personalInformationUserPaths),
value: z16.string().min(1)
}),
z16.object({
op: z16.literal("remove"),
path: z16.enum(personalInformationUserPaths)
})
])
).min(1)
});
var updateUserPersonalInfo = async (client, userId, actions) => {
const result = schema7.safeParse({ userId, actions });
if (!result.success) {
throw new TypeError("Invalid args", {
cause: result.error.issues
});
}
await client.patch(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/pi`, actions, {
headers: {
"Content-Type": "application/json-patch+json"
}
}).then(({ data }) => data);
};
// src/getEntity.ts
import { z as z17 } from "zod";
var getEntity = async (client, entityId) => {
const result = z17.string().trim().min(1).uuid().safeParse(entityId);
if (!result.success) {
throw new TypeError("Invalid entity id", {
cause: result.error.issues
});
}
const entity = await client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/entities/${entityId}`).then(({ data }) => data);
return entity;
};
export {
acceptTAndC,
accountStatus,
addLabelForUser,
assignBillingGroup,
createBusinessProfile,
createUser,
findUser,
getEntity,
getLabelsForUser,
getProfilePersonalInfoById,
getRegistrationOverview,
getUserById,
getUserPersonalInfoById,
getUsersPIByIds,
personalInformationProfileTypeSchema,
personalInformationProfileTypes,
personalInformationUserPaths,
personalInformationUserTypeSchema,
personalInformationUserTypes,
removeLabelForUser,
setServicesStatus,
updateProfilePersonalInfo,
updateUser,
updateUserPersonalInfo
};