feat(assessment): add the review band of attempt signals and the disclosed collector
This commit is contained in:
1 parent
68286af8b7
commit
b3c6dc870b
124 files changed
+13522
-633
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import type { z } from "zod";
|
||||
import { recordServerDate } from "./server-clock";
|
||||
import { Problem, type ProblemCode, type ProblemFieldError } from "./schemas";
|
||||
|
||||
const apiPrefix = "/api/v1";
|
||||
@@ -166,6 +167,8 @@ export async function apiRequest<T>(
|
||||
});
|
||||
}
|
||||
|
||||
recordServerDate(response.headers.get("date"), Date.now());
|
||||
|
||||
if (!response.ok) {
|
||||
throw await toApiError(response);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import type {
|
||||
AssessmentQualifiedResult,
|
||||
AssessmentResult,
|
||||
AssessmentSessions,
|
||||
AssessmentSignalNotice,
|
||||
AssessmentSignalReceipt,
|
||||
AssessmentUncertainty,
|
||||
BasicScore,
|
||||
@@ -48,6 +49,10 @@ import type {
|
||||
|
||||
export const getGetMyAssessmentAvailabilityResponseMock = (overrideResponse: Partial<Extract<AssessmentAvailability, object>> = {}): AssessmentAvailability => ({specializations: Array.from({ length: faker.number.int({min: 1, max: 2}) }, (_, i) => i + 1).map(() => ({specialization: faker.helpers.arrayElement(['backend','frontend','mobile','network_engineer','devops_sre','data_analyst','ds_ml','information_security','qa'] as const), confirmed_grade: faker.helpers.arrayElement([faker.helpers.arrayElement(['intern','junior','middle','senior'] as const),null,]), active_attempt_id: faker.helpers.arrayElement([faker.string.uuid(), null]), grades: Array.from({ length: faker.number.int({min: 1, max: 10}) }, (_, i) => i + 1).map(() => ({grade: faker.helpers.arrayElement(['intern','junior','middle','senior'] as const), status: faker.helpers.arrayElement(['available','active_attempt','cooldown','insufficient_bank'] as const), mode: faker.helpers.arrayElement([faker.helpers.arrayElement(['demo_basic','adaptive'] as const),null,]), available_at: faker.helpers.arrayElement([faker.date.past().toISOString().slice(0, 19) + 'Z',null,]), time_limit_seconds: faker.helpers.arrayElement([faker.number.int({min: 1}), null]), max_sessions: faker.helpers.arrayElement([faker.number.int({min: 1, max: 10}), null]), max_items: faker.helpers.arrayElement([faker.number.int({min: 1, max: 100}), null]), practice_required: faker.helpers.arrayElement([faker.datatype.boolean(), null])}))})), ...overrideResponse})
|
||||
|
||||
export const getGetMyAssessmentSignalNoticeResponseMock = (overrideResponse: Partial<Extract<AssessmentSignalNotice, object>> = {}): AssessmentSignalNotice => ({notice_version: faker.number.int({min: 1, max: 2147483647}), acknowledged: faker.datatype.boolean(), acknowledged_at: faker.helpers.arrayElement([faker.date.past().toISOString().slice(0, 19) + 'Z',null,]), ...overrideResponse})
|
||||
|
||||
export const getAcknowledgeMyAssessmentSignalNoticeResponseMock = (overrideResponse: Partial<Extract<AssessmentSignalNotice, object>> = {}): AssessmentSignalNotice => ({notice_version: faker.number.int({min: 1, max: 2147483647}), acknowledged: faker.datatype.boolean(), acknowledged_at: faker.helpers.arrayElement([faker.date.past().toISOString().slice(0, 19) + 'Z',null,]), ...overrideResponse})
|
||||
|
||||
export const getCreateMyAssessmentAttemptResponseAssessmentSessionsMock = (overrideResponse: Partial<AssessmentSessions> = {}): AssessmentSessions => ({...{used: faker.number.int({min: 1, max: 10}), max: faker.number.int({min: 1, max: 10}), idle_timeout_seconds: faker.number.int({min: 60, max: 86400})}, ...overrideResponse});
|
||||
|
||||
export const getCreateMyAssessmentAttemptResponseChoiceItemContentMock = (overrideResponse: Partial<ChoiceItemContent> = {}): ChoiceItemContent => ({...{format: faker.helpers.arrayElement(['choice'] as const), options: Array.from({ length: faker.number.int({min: 2, max: 10}) }, (_, i) => i + 1).map(() => ({id: fakeFromPattern("^[A-Za-z0-9_-]+$", {minLength: 1, maxLength: 32}), text: faker.string.alpha({length: {min: 1, max: 2000}})})), multiple: faker.datatype.boolean()}, ...overrideResponse});
|
||||
@@ -215,6 +220,30 @@ export const getGetMyAssessmentAvailabilityMockHandler = (overrideResponse?: Ass
|
||||
}, options)
|
||||
}
|
||||
|
||||
export const getGetMyAssessmentSignalNoticeMockHandler = (overrideResponse?: AssessmentSignalNotice | ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => Promise<AssessmentSignalNotice> | AssessmentSignalNotice), options?: RequestHandlerOptions) => {
|
||||
return http.get('*/api/v1/me/assessment-signal-notice', async (info: Parameters<Parameters<typeof http.get>[1]>[0]) => {
|
||||
|
||||
|
||||
return HttpResponse.json(overrideResponse !== undefined
|
||||
? (typeof overrideResponse === "function" ? await overrideResponse(info) : overrideResponse)
|
||||
: getGetMyAssessmentSignalNoticeResponseMock(),
|
||||
{ status: 200
|
||||
})
|
||||
}, options)
|
||||
}
|
||||
|
||||
export const getAcknowledgeMyAssessmentSignalNoticeMockHandler = (overrideResponse?: AssessmentSignalNotice | ((info: Parameters<Parameters<typeof http.put>[1]>[0]) => Promise<AssessmentSignalNotice> | AssessmentSignalNotice), options?: RequestHandlerOptions) => {
|
||||
return http.put('*/api/v1/me/assessment-signal-notice', async (info: Parameters<Parameters<typeof http.put>[1]>[0]) => {
|
||||
|
||||
|
||||
return HttpResponse.json(overrideResponse !== undefined
|
||||
? (typeof overrideResponse === "function" ? await overrideResponse(info) : overrideResponse)
|
||||
: getAcknowledgeMyAssessmentSignalNoticeResponseMock(),
|
||||
{ status: 200
|
||||
})
|
||||
}, options)
|
||||
}
|
||||
|
||||
export const getCreateMyAssessmentAttemptMockHandler = (overrideResponse?: AssessmentAttempt | ((info: Parameters<Parameters<typeof http.post>[1]>[0]) => Promise<AssessmentAttempt> | AssessmentAttempt), options?: RequestHandlerOptions) => {
|
||||
return http.post('*/api/v1/me/assessment-attempts', async (info: Parameters<Parameters<typeof http.post>[1]>[0]) => {
|
||||
|
||||
@@ -300,6 +329,8 @@ export const getGetMyAssessmentResultMockHandler = (overrideResponse?: Assessmen
|
||||
}
|
||||
export const getAssessmentMock = () => [
|
||||
getGetMyAssessmentAvailabilityMockHandler(),
|
||||
getGetMyAssessmentSignalNoticeMockHandler(),
|
||||
getAcknowledgeMyAssessmentSignalNoticeMockHandler(),
|
||||
getCreateMyAssessmentAttemptMockHandler(),
|
||||
getGetMyAssessmentAttemptMockHandler(),
|
||||
getStartMyAssessmentAttemptSessionMockHandler(),
|
||||
|
||||
@@ -33,6 +33,8 @@ import type {
|
||||
AssessmentFinalizeConflictProblem,
|
||||
AssessmentResult,
|
||||
AssessmentSignalBatch,
|
||||
AssessmentSignalNotice,
|
||||
AssessmentSignalNoticeAcknowledgement,
|
||||
AssessmentSignalReceipt,
|
||||
CreateMyAssessmentAttemptHeaders,
|
||||
FinalizeMyAssessmentAttemptHeaders,
|
||||
@@ -170,7 +172,206 @@ export function useGetMyAssessmentAvailability<TData = Awaited<ReturnType<typeof
|
||||
|
||||
|
||||
|
||||
export const getCreateMyAssessmentAttemptUrl = () => {
|
||||
export const getGetMyAssessmentSignalNoticeUrl = () => {
|
||||
|
||||
|
||||
|
||||
|
||||
return `/api/v1/me/assessment-signal-notice`
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires the session cookie of a candidate account with a confirmed email; the candidate comes from the session. Returns the notice version that the server requires now and whether this candidate acknowledged it. The notice lists the signals that are collected during a real assessment attempt and states that images, sound, and clipboard contents are not collected. Client signals are the time away from the tab or window, copy, paste and cut with a size only, and exits from fullscreen mode. Server signals are the response time of each item measured by the server, a change of network address during the attempt, parallel sessions, and the comparison of answers to variants of the same task by candidates. The server stores for these only one-way keyed digests: it stores no network address, no session token, and no answer text. Client signals are stored only while the C3 consent is current. The client shows it before a real attempt starts and does not start the attempt until the notice is acknowledged.
|
||||
*
|
||||
* The acknowledgement is stored on the server per account and notice version, so it survives a reload and a new browser. It is not a consent and never changes C3: the signal operation still requires a current C3 consent, and an unacknowledged notice does not make that operation fail. The demo_express training mode collects no signals and needs no acknowledgement.
|
||||
*
|
||||
* A missing, unknown, expired, or revoked session answers 401 unauthenticated; an employer account or an unconfirmed email answers 403 forbidden.
|
||||
* @summary Read whether the current candidate acknowledged the signal notice.
|
||||
*/
|
||||
export const getMyAssessmentSignalNotice = async ( options?: Parameters<typeof apiRequest>[1]): Promise<AssessmentSignalNotice> => {
|
||||
|
||||
return apiRequest<AssessmentSignalNotice>(getGetMyAssessmentSignalNoticeUrl(),
|
||||
{
|
||||
...options,
|
||||
method: 'GET'
|
||||
|
||||
|
||||
}
|
||||
);}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export const getGetMyAssessmentSignalNoticeQueryKey = () => {
|
||||
return [
|
||||
`/api/v1/me/assessment-signal-notice`
|
||||
] as const;
|
||||
}
|
||||
|
||||
|
||||
export const getGetMyAssessmentSignalNoticeQueryOptions = <TData = Awaited<ReturnType<typeof getMyAssessmentSignalNotice>>, TError = ErrorType<Problem>>( options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getMyAssessmentSignalNotice>>, TError, TData>>, request?: SecondParameter<typeof apiRequest>}
|
||||
) => {
|
||||
|
||||
const {query: queryOptions, request: requestOptions} = options ?? {};
|
||||
|
||||
const queryKey = queryOptions?.queryKey ?? getGetMyAssessmentSignalNoticeQueryKey();
|
||||
|
||||
|
||||
|
||||
const queryFn: QueryFunction<Awaited<ReturnType<typeof getMyAssessmentSignalNotice>>> = ({ signal }) => getMyAssessmentSignalNotice({ signal, ...requestOptions });
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getMyAssessmentSignalNotice>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
|
||||
}
|
||||
|
||||
export type GetMyAssessmentSignalNoticeQueryResult = NonNullable<Awaited<ReturnType<typeof getMyAssessmentSignalNotice>>>
|
||||
export type GetMyAssessmentSignalNoticeQueryError = ErrorType<Problem>
|
||||
|
||||
|
||||
export function useGetMyAssessmentSignalNotice<TData = Awaited<ReturnType<typeof getMyAssessmentSignalNotice>>, TError = ErrorType<Problem>>(
|
||||
options: { query:Partial<UseQueryOptions<Awaited<ReturnType<typeof getMyAssessmentSignalNotice>>, TError, TData>> & Pick<
|
||||
DefinedInitialDataOptions<
|
||||
Awaited<ReturnType<typeof getMyAssessmentSignalNotice>>,
|
||||
TError,
|
||||
Awaited<ReturnType<typeof getMyAssessmentSignalNotice>>
|
||||
> , 'initialData'
|
||||
>, request?: SecondParameter<typeof apiRequest>}
|
||||
, queryClient?: QueryClient
|
||||
): DefinedUseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
|
||||
export function useGetMyAssessmentSignalNotice<TData = Awaited<ReturnType<typeof getMyAssessmentSignalNotice>>, TError = ErrorType<Problem>>(
|
||||
options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getMyAssessmentSignalNotice>>, TError, TData>> & Pick<
|
||||
UndefinedInitialDataOptions<
|
||||
Awaited<ReturnType<typeof getMyAssessmentSignalNotice>>,
|
||||
TError,
|
||||
Awaited<ReturnType<typeof getMyAssessmentSignalNotice>>
|
||||
> , 'initialData'
|
||||
>, request?: SecondParameter<typeof apiRequest>}
|
||||
, queryClient?: QueryClient
|
||||
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
|
||||
export function useGetMyAssessmentSignalNotice<TData = Awaited<ReturnType<typeof getMyAssessmentSignalNotice>>, TError = ErrorType<Problem>>(
|
||||
options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getMyAssessmentSignalNotice>>, TError, TData>>, request?: SecondParameter<typeof apiRequest>}
|
||||
, queryClient?: QueryClient
|
||||
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
|
||||
/**
|
||||
* @summary Read whether the current candidate acknowledged the signal notice.
|
||||
*/
|
||||
|
||||
export function useGetMyAssessmentSignalNotice<TData = Awaited<ReturnType<typeof getMyAssessmentSignalNotice>>, TError = ErrorType<Problem>>(
|
||||
options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getMyAssessmentSignalNotice>>, TError, TData>>, request?: SecondParameter<typeof apiRequest>}
|
||||
, queryClient?: QueryClient
|
||||
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
|
||||
|
||||
const queryOptions = getGetMyAssessmentSignalNoticeQueryOptions(options)
|
||||
|
||||
const query = useQuery(queryOptions, queryClient) as UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
|
||||
|
||||
return withQueryKey(query, queryOptions.queryKey);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export const getAcknowledgeMyAssessmentSignalNoticeUrl = () => {
|
||||
|
||||
|
||||
|
||||
|
||||
return `/api/v1/me/assessment-signal-notice`
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires the session cookie of a candidate account with a confirmed email, the CSRF token of that session in X-CSRF-Token, and an allowed Origin. The body carries the notice version the candidate was shown. The server stores the acknowledgement for the account and that version; the response carries the server time of the first acknowledgement.
|
||||
*
|
||||
* The operation needs no Idempotency-Key: it is idempotent. Repeating it for an acknowledged version changes nothing, keeps the first time, and answers 200, so a retry after a lost response succeeds. A version other than the one the server requires answers 409 state_conflict and stores nothing; the client reads the notice again.
|
||||
*
|
||||
* The acknowledgement is not a consent. It does not grant, replace, or hide C3, and it does not affect the signal operation or any score, category, or quota. The body carries no signal, answer, or clipboard data.
|
||||
*
|
||||
* Order of checks: session (401), CSRF and Origin (403 csrf_check_failed), request validation (400), account (403 forbidden), then the version (409).
|
||||
* @summary Record that the current candidate read the signal notice.
|
||||
*/
|
||||
export const acknowledgeMyAssessmentSignalNotice = async (assessmentSignalNoticeAcknowledgement: AssessmentSignalNoticeAcknowledgement, options?: Parameters<typeof apiRequest>[1]): Promise<AssessmentSignalNotice> => {
|
||||
|
||||
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<AssessmentSignalNotice>(getAcknowledgeMyAssessmentSignalNoticeUrl(),
|
||||
{
|
||||
...options,
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json', ...getHeaders(options?.headers) },
|
||||
body: JSON.stringify(assessmentSignalNoticeAcknowledgement)
|
||||
}
|
||||
);}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export const getAcknowledgeMyAssessmentSignalNoticeMutationKey = () => ['acknowledgeMyAssessmentSignalNotice'] as const;
|
||||
|
||||
export const getAcknowledgeMyAssessmentSignalNoticeMutationOptions = <TError = ErrorType<Problem>,
|
||||
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof acknowledgeMyAssessmentSignalNotice>>, TError,AcknowledgeMyAssessmentSignalNoticeMutationVariables, TContext>, request?: SecondParameter<typeof apiRequest>}
|
||||
): UseMutationOptions<Awaited<ReturnType<typeof acknowledgeMyAssessmentSignalNotice>>, TError,AcknowledgeMyAssessmentSignalNoticeMutationVariables, TContext> => {
|
||||
|
||||
const mutationKey = getAcknowledgeMyAssessmentSignalNoticeMutationKey();
|
||||
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 acknowledgeMyAssessmentSignalNotice>>, AcknowledgeMyAssessmentSignalNoticeMutationVariables> = (props) => {
|
||||
const {data} = props ?? {};
|
||||
|
||||
return acknowledgeMyAssessmentSignalNotice(data,requestOptions)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { mutationFn, ...mutationOptions }}
|
||||
|
||||
export type AcknowledgeMyAssessmentSignalNoticeMutationResult = NonNullable<Awaited<ReturnType<typeof acknowledgeMyAssessmentSignalNotice>>>
|
||||
export type AcknowledgeMyAssessmentSignalNoticeMutationBody = AssessmentSignalNoticeAcknowledgement
|
||||
export type AcknowledgeMyAssessmentSignalNoticeMutationError = ErrorType<Problem>
|
||||
export type AcknowledgeMyAssessmentSignalNoticeMutationVariables = {data: AssessmentSignalNoticeAcknowledgement}
|
||||
|
||||
/**
|
||||
* @summary Record that the current candidate read the signal notice.
|
||||
*/
|
||||
export const useAcknowledgeMyAssessmentSignalNotice = <TError = ErrorType<Problem>,
|
||||
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof acknowledgeMyAssessmentSignalNotice>>, TError,AcknowledgeMyAssessmentSignalNoticeMutationVariables, TContext>, request?: SecondParameter<typeof apiRequest>}
|
||||
, queryClient?: QueryClient): UseMutationResult<
|
||||
Awaited<ReturnType<typeof acknowledgeMyAssessmentSignalNotice>>,
|
||||
TError,
|
||||
AcknowledgeMyAssessmentSignalNoticeMutationVariables,
|
||||
TContext
|
||||
> => {
|
||||
return useMutation(getAcknowledgeMyAssessmentSignalNoticeMutationOptions(options), queryClient);
|
||||
}
|
||||
export const getCreateMyAssessmentAttemptUrl = () => {
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -6,3 +6,4 @@ export {
|
||||
unknownErrorCode,
|
||||
type ApiErrorCode,
|
||||
} from "./client";
|
||||
export { serverClockOffsetMs, toServerTime } from "./server-clock";
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Generated by orval 🍺
|
||||
* Do not edit manually.
|
||||
* Lincodex API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
import * as zod from 'zod';
|
||||
|
||||
export const acknowledgeMyAssessmentSignalNoticeBodyNoticeVersionMax = 2147483647;
|
||||
|
||||
|
||||
export const AcknowledgeMyAssessmentSignalNoticeBody = zod.object({
|
||||
"notice_version": zod.int().min(1).max(acknowledgeMyAssessmentSignalNoticeBodyNoticeVersionMax).describe('Version of the notice text about the collected signals. The client shows the text of the version it knows and sends that version back when the candidate confirms; a changed text gets a new version and needs a new confirmation.')
|
||||
}).describe('The notice version the candidate was shown and acknowledged.')
|
||||
|
||||
export type AcknowledgeMyAssessmentSignalNoticeBody = zod.input<typeof AcknowledgeMyAssessmentSignalNoticeBody>;
|
||||
export type AcknowledgeMyAssessmentSignalNoticeBodyOutput = zod.output<typeof AcknowledgeMyAssessmentSignalNoticeBody>;
|
||||
@@ -14,7 +14,7 @@ export const AssessmentClipboardSignal = zod.object({
|
||||
"kind": zod.enum(['copy', 'paste', 'cut']),
|
||||
"item_instance_id": zod.uuid().describe('Identifier of an item instance in one attempt. It identifies the fixed variant served to this candidate and reveals neither the task family, its version, nor the variant seed.'),
|
||||
"occurred_at": zod.iso.datetime({"offset":true}).describe('UTC instant in RFC 3339 format with the Z suffix, for example 2026-10-05T09:30:00Z. Servers always emit UTC. Every date-time field in this contract uses this schema.'),
|
||||
"size_bytes": zod.int().min(assessmentClipboardSignalSizeBytesMin).max(assessmentClipboardSignalSizeBytesMax).describe('Byte count only. Clipboard or selection contents are not transmitted or retained.')
|
||||
"size_bytes": zod.int().min(assessmentClipboardSignalSizeBytesMin).max(assessmentClipboardSignalSizeBytesMax).describe('Size only; clipboard and selection contents are never transmitted or retained. For `paste` it is the UTF-8 byte count of the pasted plain text plus the byte size of pasted files, counted on the device from the paste event. For `copy` and `cut` it is the selection length in UTF-16 code units taken from the selection offsets of a form field, or zero when the field offsets are unavailable; it is an approximate size and the selected text is not read. The server applies no conversion and treats the value as an order-of-magnitude indicator.')
|
||||
})
|
||||
|
||||
export type AssessmentClipboardSignal = zod.input<typeof AssessmentClipboardSignal>;
|
||||
|
||||
@@ -24,7 +24,7 @@ export const AssessmentSignalBatch = zod.object({
|
||||
"kind": zod.enum(['copy', 'paste', 'cut']),
|
||||
"item_instance_id": zod.uuid().describe('Identifier of an item instance in one attempt. It identifies the fixed variant served to this candidate and reveals neither the task family, its version, nor the variant seed.'),
|
||||
"occurred_at": zod.iso.datetime({"offset":true}).describe('UTC instant in RFC 3339 format with the Z suffix, for example 2026-10-05T09:30:00Z. Servers always emit UTC. Every date-time field in this contract uses this schema.'),
|
||||
"size_bytes": zod.int().min(assessmentSignalBatchEventsItemTwoSizeBytesMin).max(assessmentSignalBatchEventsItemTwoSizeBytesMax).describe('Byte count only. Clipboard or selection contents are not transmitted or retained.')
|
||||
"size_bytes": zod.int().min(assessmentSignalBatchEventsItemTwoSizeBytesMin).max(assessmentSignalBatchEventsItemTwoSizeBytesMax).describe('Size only; clipboard and selection contents are never transmitted or retained. For `paste` it is the UTF-8 byte count of the pasted plain text plus the byte size of pasted files, counted on the device from the paste event. For `copy` and `cut` it is the selection length in UTF-16 code units taken from the selection offsets of a form field, or zero when the field offsets are unavailable; it is an approximate size and the selected text is not read. The server applies no conversion and treats the value as an order-of-magnitude indicator.')
|
||||
}),zod.object({
|
||||
"kind": zod.enum(['fullscreen_exit']),
|
||||
"item_instance_id": zod.uuid().describe('Identifier of an item instance in one attempt. It identifies the fixed variant served to this candidate and reveals neither the task family, its version, nor the variant seed.'),
|
||||
|
||||
@@ -21,7 +21,7 @@ export const AssessmentSignalEvent = zod.union([zod.object({
|
||||
"kind": zod.enum(['copy', 'paste', 'cut']),
|
||||
"item_instance_id": zod.uuid().describe('Identifier of an item instance in one attempt. It identifies the fixed variant served to this candidate and reveals neither the task family, its version, nor the variant seed.'),
|
||||
"occurred_at": zod.iso.datetime({"offset":true}).describe('UTC instant in RFC 3339 format with the Z suffix, for example 2026-10-05T09:30:00Z. Servers always emit UTC. Every date-time field in this contract uses this schema.'),
|
||||
"size_bytes": zod.int().min(assessmentSignalEventTwoSizeBytesMin).max(assessmentSignalEventTwoSizeBytesMax).describe('Byte count only. Clipboard or selection contents are not transmitted or retained.')
|
||||
"size_bytes": zod.int().min(assessmentSignalEventTwoSizeBytesMin).max(assessmentSignalEventTwoSizeBytesMax).describe('Size only; clipboard and selection contents are never transmitted or retained. For `paste` it is the UTF-8 byte count of the pasted plain text plus the byte size of pasted files, counted on the device from the paste event. For `copy` and `cut` it is the selection length in UTF-16 code units taken from the selection offsets of a form field, or zero when the field offsets are unavailable; it is an approximate size and the selected text is not read. The server applies no conversion and treats the value as an order-of-magnitude indicator.')
|
||||
}),zod.object({
|
||||
"kind": zod.enum(['fullscreen_exit']),
|
||||
"item_instance_id": zod.uuid().describe('Identifier of an item instance in one attempt. It identifies the fixed variant served to this candidate and reveals neither the task family, its version, nor the variant seed.'),
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Generated by orval 🍺
|
||||
* Do not edit manually.
|
||||
* Lincodex API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
import * as zod from 'zod';
|
||||
|
||||
export const assessmentSignalNoticeNoticeVersionOneMax = 2147483647;
|
||||
|
||||
|
||||
export const AssessmentSignalNotice = zod.object({
|
||||
"notice_version": zod.int().min(1).max(assessmentSignalNoticeNoticeVersionOneMax).describe('Version of the notice text about the collected signals. The client shows the text of the version it knows and sends that version back when the candidate confirms; a changed text gets a new version and needs a new confirmation.').describe('The version the server currently requires the candidate to acknowledge.'),
|
||||
"acknowledged": zod.boolean().describe('True when the candidate acknowledged `notice_version`.'),
|
||||
"acknowledged_at": zod.union([zod.iso.datetime({"offset":true}).describe('UTC instant in RFC 3339 format with the Z suffix, for example 2026-10-05T09:30:00Z. Servers always emit UTC. Every date-time field in this contract uses this schema.'),zod.null()]).describe('Server time of the first acknowledgement of this version, or null.')
|
||||
}).describe('State of the notice about the signals that are collected during a real assessment attempt. The acknowledgement is a record that the candidate was informed. It is not a consent, grants no purpose, and neither enables nor blocks signal storage; C3 remains the only consent that the signal operation checks.')
|
||||
|
||||
export type AssessmentSignalNotice = zod.input<typeof AssessmentSignalNotice>;
|
||||
export type AssessmentSignalNoticeOutput = zod.output<typeof AssessmentSignalNotice>;
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Generated by orval 🍺
|
||||
* Do not edit manually.
|
||||
* Lincodex API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
import * as zod from 'zod';
|
||||
|
||||
export const assessmentSignalNoticeAcknowledgementNoticeVersionMax = 2147483647;
|
||||
|
||||
|
||||
export const AssessmentSignalNoticeAcknowledgement = zod.object({
|
||||
"notice_version": zod.int().min(1).max(assessmentSignalNoticeAcknowledgementNoticeVersionMax).describe('Version of the notice text about the collected signals. The client shows the text of the version it knows and sends that version back when the candidate confirms; a changed text gets a new version and needs a new confirmation.')
|
||||
}).describe('The notice version the candidate was shown and acknowledged.')
|
||||
|
||||
export type AssessmentSignalNoticeAcknowledgement = zod.input<typeof AssessmentSignalNoticeAcknowledgement>;
|
||||
export type AssessmentSignalNoticeAcknowledgementOutput = zod.output<typeof AssessmentSignalNoticeAcknowledgement>;
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Generated by orval 🍺
|
||||
* Do not edit manually.
|
||||
* Lincodex API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
import * as zod from 'zod';
|
||||
|
||||
export const AssessmentSignalNoticeVersionMax = 2147483647;
|
||||
|
||||
|
||||
export const AssessmentSignalNoticeVersion = zod.int().min(1).max(AssessmentSignalNoticeVersionMax).describe('Version of the notice text about the collected signals. The client shows the text of the version it knows and sends that version back when the candidate confirms; a changed text gets a new version and needs a new confirmation.')
|
||||
|
||||
export type AssessmentSignalNoticeVersion = zod.input<typeof AssessmentSignalNoticeVersion>;
|
||||
export type AssessmentSignalNoticeVersionOutput = zod.output<typeof AssessmentSignalNoticeVersion>;
|
||||
@@ -5,6 +5,7 @@
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export * from './acknowledgeMyAssessmentSignalNoticeBody.zod';
|
||||
export * from './assessmentAnswer.zod';
|
||||
export * from './assessmentAnswerSubmission.zod';
|
||||
export * from './assessmentAttempt.zod';
|
||||
@@ -53,6 +54,9 @@ export * from './assessmentResult.zod';
|
||||
export * from './assessmentSessions.zod';
|
||||
export * from './assessmentSignalBatch.zod';
|
||||
export * from './assessmentSignalEvent.zod';
|
||||
export * from './assessmentSignalNotice.zod';
|
||||
export * from './assessmentSignalNoticeAcknowledgement.zod';
|
||||
export * from './assessmentSignalNoticeVersion.zod';
|
||||
export * from './assessmentSignalReceipt.zod';
|
||||
export * from './assessmentSpecializationAvailability.zod';
|
||||
export * from './assessmentStrength.zod';
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ export const RecordMyAssessmentAttemptSignalsBody = zod.object({
|
||||
"kind": zod.enum(['copy', 'paste', 'cut']),
|
||||
"item_instance_id": zod.uuid().describe('Identifier of an item instance in one attempt. It identifies the fixed variant served to this candidate and reveals neither the task family, its version, nor the variant seed.'),
|
||||
"occurred_at": zod.iso.datetime({"offset":true}).describe('UTC instant in RFC 3339 format with the Z suffix, for example 2026-10-05T09:30:00Z. Servers always emit UTC. Every date-time field in this contract uses this schema.'),
|
||||
"size_bytes": zod.int().min(recordMyAssessmentAttemptSignalsBodyEventsItemTwoSizeBytesMin).max(recordMyAssessmentAttemptSignalsBodyEventsItemTwoSizeBytesMax).describe('Byte count only. Clipboard or selection contents are not transmitted or retained.')
|
||||
"size_bytes": zod.int().min(recordMyAssessmentAttemptSignalsBodyEventsItemTwoSizeBytesMin).max(recordMyAssessmentAttemptSignalsBodyEventsItemTwoSizeBytesMax).describe('Size only; clipboard and selection contents are never transmitted or retained. For `paste` it is the UTF-8 byte count of the pasted plain text plus the byte size of pasted files, counted on the device from the paste event. For `copy` and `cut` it is the selection length in UTF-16 code units taken from the selection offsets of a form field, or zero when the field offsets are unavailable; it is an approximate size and the selected text is not read. The server applies no conversion and treats the value as an order-of-magnitude indicator.')
|
||||
}),zod.object({
|
||||
"kind": zod.enum(['fullscreen_exit']),
|
||||
"item_instance_id": zod.uuid().describe('Identifier of an item instance in one attempt. It identifies the fixed variant served to this candidate and reveals neither the task family, its version, nor the variant seed.'),
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import {
|
||||
recordServerDate,
|
||||
resetServerClock,
|
||||
serverClockOffsetMs,
|
||||
toServerTime,
|
||||
} from "./server-clock";
|
||||
|
||||
afterEach(resetServerClock);
|
||||
|
||||
describe("server clock", () => {
|
||||
it("has no offset before any response", () => {
|
||||
expect(serverClockOffsetMs()).toBe(0);
|
||||
expect(toServerTime(1_000)).toBe(1_000);
|
||||
});
|
||||
|
||||
it("learns the offset of a device clock that runs an hour ahead", () => {
|
||||
const serverNow = Date.UTC(2026, 9, 8, 12, 0, 0);
|
||||
recordServerDate(new Date(serverNow).toUTCString(), serverNow + 3_600_000);
|
||||
expect(serverClockOffsetMs()).toBe(-3_600_000);
|
||||
expect(toServerTime(serverNow + 3_600_000 + 5_000)).toBe(serverNow + 5_000);
|
||||
});
|
||||
|
||||
it("learns the offset of a device clock that runs behind", () => {
|
||||
const serverNow = Date.UTC(2026, 9, 8, 12, 0, 0);
|
||||
recordServerDate(new Date(serverNow).toUTCString(), serverNow - 600_000);
|
||||
expect(toServerTime(serverNow - 600_000)).toBe(serverNow);
|
||||
});
|
||||
|
||||
it("ignores a missing or malformed header", () => {
|
||||
recordServerDate(null, 1_000);
|
||||
recordServerDate("not a date", 1_000);
|
||||
recordServerDate("", 1_000);
|
||||
expect(serverClockOffsetMs()).toBe(0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Offset between the device clock and the server clock, learned from the Date
|
||||
* header of API responses. A device clock that is minutes off would otherwise
|
||||
* make the server reject event timestamps; applying the offset keeps client
|
||||
* metadata inside the window the server accepts.
|
||||
*
|
||||
* The Date header has one-second resolution, which is far below the minutes of
|
||||
* tolerance the server allows, so no round-trip correction is attempted.
|
||||
*/
|
||||
let offsetMs = 0;
|
||||
|
||||
/** Records the offset from a Date header value; an invalid value changes nothing. */
|
||||
export function recordServerDate(header: string | null, deviceNowMs: number): void {
|
||||
if (!header) return;
|
||||
const serverMs = Date.parse(header);
|
||||
if (!Number.isFinite(serverMs) || !Number.isFinite(deviceNowMs)) return;
|
||||
offsetMs = serverMs - deviceNowMs;
|
||||
}
|
||||
|
||||
/** Server time estimated from a device timestamp in milliseconds. */
|
||||
export function toServerTime(deviceMs: number): number {
|
||||
return deviceMs + offsetMs;
|
||||
}
|
||||
|
||||
/** Current offset in milliseconds; 0 until a response with a Date header arrived. */
|
||||
export function serverClockOffsetMs(): number {
|
||||
return offsetMs;
|
||||
}
|
||||
|
||||
/** Resets the learned offset; used by tests. */
|
||||
export function resetServerClock(): void {
|
||||
offsetMs = 0;
|
||||
}
|
||||
Reference in new issue
Block a user