Profils
Gestion des profils utilisateurs via @ziwako/client — CRUD, profil courant et profils publics.
La ressource Profils gère les comptes utilisateurs de la plateforme. Chaque profil lie une
identité d'authentification externe (authId, ex. Auth0) aux données internes Ziwako :
contacts, plan de facturation et solde de crédits.
- Factory :
getProfils()(@ziwako/client/axios) - Types :
Profil,ProfilResponse,ProfilListResponse,CreateProfilBody,UpdateProfilBody,ListPublicProfilParams - Endpoints :
POST /profils,GET /profils/me,GET /profils/{id},PUT /profils/{id},DELETE /profils/{id},GET /public/profils,GET /public/profils/{id}
import { configure, getProfils } from '@ziwako/client/axios';
configure({ accessToken: '...' });
const profils = getProfils();Le wrapper de réponse est { type: 'success', code, status, message, data } ; le profil se
trouve dans data (Profil) et les listes paginées dans data.docs.
createProfil
Crée un nouveau profil utilisateur. À appeler immédiatement après l'inscription via le fournisseur d'authentification : le compte est initialisé avec un plan gratuit et un solde de crédits à zéro.
Signature : createProfil(createProfilBody?: CreateProfilBody) → Promise<ProfilResponse>
const response = await profils.createProfil({
username: 'ada.lovelace',
firstName: 'Ada',
lastName: 'Lovelace',
fullName: 'Ada Lovelace',
contacts: { emails: ['ada@example.com'] },
profilType: 'user',
authId: 'auth0|123456',
});
console.log(response.data?.id, response.data?.billingPlan);import { useCreateProfil } from '@ziwako/client/react-query';
const mutation = useCreateProfil({
mutation: {
onSuccess: (response) => {
console.log('Profil créé:', response.data?.id);
},
},
});
mutation.mutate({
data: {
username: 'ada.lovelace',
firstName: 'Ada',
lastName: 'Lovelace',
fullName: 'Ada Lovelace',
authId: 'auth0|123456',
},
});getCurrentProfil
Retourne le profil associé au jeton d'accès fourni. Endpoint de commodité pour initialiser l'état de l'application après connexion, afficher « Mon compte », ou vérifier le solde de crédits et le plan de facturation. Retourne des données privées : nécessite un jeton d'accès valide.
Signature : getCurrentProfil() → Promise<ProfilResponse>
const me = await profils.getCurrentProfil();
console.log(me.data?.username, me.data?.credit, me.data?.billingPlan);import { useGetCurrentProfil } from '@ziwako/client/react-query';
const { data, isLoading } = useGetCurrentProfil({
query: { enabled: !!accessToken },
});
if (isLoading) return <Spinner />;
return <p>Bienvenue {data?.data?.fullName}</p>;getProfil
Retourne la configuration complète d'un profil par son id : identité, rôle (profilType),
contacts, crédits et plan actif.
Signature : getProfil(id: string) → Promise<ProfilResponse>
const response = await profils.getProfil('64b8f2...');
console.log(response.data?.fullName, response.data?.contacts?.emails);import { useGetProfil } from '@ziwako/client/react-query';
const { data } = useGetProfil(profilId, {
query: { enabled: !!profilId },
});updateProfil
Modifie les attributs d'un profil (nom, username, photos, contacts, plan, solde). Le corps accepte les champs à mettre à jour ; la réponse renvoie le profil complet.
Signature : updateProfil(id: string, updateProfilBody?: UpdateProfilBody) → Promise<ProfilResponse>
const response = await profils.updateProfil(profilId, {
fullName: 'Ada King',
contacts: { emails: ['ada.king@example.com'] },
});import { useUpdateProfil } from '@ziwako/client/react-query';
const mutation = useUpdateProfil({
mutation: { onSuccess: () => queryClient.invalidateQueries({ queryKey: ['/profils/me'] }) },
});
mutation.mutate({ id: profilId, data: { fullName: 'Ada King' } });deleteProfil
Supprime définitivement un profil (contacts, historique et métadonnées associées). Action irréversible : prévoyez une confirmation dans l'interface.
Signature : deleteProfil(id: string) → Promise<DeleteProfil200>
await profils.deleteProfil(profilId);import { useDeleteProfil } from '@ziwako/client/react-query';
const mutation = useDeleteProfil();
mutation.mutate({ id: profilId });listPublicProfil
Recherche et parcourt l'annuaire des profils publics (utilisateurs, institutions, bots). Paginé, accepte les filtres, le tri et la sélection de champs. Idéal pour les fonctions de recherche et les flux « Explorer ».
Signature : listPublicProfil(params?: ListPublicProfilParams) → Promise<ProfilListResponse>
ListPublicProfilParams : { filter?, limit?, page?, sort?, populate?, select?, skip? }
const list = await profils.listPublicProfil({
page: 1,
limit: 20,
sort: '-createdAt',
filter: { profilType: 'user' },
});
console.log(list.data?.docs, list.data?.totalPages);import { useListPublicProfil } from '@ziwako/client/react-query';
const { data, isLoading } = useListPublicProfil(
{ page: 1, limit: 20, sort: '-createdAt' },
{ query: { enabled: true } },
);
return (
<ul>
{data?.data?.docs?.map((profil) => <li key={profil.id}>{profil.fullName}</li>)}
</ul>
);getPublicProfil
Retourne les informations publiques d'un profil (identité, photos, contacts) en excluant
strictement les données sensibles (plan, crédits, authId). Endpoint public, pour
afficher une carte de profil à d'autres utilisateurs ou visiteurs.
Signature : getPublicProfil(id: string) → Promise<ProfilResponse>
const response = await profils.getPublicProfil('64b8f2...');
console.log(response.data?.username, response.data?.contacts?.tels);import { useGetPublicProfil } from '@ziwako/client/react-query';
const { data } = useGetPublicProfil(profilId);