Ziwako Docs
Ziwako ContactGuide développeurSDK @ziwako/contact

Contacts

Gestion des contacts via @ziwako/contact — CRUD, doublons, fusion, favoris, labels et import/export.

La ressource Contacts gère le carnet d'adresses de chaque utilisateur : CRUD, détection de doublons, fusion, favoris, affectation de labels et import/export (vCard, CSV).

  • Factory : getContacts() (@ziwako/contact/axios)
  • Types : IContact, ContactResponse, ContactPaginatedResponse, CreateContactBody, UpdateContactBody, MergeContactsBody, ToggleContactFavoriteBody, AssignContactLabelsBody, ImportContactsVCardBody, ImportContactsCsvBody, ListContactsParams
  • Endpoints : GET /contacts, POST /contacts, GET /contacts/duplicates, POST /contacts/merge, GET /contacts/{id}, PUT /contacts/{id}, DELETE /contacts/{id}, PATCH /contacts/{id}/favorite, POST /contacts/{id}/labels, DELETE /contacts/{id}/labels/{labelId}, GET /contacts/export/vcard, GET /contacts/export/csv, POST /contacts/import/vcard, POST /contacts/import/csv
import { configure, getContacts } from '@ziwako/contact/axios';
configure({ accessToken: '...' });
const contacts = getContacts();

CRUD

listContacts

Liste paginée des contacts, filtrable par search, label, isFavorite.

Signature : listContacts(params?: ListContactsParams) → Promise<ContactPaginatedResponse>

ListContactsParams : { page?, limit?, sort?, search?, label?, isFavorite? }

const list = await contacts.listContacts({ page: 1, limit: 20, search: 'grace' });
console.log(list.data?.docs, list.data?.totalDocs);
import { useListContacts } from '@ziwako/contact/react-query';

const { data, isLoading } = useListContacts(
    { page: 1, limit: 20, search: query },
    { query: { enabled: true } },
);

return (
    <ul>
        {data?.data?.docs?.map((contact) => (
            <li key={contact._id}>{contact.name.givenName} {contact.name.familyName}</li>
        ))}
    </ul>
);

createContact

Crée un contact.

Signature : createContact(createContactBody?: CreateContactBody) → Promise<ContactResponse>

const response = await contacts.createContact({
    name: { givenName: 'Ada', familyName: 'Lovelace' },
    phoneNumbers: [{ type: 'mobile', value: '+243991111111' }],
    emails: [{ type: 'work', value: 'ada@example.com' }],
    notes: 'Première programmeuse',
    labels: ['64b8f2...'],
});
console.log(response.data?._id);
import { useCreateContact } from '@ziwako/contact/react-query';

const mutation = useCreateContact({
    mutation: {
        onSuccess: () => {
            toast.success('Contact créé');
            queryClient.invalidateQueries({ queryKey: ['listContacts'] });
        },
    },
});

mutation.mutate({
    data: { name: { givenName: 'Ada', familyName: 'Lovelace' }, emails: [{ type: 'work', value: 'ada@example.com' }] },
});

getContact

Récupère un contact par son id.

Signature : getContact(id: string) → Promise<ContactResponse>

const response = await contacts.getContact('64b8f2...');
console.log(response.data?.name, response.data?.phoneNumbers);
import { useGetContact } from '@ziwako/contact/react-query';

const { data } = useGetContact(contactId, { query: { enabled: !!contactId } });

updateContact

Met à jour un contact.

Signature : updateContact(id: string, updateContactBody?: UpdateContactBody) → Promise<ContactResponse>

await contacts.updateContact(contactId, { notes: 'Cliente fidèle' });
import { useUpdateContact } from '@ziwako/contact/react-query';

const mutation = useUpdateContact();
mutation.mutate({ id: contactId, data: { notes: 'Cliente fidèle' } });

deleteContact

Supprime un contact.

Signature : deleteContact(id: string) → Promise<DeleteContact200>

await contacts.deleteContact(contactId);
import { useDeleteContact } from '@ziwako/contact/react-query';

const mutation = useDeleteContact();
mutation.mutate({ id: contactId });

Doublons & fusion

findDuplicateContacts

Détecte les contacts en double dans le carnet.

Signature : findDuplicateContacts() → Promise<FindDuplicateContacts200>

const duplicates = await contacts.findDuplicateContacts();
console.log(duplicates.data?.groups);
import { useFindDuplicateContacts } from '@ziwako/contact/react-query';

const { data } = useFindDuplicateContacts();

mergeContacts

Fusionne plusieurs contacts en un seul (nettoie les doublons).

Signature : mergeContacts(mergeContactsBody?: MergeContactsBody) → Promise<MergeContacts200>

const merged = await contacts.mergeContacts({
    primaryContactId: '64b8f2...',
    secondaryContactIds: ['64b8f3...', '64b8f4...'],
});
console.log(merged.data?._id);
import { useMergeContacts } from '@ziwako/contact/react-query';

const mutation = useMergeContacts();
mutation.mutate({ data: { primaryContactId: '64b8f2...', secondaryContactIds: ['64b8f3...'] } });

Favoris & labels

toggleContactFavorite

Bascule le statut favori d'un contact.

Signature : toggleContactFavorite(id: string, toggleContactFavoriteBody?: ToggleContactFavoriteBody) → Promise<ContactResponse>

await contacts.toggleContactFavorite(contactId, { isFavorite: true });
import { useToggleContactFavorite } from '@ziwako/contact/react-query';

const mutation = useToggleContactFavorite();
mutation.mutate({ id: contactId, data: { isFavorite: true } });

assignContactLabels

Affecte des labels à un contact.

Signature : assignContactLabels(id: string, assignContactLabelsBody?: AssignContactLabelsBody) → Promise<ContactResponse>

await contacts.assignContactLabels(contactId, { labelIds: ['64b8f2...', '64b8f3...'] });
import { useAssignContactLabels } from '@ziwako/contact/react-query';

const mutation = useAssignContactLabels();
mutation.mutate({ id: contactId, data: { labelIds: ['64b8f2...'] } });

removeContactLabel

Retire un label d'un contact.

Signature : removeContactLabel(id: string, labelId: string) → Promise<ContactResponse>

await contacts.removeContactLabel(contactId, labelId);
import { useRemoveContactLabel } from '@ziwako/contact/react-query';

const mutation = useRemoveContactLabel();
mutation.mutate({ id: contactId, labelId });

Export & import

exportContactsVCard

Exporte les contacts au format vCard (retourne une chaîne).

Signature : exportContactsVCard() → Promise<string>

const vcard = await contacts.exportContactsVCard();
console.log(vcard.slice(0, 200));
import { useExportContactsVCard } from '@ziwako/contact/react-query';

const { data, refetch } = useExportContactsVCard();

exportContactsCsv

Exporte les contacts au format CSV (retourne une chaîne).

Signature : exportContactsCsv() → Promise<string>

const csv = await contacts.exportContactsCsv();
import { useExportContactsCsv } from '@ziwako/contact/react-query';

const { data } = useExportContactsCsv();

importContactsVCard

Importe des contacts depuis un fichier vCard (multipart/form-data).

Signature : importContactsVCard(importContactsVCardBody?: ImportContactsVCardBody) → Promise<ImportContactsVCard200>

const response = await contacts.importContactsVCard({
    file: new File([vcardContent], 'contacts.vcf', { type: 'text/vcard' }),
});
console.log(response.data?.imported);
import { useImportContactsVCard } from '@ziwako/contact/react-query';

const mutation = useImportContactsVCard();
mutation.mutate({ data: { file: selectedFile } });

importContactsCsv

Importe des contacts depuis un fichier CSV (multipart/form-data).

Signature : importContactsCsv(importContactsCsvBody?: ImportContactsCsvBody) → Promise<ImportContactsCsv200>

const response = await contacts.importContactsCsv({
    file: new File([csvContent], 'contacts.csv', { type: 'text/csv' }),
});
console.log(response.data?.imported);
import { useImportContactsCsv } from '@ziwako/contact/react-query';

const mutation = useImportContactsCsv();
mutation.mutate({ data: { file: selectedFile } });