feat(consent): add versioned append-only consent ledger C1-C5
This commit is contained in:
1 parent
008254e44a
commit
de49f93b0b
64 files changed
+9244
-132
No files matched your search
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Generated by orval 🍺
|
||||
* Do not edit manually.
|
||||
* Lincodex API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
import {
|
||||
faker
|
||||
} from '@faker-js/faker';
|
||||
|
||||
import {
|
||||
fakeFromPattern
|
||||
} from '../../mock-pattern';
|
||||
|
||||
import {
|
||||
HttpResponse,
|
||||
http
|
||||
} from 'msw';
|
||||
import type {
|
||||
RequestHandlerOptions
|
||||
} from 'msw';
|
||||
|
||||
import type {
|
||||
ConsentOrganization,
|
||||
ConsentRecordList
|
||||
} from '../../schemas';
|
||||
|
||||
|
||||
export const getListMyConsentsResponseConsentOrganizationMock = (overrideResponse: Partial<ConsentOrganization> = {}): ConsentOrganization => ({...{id: faker.string.uuid(), name: faker.string.alpha({length: {min: 1, max: 200}})}, ...overrideResponse});
|
||||
|
||||
export const getListMyConsentsResponseMock = (overrideResponse: Partial<Extract<ConsentRecordList, object>> = {}): ConsentRecordList => ({items: Array.from({ length: faker.number.int({min: 1, max: 100}) }, (_, i) => i + 1).map(() => ({id: faker.string.uuid(), purpose: faker.helpers.arrayElement(['c1','c2','c3','c4','c5'] as const), state: faker.helpers.arrayElement(['active','superseded','revoked'] as const), text_version: fakeFromPattern("^[A-Za-z0-9._-]+$", {minLength: 1, maxLength: 64}), source: faker.helpers.arrayElement(['registration','consent_settings','invitation_acceptance'] as const), granted_at: faker.date.past().toISOString().slice(0, 19) + 'Z', revoked_at: faker.helpers.arrayElement([faker.date.past().toISOString().slice(0, 19) + 'Z',null,]), revocation_source: faker.helpers.arrayElement([faker.helpers.arrayElement(['consent_settings','support_request'] as const),null,]), organization: faker.helpers.arrayElement([{...getListMyConsentsResponseConsentOrganizationMock()},null,]), fields: faker.helpers.arrayElement([faker.helpers.arrayElements(['full_name','email','phone','telegram'] as const), null]), invitation_id: faker.helpers.arrayElement([faker.string.uuid(), null]), invitation_terms_version: faker.helpers.arrayElement([faker.number.int({min: 1}),null,])})), page: {has_more: faker.datatype.boolean(), next_cursor: faker.helpers.arrayElement([fakeFromPattern("^[A-Za-z0-9_-]+$", {minLength: 1, maxLength: 512}), null])}, ...overrideResponse})
|
||||
|
||||
|
||||
export const getListMyConsentsMockHandler = (overrideResponse?: ConsentRecordList | ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => Promise<ConsentRecordList> | ConsentRecordList), options?: RequestHandlerOptions) => {
|
||||
return http.get('*/api/v1/me/consents', async (info: Parameters<Parameters<typeof http.get>[1]>[0]) => {
|
||||
|
||||
|
||||
return HttpResponse.json(overrideResponse !== undefined
|
||||
? (typeof overrideResponse === "function" ? await overrideResponse(info) : overrideResponse)
|
||||
: getListMyConsentsResponseMock(),
|
||||
{ status: 200
|
||||
})
|
||||
}, options)
|
||||
}
|
||||
export const getConsentMock = () => [
|
||||
getListMyConsentsMockHandler()
|
||||
]
|
||||
@@ -0,0 +1,166 @@
|
||||
/**
|
||||
* Generated by orval 🍺
|
||||
* Do not edit manually.
|
||||
* Lincodex API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
import {
|
||||
useQuery
|
||||
} from '@tanstack/react-query';
|
||||
import type {
|
||||
DataTag,
|
||||
DefinedInitialDataOptions,
|
||||
DefinedUseQueryResult,
|
||||
QueryClient,
|
||||
QueryFunction,
|
||||
QueryKey,
|
||||
UndefinedInitialDataOptions,
|
||||
UseQueryOptions,
|
||||
UseQueryResult
|
||||
} from '@tanstack/react-query';
|
||||
|
||||
import type {
|
||||
ConsentRecordList,
|
||||
ListMyConsentsParams,
|
||||
Problem
|
||||
} from '../../schemas';
|
||||
|
||||
import { apiRequest } from '../../client';
|
||||
import type { ErrorType } from '../../client';
|
||||
|
||||
|
||||
type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];
|
||||
|
||||
|
||||
|
||||
const withQueryKey = <T extends object, K>(query: T, queryKey: K): T & { queryKey: K } => {
|
||||
const result = { queryKey } as T & { queryKey: K };
|
||||
for (const key of Object.keys(query)) {
|
||||
// The explicit queryKey always wins, matching the previous
|
||||
// `{ ...query, queryKey }` spread where it was set last.
|
||||
if (key === 'queryKey') continue;
|
||||
Object.defineProperty(result, key, {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
get: () => (query as Record<string, unknown>)[key],
|
||||
});
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
export const getListMyConsentsUrl = (params?: ListMyConsentsParams,) => {
|
||||
const normalizedParams = new URLSearchParams();
|
||||
|
||||
Object.entries(params || {}).forEach(([key, value]) => {
|
||||
|
||||
if (value !== undefined) {
|
||||
normalizedParams.append(key, value === null ? 'null' : String(value))
|
||||
}
|
||||
});
|
||||
|
||||
const stringifiedParams = normalizedParams.toString();
|
||||
|
||||
return stringifiedParams.length > 0 ? `/api/v1/me/consents?${stringifiedParams}` : `/api/v1/me/consents`
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires the session cookie of a candidate or an employer account. The subject comes from the session, never from a request parameter, so the response holds only the caller's own consents: no request can name another account, and records of other accounts are never listed. Returns a page of the consent ledger of the account, newest grant first with the identifier as the tie-breaker, with cursor pagination.
|
||||
*
|
||||
* The ledger is append-only. Every grant is a record with its purpose, the accepted text version, the source, and the grant time; the server also stores the hash of exactly the text the subject saw. A newer text version of the same purpose is a new record, and the earlier one becomes `superseded` without any change. A revocation stamps every unrevoked record of the purpose, and for c4 of one organization, once; a later grant is a new record. Purposes are independent.
|
||||
*
|
||||
* Without `state` the page lists the whole history; `state=active` lists the consents that hold now, one per purpose for c1, c2, c3, and c5 and one per accepted invitation for c4. A c4 record names the organization with the name its consent text showed (a snapshot that a later rename does not change), the selected contact fields, and the invitation with its terms version; it never carries a contact value. A c2 record proves the consent to the publication text; the published field set and its changes are evidence of the publication history (TASK-088).
|
||||
*
|
||||
* Granting c1, c2, c3, and c5 in the consent settings and revoking any purpose are planned operations of this tag (TASK-063 and TASK-064); c1 is given at registration and c4 only in AcceptMyInvitation.
|
||||
*
|
||||
* Access: a missing, unknown, expired, or revoked session answers 401 unauthenticated. A malformed `limit`, `cursor`, or `state` answers 400 validation_failed.
|
||||
* @summary List the consents of the current account with their history.
|
||||
*/
|
||||
export const listMyConsents = async (params?: ListMyConsentsParams, options?: Parameters<typeof apiRequest>[1]): Promise<ConsentRecordList> => {
|
||||
|
||||
return apiRequest<ConsentRecordList>(getListMyConsentsUrl(params),
|
||||
{
|
||||
...options,
|
||||
method: 'GET'
|
||||
|
||||
|
||||
}
|
||||
);}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export const getListMyConsentsQueryKey = (params?: ListMyConsentsParams,) => {
|
||||
return [
|
||||
`/api/v1/me/consents`, ...(params ? [params] : [])
|
||||
] as const;
|
||||
}
|
||||
|
||||
|
||||
export const getListMyConsentsQueryOptions = <TData = Awaited<ReturnType<typeof listMyConsents>>, TError = ErrorType<Problem>>(params?: ListMyConsentsParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof listMyConsents>>, TError, TData>>, request?: SecondParameter<typeof apiRequest>}
|
||||
) => {
|
||||
|
||||
const {query: queryOptions, request: requestOptions} = options ?? {};
|
||||
|
||||
const queryKey = queryOptions?.queryKey ?? getListMyConsentsQueryKey(params);
|
||||
|
||||
|
||||
|
||||
const queryFn: QueryFunction<Awaited<ReturnType<typeof listMyConsents>>> = ({ signal }) => listMyConsents(params, { signal, ...requestOptions });
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof listMyConsents>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
|
||||
}
|
||||
|
||||
export type ListMyConsentsQueryResult = NonNullable<Awaited<ReturnType<typeof listMyConsents>>>
|
||||
export type ListMyConsentsQueryError = ErrorType<Problem>
|
||||
|
||||
|
||||
export function useListMyConsents<TData = Awaited<ReturnType<typeof listMyConsents>>, TError = ErrorType<Problem>>(
|
||||
params: undefined | ListMyConsentsParams, options: { query:Partial<UseQueryOptions<Awaited<ReturnType<typeof listMyConsents>>, TError, TData>> & Pick<
|
||||
DefinedInitialDataOptions<
|
||||
Awaited<ReturnType<typeof listMyConsents>>,
|
||||
TError,
|
||||
Awaited<ReturnType<typeof listMyConsents>>
|
||||
> , 'initialData'
|
||||
>, request?: SecondParameter<typeof apiRequest>}
|
||||
, queryClient?: QueryClient
|
||||
): DefinedUseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
|
||||
export function useListMyConsents<TData = Awaited<ReturnType<typeof listMyConsents>>, TError = ErrorType<Problem>>(
|
||||
params?: ListMyConsentsParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof listMyConsents>>, TError, TData>> & Pick<
|
||||
UndefinedInitialDataOptions<
|
||||
Awaited<ReturnType<typeof listMyConsents>>,
|
||||
TError,
|
||||
Awaited<ReturnType<typeof listMyConsents>>
|
||||
> , 'initialData'
|
||||
>, request?: SecondParameter<typeof apiRequest>}
|
||||
, queryClient?: QueryClient
|
||||
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
|
||||
export function useListMyConsents<TData = Awaited<ReturnType<typeof listMyConsents>>, TError = ErrorType<Problem>>(
|
||||
params?: ListMyConsentsParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof listMyConsents>>, TError, TData>>, request?: SecondParameter<typeof apiRequest>}
|
||||
, queryClient?: QueryClient
|
||||
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
|
||||
/**
|
||||
* @summary List the consents of the current account with their history.
|
||||
*/
|
||||
|
||||
export function useListMyConsents<TData = Awaited<ReturnType<typeof listMyConsents>>, TError = ErrorType<Problem>>(
|
||||
params?: ListMyConsentsParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof listMyConsents>>, TError, TData>>, request?: SecondParameter<typeof apiRequest>}
|
||||
, queryClient?: QueryClient
|
||||
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
|
||||
|
||||
const queryOptions = getListMyConsentsQueryOptions(params,options)
|
||||
|
||||
const query = useQuery(queryOptions, queryClient) as UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
|
||||
|
||||
return withQueryKey(query, queryOptions.queryKey);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
export { getAssessmentMock } from './assessment/assessment.msw'
|
||||
export { getCandidateMock } from './candidate/candidate.msw'
|
||||
export { getCatalogMock } from './catalog/catalog.msw'
|
||||
export { getConsentMock } from './consent/consent.msw'
|
||||
export { getHealthMock } from './health/health.msw'
|
||||
export { getIdentityMock } from './identity/identity.msw'
|
||||
export { getInvitationMock } from './invitation/invitation.msw'
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
export * from './assessment/assessment';
|
||||
export * from './candidate/candidate';
|
||||
export * from './catalog/catalog';
|
||||
export * from './consent/consent';
|
||||
export * from './health/health';
|
||||
export * from './identity/identity';
|
||||
export * from './invitation/invitation';
|
||||
|
||||
Reference in new issue
Block a user