UNPKG

@vulog/aima-user

Version:

533 lines (513 loc) 18.4 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var index_exports = {}; __export(index_exports, { acceptTAndC: () => acceptTAndC, accountStatus: () => accountStatus, addLabelForUser: () => addLabelForUser, assignBillingGroup: () => assignBillingGroup, createBusinessProfile: () => createBusinessProfile, createUser: () => createUser, findUser: () => findUser, getEntity: () => getEntity, getLabelsForUser: () => getLabelsForUser, getProfilePersonalInfoById: () => getProfilePersonalInfoById, getRegistrationOverview: () => getRegistrationOverview, getUserById: () => getUserById, getUserPersonalInfoById: () => getUserPersonalInfoById, getUsersPIByIds: () => getUsersPIByIds, personalInformationProfileTypeSchema: () => personalInformationProfileTypeSchema, personalInformationProfileTypes: () => personalInformationProfileTypes, personalInformationUserPaths: () => personalInformationUserPaths, personalInformationUserTypeSchema: () => personalInformationUserTypeSchema, personalInformationUserTypes: () => personalInformationUserTypes, removeLabelForUser: () => removeLabelForUser, setServicesStatus: () => setServicesStatus, updateProfilePersonalInfo: () => updateProfilePersonalInfo, updateUser: () => updateUser, updateUserPersonalInfo: () => updateUserPersonalInfo }); module.exports = __toCommonJS(index_exports); // src/acceptTAndC.ts var import_zod = require("zod"); var schema = import_zod.z.object({ userId: import_zod.z.string().uuid(), cityId: import_zod.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 var import_zod2 = require("zod"); var schema2 = import_zod2.z.object({ entityId: import_zod2.z.string().trim().min(1).uuid(), billingGroupId: import_zod2.z.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 var import_zod3 = require("zod"); var createBusinessProfileSchema = import_zod3.z.object({ userId: import_zod3.z.string().nonempty().uuid(), businessId: import_zod3.z.string().nonempty().uuid(), data: import_zod3.z.object({ emailConsent: import_zod3.z.boolean(), email: import_zod3.z.string().email(), requestId: import_zod3.z.string().nonempty().uuid(), costCenterId: import_zod3.z.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 var import_zod4 = require("zod"); var createUserSchema = import_zod4.z.object({ userName: import_zod4.z.string().min(1), password: import_zod4.z.string().min(1), locale: import_zod4.z.string().length(5), email: import_zod4.z.string().min(1).email(), dataPrivacyConsent: import_zod4.z.boolean().optional(), profilingConsent: import_zod4.z.boolean().optional(), marketingConsent: import_zod4.z.boolean().optional(), phoneNumber: import_zod4.z.string().optional() }); var createUserOptionsSchema = import_zod4.z.object({ tcApproval: import_zod4.z.boolean().default(true), skipUserNotification: import_zod4.z.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 var import_zod6 = require("zod"); // src/types.ts var import_zod5 = require("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 = import_zod5.z.enum(personalInformationUserTypes); var personalInformationProfileTypes = ["ID_NUMBER", "PHONE_NUMBER", "EMAIL", "BILLING_ADDRESS"]; var personalInformationProfileTypeSchema = import_zod5.z.enum(personalInformationProfileTypes); // src/findUser.ts var searchTypes = ["email", "username", "phoneNumber"]; var querySchema = import_zod6.z.object({ searchType: import_zod6.z.enum(searchTypes), searchQuery: import_zod6.z.string().min(1), types: import_zod6.z.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 var import_zod7 = require("zod"); var argsSchema = import_zod7.z.object({ userId: import_zod7.z.string().trim().min(1).uuid(), profileId: import_zod7.z.string().trim().min(1).uuid(), types: import_zod7.z.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 var import_zod8 = require("zod"); var getRegistrationOverview = async (client, userId) => { const result = import_zod8.z.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 var import_zod9 = require("zod"); var getUserById = async (client, id, addAccountStatus = false) => { const result = import_zod9.z.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 var import_zod10 = require("zod"); var argsSchema2 = import_zod10.z.object({ id: import_zod10.z.string().trim().min(1).uuid(), types: import_zod10.z.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 var import_zod11 = require("zod"); var argsSchema3 = import_zod11.z.object({ ids: import_zod11.z.array(import_zod11.z.string().trim().min(1).uuid()).min(1), types: import_zod11.z.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 var import_zod12 = require("zod"); var schema3 = import_zod12.z.object({ userId: import_zod12.z.string().uuid() }); var schemaData = import_zod12.z.object({ userId: import_zod12.z.string().uuid(), labelId: import_zod12.z.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 var import_zod13 = require("zod"); var registrationStatus = ["APPROVED", "INCOMPLETE", "PENDING", "REJECTED", "SUSPENDED", "UNREGISTERED"]; var schema4 = import_zod13.z.object({ disableEmailNotification: import_zod13.z.boolean(), operatorProfileId: import_zod13.z.string().uuid(), actions: import_zod13.z.array( import_zod13.z.object({ reasonForChange: import_zod13.z.string(), serviceId: import_zod13.z.string().uuid(), status: import_zod13.z.enum(registrationStatus) }) ).min(1) }); var setServicesStatus = async (client, profileId, servicesUpdate) => { const resultProfileId = import_zod13.z.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 var import_zod14 = require("zod"); var paths = ["/phoneNumber", "/email"]; var schema5 = import_zod14.z.object({ userId: import_zod14.z.string().trim().min(1).uuid(), profileId: import_zod14.z.string().trim().min(1).uuid(), actions: import_zod14.z.array( import_zod14.z.union([ import_zod14.z.object({ op: import_zod14.z.enum(["add", "replace"]), path: import_zod14.z.enum(paths), value: import_zod14.z.string().min(1) }), import_zod14.z.object({ op: import_zod14.z.literal("remove"), path: import_zod14.z.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 var import_zod15 = require("zod"); var schema6 = import_zod15.z.object({ id: import_zod15.z.string().trim().min(1).uuid(), user: import_zod15.z.object({ locale: import_zod15.z.string(), accountStatus: import_zod15.z.enum(accountStatus), dataPrivacyConsent: import_zod15.z.boolean(), marketingConsent: import_zod15.z.boolean(), surveyConsent: import_zod15.z.boolean(), shareDataConsent: import_zod15.z.boolean(), profilingConsent: import_zod15.z.boolean(), membershipNumber: import_zod15.z.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 var import_zod16 = require("zod"); var schema7 = import_zod16.z.object({ userId: import_zod16.z.string().trim().min(1).uuid(), actions: import_zod16.z.array( import_zod16.z.union([ import_zod16.z.object({ op: import_zod16.z.enum(["add", "replace"]), path: import_zod16.z.enum(personalInformationUserPaths), value: import_zod16.z.string().min(1) }), import_zod16.z.object({ op: import_zod16.z.literal("remove"), path: import_zod16.z.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 var import_zod17 = require("zod"); var getEntity = async (client, entityId) => { const result = import_zod17.z.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; }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { acceptTAndC, accountStatus, addLabelForUser, assignBillingGroup, createBusinessProfile, createUser, findUser, getEntity, getLabelsForUser, getProfilePersonalInfoById, getRegistrationOverview, getUserById, getUserPersonalInfoById, getUsersPIByIds, personalInformationProfileTypeSchema, personalInformationProfileTypes, personalInformationUserPaths, personalInformationUserTypeSchema, personalInformationUserTypes, removeLabelForUser, setServicesStatus, updateProfilePersonalInfo, updateUser, updateUserPersonalInfo });