Appels à l'API

Afin d’utiliser les fonctionnalités décrites dans cette page, il est impératif d’avoir initialiser la librairie comme indiqué dans la section

Consent.js implémente une bibliothèque de méthodes permettant d’interfacer avec l' Right Consents.

Ces méthodes définisents des paramètres en entrée et en sortie de chaque endpoint, et utilise une fonction de requêtage HTTP.

Client HTTP

Afin que les méthodes d’appel à l’API fonctionnent correctement, un Client HTTP doit être fourni à la librairie. II en existe un par défaut, mais il ne répondra peut-être pas à tous vos besoins.

Le client HTTP doit correspondre à un objet de type RcHttpClient, disponible depuis @fairandsmart/consent-manager/http

Voici un exemple de création d’un client HTTP compatible, suivi de l’utilisation d’une méthode d’appel à l’API.

import { RightConsents, RcHttpClientConfig } from '@fairandsmart/consent-manager'; // Création du client HTTP. function myCustomHttpClient(config: RcHttpClientConfig): Observable<ModelEntryDto> { // ajouter une clé API, un workflow oAuth, etc., puis effectuer l'appel HTTP. return fromFetch(config.url, ...); } // Initialisation de la librairie RightConsents RightConsents.init({ apiRoot: 'https://consent-manager.fairandsmart.com', catalogRoot: 'https://catalog.fairandsmart.com', httpClient: myCustomHttpClient, }); // Appel à l'API avec un observable ModelsResource.getEntry(entryId).subscribe((modelEntry: ModelEntryDto) => { ... }); // ... ou avec une promesse, avec la fonction .toPromise(); const modelEntry: ModelEntryDto = await ModelsResource.getEntry(entryId).toPromise();

Endpoints

ConsentsResource

createTransactionJson

POST /consents

Prend un ConsentContext en entrée et créer une nouvelle transaction pour le contexte donné, dans la langue spécifiée.

Retourne le token de la transaction.

import { createTransactionJson } from '@fairandsmart/consent-manager/consents'; createTransactionJson(ctx: ConsentContext, lang: string, options?: RCApiOptions): Observable<string>

 

getTransactionJson

GET /consents/:transactionId

import { getTransactionJson } from '@fairandsmart/consent-manager/consents'; getTransactionJson(transactionId: string, options?: RCApiOptions): Observable<string>

 

postSubmissionValuesHtml

POST /consents/:transactionId/submit

getSubmitFormPreview

POST /consents/preview

KeysResource

listKeys

GET /keys

 

createKey

POST /keys

deleteKey

DELETE /keys/:keyId

ModelsResource

listEntries

GET /models

 

createEntry

POST /models

 

getEntry

GET /models/:modelId

 

updateEntry

PUT /models/:modelId

 

deleteEntry

DELETE /models/:modelId

 

setDefaultInfoModel

POST /models/defaultinfo

 

listVersions

GET /models/:modelId/versions

 

createVersion

POST /models/:modelId/versions

 

getLatestVersion

GET /models/:modelId/versions/latest

 

getActiveVersion

GET /models/:modelId/versions/active

 

getVersion

GET /models/:modelId/versions/:versionId

 

updateVersion

PUT /models/:modelId/versions/:versionId

 

updateVersionStatus

PUT /models/:modelId/versions/:versionId/status

 

updateVersionType

PUT /models/:modelId/versions/:versionId/type

 

getVersionPreview

POST /models/:modelId/versions/:versionId/preview

 

deleteVersion

DELETE /models/:modelId/versions/:versionId

 

exportEntry

GET /models/:modelId/export

 

importEntry

POST /models/import

 

ReceiptsResource

getReceiptPdf

GET /receipts/:transactionId

 

RecordsResource

listRecordsOfSubject

GET /records

 

extractRecords

POST /records/extraction

 

extractRecordsCsv

POST /records/extraction

 

StatisticsResource

getStats

GET /stats

 

SubjectsResource

listSubjects

GET /subjects

 

getSubject

GET /subjects/:subjectId

 

createSubject

POST /subjects

 

updateSubject

PUT /subjects/:subjectId

 

listSubjectRecords

GET /subjects/:subjectId/records

 

SystemResource

getSupportInfo

GET /system/support/infos

 

getClientConfig

GET /system/config

 

TokensResource

createToken

POST /tokens

 

UsersResource

getMe

GET /user

 

getRecordsForUser

GET /user

 

getUserStatus

GET /user

 

 

Options additionnelles (RcApiOptions)

Chaque méthode d’appel à l’API prend un paramètre optionnel appelé options et de type RcApiOptions. Il s’agit d’un objet de configuration supplémentaire qui pourra être passé à votre client HTTP pour certains cas particuliers.