feat(accounts): add consent settings and organization management
This commit is contained in:
1 parent
24638d46d2
commit
391af7a1ef
83 files changed
+10198
-613
No files matched your search
@@ -21,15 +21,38 @@ import type {
|
||||
} from 'msw';
|
||||
|
||||
import type {
|
||||
ConsentDeletionRequest,
|
||||
ConsentOrganization,
|
||||
ConsentRecordList
|
||||
ConsentRecord,
|
||||
ConsentRecordList,
|
||||
ConsentText
|
||||
} from '../../schemas';
|
||||
|
||||
|
||||
export const getGetMyConsentTextResponseMock = (overrideResponse: Partial<Extract<ConsentText, object>> = {}): ConsentText => ({purpose: faker.helpers.arrayElement(['c1','c2','c3','c4','c5'] as const), text_version: fakeFromPattern("^[A-Za-z0-9._-]+$", {minLength: 1, maxLength: 64}), text: faker.string.alpha({length: {min: 1, max: 100000}}), published_at: faker.date.past().toISOString().slice(0, 19) + 'Z', ...overrideResponse})
|
||||
|
||||
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 getGrantMyConsentResponseConsentOrganizationMock = (overrideResponse: Partial<ConsentOrganization> = {}): ConsentOrganization => ({...{id: faker.string.uuid(), name: faker.string.alpha({length: {min: 1, max: 200}})}, ...overrideResponse});
|
||||
|
||||
export const getGrantMyConsentResponseMock = (overrideResponse: Partial<Extract<ConsentRecord, object>> = {}): ConsentRecord => ({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([{...getGrantMyConsentResponseConsentOrganizationMock()},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,]), ...overrideResponse})
|
||||
|
||||
export const getRequestMyAccountDeletionResponseMock = (overrideResponse: Partial<Extract<ConsentDeletionRequest, object>> = {}): ConsentDeletionRequest => ({id: faker.string.uuid(), status: faker.helpers.arrayElement(['requested','processing'] as const), requested_at: faker.date.past().toISOString().slice(0, 19) + 'Z', ...overrideResponse})
|
||||
|
||||
|
||||
export const getGetMyConsentTextMockHandler = (overrideResponse?: ConsentText | ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => Promise<ConsentText> | ConsentText), options?: RequestHandlerOptions) => {
|
||||
return http.get('*/api/v1/me/consent-texts/:purpose', async (info: Parameters<Parameters<typeof http.get>[1]>[0]) => {
|
||||
|
||||
|
||||
return HttpResponse.json(overrideResponse !== undefined
|
||||
? (typeof overrideResponse === "function" ? await overrideResponse(info) : overrideResponse)
|
||||
: getGetMyConsentTextResponseMock(),
|
||||
{ status: 200
|
||||
})
|
||||
}, options)
|
||||
}
|
||||
|
||||
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]) => {
|
||||
@@ -42,6 +65,55 @@ export const getListMyConsentsMockHandler = (overrideResponse?: ConsentRecordLis
|
||||
})
|
||||
}, options)
|
||||
}
|
||||
|
||||
export const getGrantMyConsentMockHandler = (overrideResponse?: ConsentRecord | ((info: Parameters<Parameters<typeof http.put>[1]>[0]) => Promise<ConsentRecord> | ConsentRecord), options?: RequestHandlerOptions) => {
|
||||
return http.put('*/api/v1/me/consents/:purpose', async (info: Parameters<Parameters<typeof http.put>[1]>[0]) => {
|
||||
|
||||
|
||||
return HttpResponse.json(overrideResponse !== undefined
|
||||
? (typeof overrideResponse === "function" ? await overrideResponse(info) : overrideResponse)
|
||||
: getGrantMyConsentResponseMock(),
|
||||
{ status: 200
|
||||
})
|
||||
}, options)
|
||||
}
|
||||
|
||||
export const getRevokeMyConsentMockHandler = (overrideResponse?: void | ((info: Parameters<Parameters<typeof http.delete>[1]>[0]) => Promise<void> | void), options?: RequestHandlerOptions) => {
|
||||
return http.delete('*/api/v1/me/consents/:purpose', async (info: Parameters<Parameters<typeof http.delete>[1]>[0]) => {
|
||||
if (typeof overrideResponse === 'function') {await overrideResponse(info); }
|
||||
|
||||
return new HttpResponse(null,
|
||||
{ status: 204
|
||||
})
|
||||
}, options)
|
||||
}
|
||||
|
||||
export const getRevokeMyOrganizationContactConsentMockHandler = (overrideResponse?: void | ((info: Parameters<Parameters<typeof http.delete>[1]>[0]) => Promise<void> | void), options?: RequestHandlerOptions) => {
|
||||
return http.delete('*/api/v1/me/consents/c4/organizations/:orgId', async (info: Parameters<Parameters<typeof http.delete>[1]>[0]) => {
|
||||
if (typeof overrideResponse === 'function') {await overrideResponse(info); }
|
||||
|
||||
return new HttpResponse(null,
|
||||
{ status: 204
|
||||
})
|
||||
}, options)
|
||||
}
|
||||
|
||||
export const getRequestMyAccountDeletionMockHandler = (overrideResponse?: ConsentDeletionRequest | ((info: Parameters<Parameters<typeof http.post>[1]>[0]) => Promise<ConsentDeletionRequest> | ConsentDeletionRequest), options?: RequestHandlerOptions) => {
|
||||
return http.post('*/api/v1/me/account-deletion-requests', async (info: Parameters<Parameters<typeof http.post>[1]>[0]) => {
|
||||
|
||||
|
||||
return HttpResponse.json(overrideResponse !== undefined
|
||||
? (typeof overrideResponse === "function" ? await overrideResponse(info) : overrideResponse)
|
||||
: getRequestMyAccountDeletionResponseMock(),
|
||||
{ status: 202
|
||||
})
|
||||
}, options)
|
||||
}
|
||||
export const getConsentMock = () => [
|
||||
getListMyConsentsMockHandler()
|
||||
getGetMyConsentTextMockHandler(),
|
||||
getListMyConsentsMockHandler(),
|
||||
getGrantMyConsentMockHandler(),
|
||||
getRevokeMyConsentMockHandler(),
|
||||
getRevokeMyOrganizationContactConsentMockHandler(),
|
||||
getRequestMyAccountDeletionMockHandler()
|
||||
]
|
||||
@@ -5,22 +5,32 @@
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
import {
|
||||
useMutation,
|
||||
useQuery
|
||||
} from '@tanstack/react-query';
|
||||
import type {
|
||||
DataTag,
|
||||
DefinedInitialDataOptions,
|
||||
DefinedUseQueryResult,
|
||||
MutationFunction,
|
||||
QueryClient,
|
||||
QueryFunction,
|
||||
QueryKey,
|
||||
UndefinedInitialDataOptions,
|
||||
UseMutationOptions,
|
||||
UseMutationResult,
|
||||
UseQueryOptions,
|
||||
UseQueryResult
|
||||
} from '@tanstack/react-query';
|
||||
|
||||
import type {
|
||||
ConsentDeletionRequest,
|
||||
ConsentRecord,
|
||||
ConsentRecordList,
|
||||
ConsentSettingsGrantRequest,
|
||||
ConsentSettingsPurpose,
|
||||
ConsentSettingsRevokePurpose,
|
||||
ConsentText,
|
||||
ListMyConsentsParams,
|
||||
Problem
|
||||
} from '../../schemas';
|
||||
@@ -48,6 +58,107 @@ const withQueryKey = <T extends object, K>(query: T, queryKey: K): T & { queryKe
|
||||
return result;
|
||||
};
|
||||
|
||||
export const getGetMyConsentTextUrl = (purpose: ConsentSettingsPurpose,) => {
|
||||
|
||||
|
||||
|
||||
|
||||
return `/api/v1/me/consent-texts/${purpose}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires a verified session. Returns the current published text and version of c1, c2, c3, or c5 so the user can read the exact text before an explicit settings grant. C4 is excluded: its text includes an organization snapshot and it is granted only during invitation acceptance. The response is private and is not cached.
|
||||
* @summary Read a current consent text for account settings.
|
||||
*/
|
||||
export const getMyConsentText = async (purpose: ConsentSettingsPurpose, options?: Parameters<typeof apiRequest>[1]): Promise<ConsentText> => {
|
||||
|
||||
return apiRequest<ConsentText>(getGetMyConsentTextUrl(purpose),
|
||||
{
|
||||
...options,
|
||||
method: 'GET'
|
||||
|
||||
|
||||
}
|
||||
);}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export const getGetMyConsentTextQueryKey = (purpose: ConsentSettingsPurpose,) => {
|
||||
return [
|
||||
`/api/v1/me/consent-texts/${purpose}`
|
||||
] as const;
|
||||
}
|
||||
|
||||
|
||||
export const getGetMyConsentTextQueryOptions = <TData = Awaited<ReturnType<typeof getMyConsentText>>, TError = ErrorType<Problem>>(purpose: ConsentSettingsPurpose, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getMyConsentText>>, TError, TData>>, request?: SecondParameter<typeof apiRequest>}
|
||||
) => {
|
||||
|
||||
const {query: queryOptions, request: requestOptions} = options ?? {};
|
||||
|
||||
const queryKey = queryOptions?.queryKey ?? getGetMyConsentTextQueryKey(purpose);
|
||||
|
||||
|
||||
|
||||
const queryFn: QueryFunction<Awaited<ReturnType<typeof getMyConsentText>>> = ({ signal }) => getMyConsentText(purpose, { signal, ...requestOptions });
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { queryKey, queryFn, enabled: purpose !== null && purpose !== undefined, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getMyConsentText>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
|
||||
}
|
||||
|
||||
export type GetMyConsentTextQueryResult = NonNullable<Awaited<ReturnType<typeof getMyConsentText>>>
|
||||
export type GetMyConsentTextQueryError = ErrorType<Problem>
|
||||
|
||||
|
||||
export function useGetMyConsentText<TData = Awaited<ReturnType<typeof getMyConsentText>>, TError = ErrorType<Problem>>(
|
||||
purpose: ConsentSettingsPurpose, options: { query:Partial<UseQueryOptions<Awaited<ReturnType<typeof getMyConsentText>>, TError, TData>> & Pick<
|
||||
DefinedInitialDataOptions<
|
||||
Awaited<ReturnType<typeof getMyConsentText>>,
|
||||
TError,
|
||||
Awaited<ReturnType<typeof getMyConsentText>>
|
||||
> , 'initialData'
|
||||
>, request?: SecondParameter<typeof apiRequest>}
|
||||
, queryClient?: QueryClient
|
||||
): DefinedUseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
|
||||
export function useGetMyConsentText<TData = Awaited<ReturnType<typeof getMyConsentText>>, TError = ErrorType<Problem>>(
|
||||
purpose: ConsentSettingsPurpose, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getMyConsentText>>, TError, TData>> & Pick<
|
||||
UndefinedInitialDataOptions<
|
||||
Awaited<ReturnType<typeof getMyConsentText>>,
|
||||
TError,
|
||||
Awaited<ReturnType<typeof getMyConsentText>>
|
||||
> , 'initialData'
|
||||
>, request?: SecondParameter<typeof apiRequest>}
|
||||
, queryClient?: QueryClient
|
||||
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
|
||||
export function useGetMyConsentText<TData = Awaited<ReturnType<typeof getMyConsentText>>, TError = ErrorType<Problem>>(
|
||||
purpose: ConsentSettingsPurpose, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getMyConsentText>>, TError, TData>>, request?: SecondParameter<typeof apiRequest>}
|
||||
, queryClient?: QueryClient
|
||||
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
|
||||
/**
|
||||
* @summary Read a current consent text for account settings.
|
||||
*/
|
||||
|
||||
export function useGetMyConsentText<TData = Awaited<ReturnType<typeof getMyConsentText>>, TError = ErrorType<Problem>>(
|
||||
purpose: ConsentSettingsPurpose, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getMyConsentText>>, TError, TData>>, request?: SecondParameter<typeof apiRequest>}
|
||||
, queryClient?: QueryClient
|
||||
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
|
||||
|
||||
const queryOptions = getGetMyConsentTextQueryOptions(purpose,options)
|
||||
|
||||
const query = useQuery(queryOptions, queryClient) as UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
|
||||
|
||||
return withQueryKey(query, queryOptions.queryKey);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export const getListMyConsentsUrl = (params?: ListMyConsentsParams,) => {
|
||||
const normalizedParams = new URLSearchParams();
|
||||
|
||||
@@ -70,7 +181,7 @@ export const getListMyConsentsUrl = (params?: ListMyConsentsParams,) => {
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Granting c1, c2, c3, and c5 in the consent settings and revoking any purpose are planned operations of this tag; c1 is given at registration and c4 only in AcceptMyInvitation.
|
||||
* Settings grants of c1, c2, c3, and c5 require the currently published text and an explicit acceptance. Revoking c2, c3, or c5 is available in settings; c1 creates a durable account-deletion request, and c4 is revoked only for one organization. C4 is granted 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.
|
||||
@@ -164,3 +275,318 @@ export function useListMyConsents<TData = Awaited<ReturnType<typeof listMyConsen
|
||||
|
||||
|
||||
|
||||
export const getGrantMyConsentUrl = (purpose: ConsentSettingsPurpose,) => {
|
||||
|
||||
|
||||
|
||||
|
||||
return `/api/v1/me/consents/${purpose}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires a verified session, its CSRF token in X-CSRF-Token, and the exact configured Origin. The subject comes from the session. The body names the current text version the user read and requires `accepted: true`; the server verifies that version is still current and stores the hash of the exact text. A stale version answers 400 validation_failed at `/text_version`, without writing a grant.
|
||||
*
|
||||
* C1 is available to candidate and employer accounts. C2, C3, and C5 are available only to candidate accounts. C4 is excluded and can be granted only by accepting an invitation. A repeated grant of the same current version returns the existing record; after revocation a grant creates a new record and never reopens a publication or restores an older grant.
|
||||
* @summary Record an explicit consent grant from settings.
|
||||
*/
|
||||
export const grantMyConsent = async (purpose: ConsentSettingsPurpose,
|
||||
consentSettingsGrantRequest: ConsentSettingsGrantRequest, options?: Parameters<typeof apiRequest>[1]): Promise<ConsentRecord> => {
|
||||
|
||||
const getHeaders = (h?: NonNullable<RequestInit['headers']>): Record<string, string | readonly string[]> => {
|
||||
if (!h) return {};
|
||||
if (h instanceof Headers) return Object.fromEntries(h.entries());
|
||||
if (Symbol.iterator in h) {
|
||||
return Object.fromEntries(
|
||||
Array.from(h as Iterable<Iterable<string>>, (entry) => Array.from(entry) as [string, string]),
|
||||
);
|
||||
}
|
||||
const headers: Record<string, string | readonly string[]> = {};
|
||||
for (const [name, value] of Object.entries<string | readonly string[] | undefined>(h)) {
|
||||
if (value !== undefined) headers[name] = value;
|
||||
}
|
||||
return headers;
|
||||
};
|
||||
return apiRequest<ConsentRecord>(getGrantMyConsentUrl(purpose),
|
||||
{
|
||||
...options,
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json', ...getHeaders(options?.headers) },
|
||||
body: JSON.stringify(consentSettingsGrantRequest)
|
||||
}
|
||||
);}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export const getGrantMyConsentMutationKey = () => ['grantMyConsent'] as const;
|
||||
|
||||
export const getGrantMyConsentMutationOptions = <TError = ErrorType<Problem>,
|
||||
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof grantMyConsent>>, TError,GrantMyConsentMutationVariables, TContext>, request?: SecondParameter<typeof apiRequest>}
|
||||
): UseMutationOptions<Awaited<ReturnType<typeof grantMyConsent>>, TError,GrantMyConsentMutationVariables, TContext> => {
|
||||
|
||||
const mutationKey = getGrantMyConsentMutationKey();
|
||||
const {mutation: mutationOptions, request: requestOptions} = options ?
|
||||
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
||||
options
|
||||
: {...options, mutation: {...options.mutation, mutationKey}}
|
||||
: {mutation: { mutationKey, }, request: undefined};
|
||||
|
||||
|
||||
|
||||
|
||||
const mutationFn: MutationFunction<Awaited<ReturnType<typeof grantMyConsent>>, GrantMyConsentMutationVariables> = (props) => {
|
||||
const {purpose,data} = props ?? {};
|
||||
|
||||
return grantMyConsent(purpose,data,requestOptions)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { mutationFn, ...mutationOptions }}
|
||||
|
||||
export type GrantMyConsentMutationResult = NonNullable<Awaited<ReturnType<typeof grantMyConsent>>>
|
||||
export type GrantMyConsentMutationBody = ConsentSettingsGrantRequest
|
||||
export type GrantMyConsentMutationError = ErrorType<Problem>
|
||||
export type GrantMyConsentMutationVariables = {purpose: ConsentSettingsPurpose;data: ConsentSettingsGrantRequest}
|
||||
|
||||
/**
|
||||
* @summary Record an explicit consent grant from settings.
|
||||
*/
|
||||
export const useGrantMyConsent = <TError = ErrorType<Problem>,
|
||||
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof grantMyConsent>>, TError,GrantMyConsentMutationVariables, TContext>, request?: SecondParameter<typeof apiRequest>}
|
||||
, queryClient?: QueryClient): UseMutationResult<
|
||||
Awaited<ReturnType<typeof grantMyConsent>>,
|
||||
TError,
|
||||
GrantMyConsentMutationVariables,
|
||||
TContext
|
||||
> => {
|
||||
return useMutation(getGrantMyConsentMutationOptions(options), queryClient);
|
||||
}
|
||||
export const getRevokeMyConsentUrl = (purpose: ConsentSettingsRevokePurpose,) => {
|
||||
|
||||
|
||||
|
||||
|
||||
return `/api/v1/me/consents/${purpose}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires a verified candidate session, its CSRF token in X-CSRF-Token, and the exact configured Origin. The subject comes from the session. Revokes every unrevoked record of c2, c3, or c5, including superseded records, and never changes another purpose. Repeating a revocation is harmless and creates no duplicate event.
|
||||
*
|
||||
* Revoking c2 immediately closes the stored publication and records privacy history in the same transaction; a downstream revocation intent is written to the outbox. A later c2 grant does not reopen publication or restore old grants. Revoking c3 does not block the manual assessment path. Revoking c5 makes the consent gate deny further FSP import and writes a durable stop/delete intent; an external FSP deletion adapter is not available yet.
|
||||
* @summary Revoke a non-scoped consent from settings.
|
||||
*/
|
||||
export const revokeMyConsent = async (purpose: ConsentSettingsRevokePurpose, options?: Parameters<typeof apiRequest>[1]): Promise<void> => {
|
||||
|
||||
return apiRequest<void>(getRevokeMyConsentUrl(purpose),
|
||||
{
|
||||
...options,
|
||||
method: 'DELETE'
|
||||
|
||||
|
||||
}
|
||||
);}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export const getRevokeMyConsentMutationKey = () => ['revokeMyConsent'] as const;
|
||||
|
||||
export const getRevokeMyConsentMutationOptions = <TError = ErrorType<Problem>,
|
||||
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof revokeMyConsent>>, TError,RevokeMyConsentMutationVariables, TContext>, request?: SecondParameter<typeof apiRequest>}
|
||||
): UseMutationOptions<Awaited<ReturnType<typeof revokeMyConsent>>, TError,RevokeMyConsentMutationVariables, TContext> => {
|
||||
|
||||
const mutationKey = getRevokeMyConsentMutationKey();
|
||||
const {mutation: mutationOptions, request: requestOptions} = options ?
|
||||
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
||||
options
|
||||
: {...options, mutation: {...options.mutation, mutationKey}}
|
||||
: {mutation: { mutationKey, }, request: undefined};
|
||||
|
||||
|
||||
|
||||
|
||||
const mutationFn: MutationFunction<Awaited<ReturnType<typeof revokeMyConsent>>, RevokeMyConsentMutationVariables> = (props) => {
|
||||
const {purpose} = props ?? {};
|
||||
|
||||
return revokeMyConsent(purpose,requestOptions)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { mutationFn, ...mutationOptions }}
|
||||
|
||||
export type RevokeMyConsentMutationResult = NonNullable<Awaited<ReturnType<typeof revokeMyConsent>>>
|
||||
|
||||
export type RevokeMyConsentMutationError = ErrorType<Problem>
|
||||
export type RevokeMyConsentMutationVariables = {purpose: ConsentSettingsRevokePurpose}
|
||||
|
||||
/**
|
||||
* @summary Revoke a non-scoped consent from settings.
|
||||
*/
|
||||
export const useRevokeMyConsent = <TError = ErrorType<Problem>,
|
||||
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof revokeMyConsent>>, TError,RevokeMyConsentMutationVariables, TContext>, request?: SecondParameter<typeof apiRequest>}
|
||||
, queryClient?: QueryClient): UseMutationResult<
|
||||
Awaited<ReturnType<typeof revokeMyConsent>>,
|
||||
TError,
|
||||
RevokeMyConsentMutationVariables,
|
||||
TContext
|
||||
> => {
|
||||
return useMutation(getRevokeMyConsentMutationOptions(options), queryClient);
|
||||
}
|
||||
export const getRevokeMyOrganizationContactConsentUrl = (orgId: string,) => {
|
||||
|
||||
|
||||
|
||||
|
||||
return `/api/v1/me/consents/c4/organizations/${orgId}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires a verified candidate session, its CSRF token in X-CSRF-Token, and the exact configured Origin. The subject comes from the session; `org_id` is the only scope the caller may choose. The server revokes every unrevoked C4 record for this subject and organization, using the fields stored on those records to request downstream grant revocation. It does not affect another organization. Repeating the request is harmless and creates no duplicate event.
|
||||
* @summary Revoke C4 for one organization.
|
||||
*/
|
||||
export const revokeMyOrganizationContactConsent = async (orgId: string, options?: Parameters<typeof apiRequest>[1]): Promise<void> => {
|
||||
|
||||
return apiRequest<void>(getRevokeMyOrganizationContactConsentUrl(orgId),
|
||||
{
|
||||
...options,
|
||||
method: 'DELETE'
|
||||
|
||||
|
||||
}
|
||||
);}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export const getRevokeMyOrganizationContactConsentMutationKey = () => ['revokeMyOrganizationContactConsent'] as const;
|
||||
|
||||
export const getRevokeMyOrganizationContactConsentMutationOptions = <TError = ErrorType<Problem>,
|
||||
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof revokeMyOrganizationContactConsent>>, TError,RevokeMyOrganizationContactConsentMutationVariables, TContext>, request?: SecondParameter<typeof apiRequest>}
|
||||
): UseMutationOptions<Awaited<ReturnType<typeof revokeMyOrganizationContactConsent>>, TError,RevokeMyOrganizationContactConsentMutationVariables, TContext> => {
|
||||
|
||||
const mutationKey = getRevokeMyOrganizationContactConsentMutationKey();
|
||||
const {mutation: mutationOptions, request: requestOptions} = options ?
|
||||
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
||||
options
|
||||
: {...options, mutation: {...options.mutation, mutationKey}}
|
||||
: {mutation: { mutationKey, }, request: undefined};
|
||||
|
||||
|
||||
|
||||
|
||||
const mutationFn: MutationFunction<Awaited<ReturnType<typeof revokeMyOrganizationContactConsent>>, RevokeMyOrganizationContactConsentMutationVariables> = (props) => {
|
||||
const {orgId} = props ?? {};
|
||||
|
||||
return revokeMyOrganizationContactConsent(orgId,requestOptions)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { mutationFn, ...mutationOptions }}
|
||||
|
||||
export type RevokeMyOrganizationContactConsentMutationResult = NonNullable<Awaited<ReturnType<typeof revokeMyOrganizationContactConsent>>>
|
||||
|
||||
export type RevokeMyOrganizationContactConsentMutationError = ErrorType<Problem>
|
||||
export type RevokeMyOrganizationContactConsentMutationVariables = {orgId: string}
|
||||
|
||||
/**
|
||||
* @summary Revoke C4 for one organization.
|
||||
*/
|
||||
export const useRevokeMyOrganizationContactConsent = <TError = ErrorType<Problem>,
|
||||
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof revokeMyOrganizationContactConsent>>, TError,RevokeMyOrganizationContactConsentMutationVariables, TContext>, request?: SecondParameter<typeof apiRequest>}
|
||||
, queryClient?: QueryClient): UseMutationResult<
|
||||
Awaited<ReturnType<typeof revokeMyOrganizationContactConsent>>,
|
||||
TError,
|
||||
RevokeMyOrganizationContactConsentMutationVariables,
|
||||
TContext
|
||||
> => {
|
||||
return useMutation(getRevokeMyOrganizationContactConsentMutationOptions(options), queryClient);
|
||||
}
|
||||
export const getRequestMyAccountDeletionUrl = () => {
|
||||
|
||||
|
||||
|
||||
|
||||
return `/api/v1/me/account-deletion-requests`
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires a verified session, its CSRF token in X-CSRF-Token, and the exact configured Origin. The subject comes from the session. In one transaction, revokes any active C1 record, creates or returns the subject's active durable deletion request, and writes the outbox intent. The API does not delete the account synchronously. Repeating the request returns the same active request; a later C1 grant never cancels it.
|
||||
* @summary Revoke C1 and request account deletion.
|
||||
*/
|
||||
export const requestMyAccountDeletion = async ( options?: Parameters<typeof apiRequest>[1]): Promise<ConsentDeletionRequest> => {
|
||||
|
||||
return apiRequest<ConsentDeletionRequest>(getRequestMyAccountDeletionUrl(),
|
||||
{
|
||||
...options,
|
||||
method: 'POST'
|
||||
|
||||
|
||||
}
|
||||
);}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export const getRequestMyAccountDeletionMutationKey = () => ['requestMyAccountDeletion'] as const;
|
||||
|
||||
export const getRequestMyAccountDeletionMutationOptions = <TError = ErrorType<Problem>,
|
||||
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof requestMyAccountDeletion>>, TError,void, TContext>, request?: SecondParameter<typeof apiRequest>}
|
||||
): UseMutationOptions<Awaited<ReturnType<typeof requestMyAccountDeletion>>, TError,void, TContext> => {
|
||||
|
||||
const mutationKey = getRequestMyAccountDeletionMutationKey();
|
||||
const {mutation: mutationOptions, request: requestOptions} = options ?
|
||||
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
||||
options
|
||||
: {...options, mutation: {...options.mutation, mutationKey}}
|
||||
: {mutation: { mutationKey, }, request: undefined};
|
||||
|
||||
|
||||
|
||||
|
||||
const mutationFn: MutationFunction<Awaited<ReturnType<typeof requestMyAccountDeletion>>, void> = () => {
|
||||
|
||||
|
||||
return requestMyAccountDeletion(requestOptions)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { mutationFn, ...mutationOptions }}
|
||||
|
||||
export type RequestMyAccountDeletionMutationResult = NonNullable<Awaited<ReturnType<typeof requestMyAccountDeletion>>>
|
||||
|
||||
export type RequestMyAccountDeletionMutationError = ErrorType<Problem>
|
||||
|
||||
|
||||
/**
|
||||
* @summary Revoke C1 and request account deletion.
|
||||
*/
|
||||
export const useRequestMyAccountDeletion = <TError = ErrorType<Problem>,
|
||||
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof requestMyAccountDeletion>>, TError,void, TContext>, request?: SecondParameter<typeof apiRequest>}
|
||||
, queryClient?: QueryClient): UseMutationResult<
|
||||
Awaited<ReturnType<typeof requestMyAccountDeletion>>,
|
||||
TError,
|
||||
void,
|
||||
TContext
|
||||
> => {
|
||||
return useMutation(getRequestMyAccountDeletionMutationOptions(options), queryClient);
|
||||
}
|
||||
@@ -29,7 +29,7 @@ import type {
|
||||
} from '../../schemas';
|
||||
|
||||
|
||||
export const getGetConsentTextResponseMock = (overrideResponse: Partial<Extract<ConsentText, object>> = {}): ConsentText => ({purpose: faker.helpers.arrayElement(['c1'] as const), text_version: fakeFromPattern("^[A-Za-z0-9._-]+$", {minLength: 1, maxLength: 64}), text: faker.string.alpha({length: {min: 1, max: 100000}}), published_at: faker.date.past().toISOString().slice(0, 19) + 'Z', ...overrideResponse})
|
||||
export const getGetConsentTextResponseMock = (overrideResponse: Partial<Extract<ConsentText, object>> = {}): ConsentText => ({purpose: faker.helpers.arrayElement(['c1','c2','c3','c4','c5'] as const), text_version: fakeFromPattern("^[A-Za-z0-9._-]+$", {minLength: 1, maxLength: 64}), text: faker.string.alpha({length: {min: 1, max: 100000}}), published_at: faker.date.past().toISOString().slice(0, 19) + 'Z', ...overrideResponse})
|
||||
|
||||
export const getRegisterAccountResponseMock = (overrideResponse: Partial<Extract<IdentityRequestAccepted, object>> = {}): IdentityRequestAccepted => ({status: faker.helpers.arrayElement(['accepted'] as const), ...overrideResponse})
|
||||
|
||||
|
||||
Reference in new issue
Block a user