UNPKG

@tantainnovative/ndpr-toolkit

Version:

Nigeria Data Protection Toolkit — enterprise-grade compliance components for the Nigeria Data Protection Act (NDPA) 2023

159 lines (151 loc) 5.64 kB
import React__default from 'react'; /** * Represents the data submitted by the DSR request form. */ declare interface DSRFormSubmission { /** The selected request type identifier */ requestType: string; /** Data subject personal information */ dataSubject: { fullName: string; email: string; phone?: string; identifierType: string; identifierValue: string; }; /** Additional information provided for the selected request type */ additionalInfo?: Record<string, string | number | boolean | null>; /** Timestamp (ms) when the form was submitted */ submittedAt: number; } declare interface DSRRequestFormClassNames { root?: string; title?: string; description?: string; form?: string; fieldGroup?: string; label?: string; input?: string; select?: string; textarea?: string; submitButton?: string; /** Alias for submitButton */ primaryButton?: string; successMessage?: string; /** Custom class applied when isSubmitting is true (e.g. a loading overlay) */ loadingOverlay?: string; } export declare const NDPRSubjectRights: React__default.FC<NDPRSubjectRightsProps>; export declare interface NDPRSubjectRightsProps { requestTypes?: RequestType[]; adapter?: StorageAdapter<DSRFormSubmission>; classNames?: DSRRequestFormClassNames; unstyled?: boolean; onSubmit?: (data: DSRFormSubmission) => void; /** * Public-form mode. Use when the form should submit to your existing * backend workflow instead of being state-managed by an adapter. * * When `submitTo` is set: * - the form does NOT require an `adapter` * - on submit, the toolkit POSTs the JSON-serialised `DSRFormSubmission` * to this URL (with `Content-Type: application/json`) * - your `onSubmit` callback still fires (after the POST resolves) * - submit failures are surfaced via `onSubmitError` * * For more control over headers, credentials, or retry behaviour, build * an `apiAdapter` (which now supports CSRF, retry, and error hooks in * 3.6.0) and pass that as `adapter` instead. `submitTo` is the * fire-and-forget shortcut for public forms. * * @example * <NDPRSubjectRights submitTo="/api/dsr" /> */ submitTo?: string; /** * Fetch options for the `submitTo` POST. Useful for adding `credentials` * (cookies/auth), `X-CSRF-Token`, or any other header your backend * requires. Ignored unless `submitTo` is set. * * @default { credentials: 'same-origin' } */ submitOptions?: { headers?: Record<string, string> | (() => Record<string, string>); credentials?: RequestCredentials; }; /** * Called when a `submitTo` POST fails (network error or non-2xx * response). Receives the underlying error or Response. */ onSubmitError?: (ctx: { error?: unknown; response?: Response; }) => void; /** * Called when a `submitTo` POST succeeds (2xx response). Receives the * `Response` object, the submitted `DSRFormSubmission` payload, and the * parsed JSON body if the server returned valid JSON. Use this to * display a server-generated reference number, redirect the user, or * trigger analytics. * * The `body` field is `undefined` if the response had no body or the * body was not valid JSON. It is typed `unknown` to force consumers to * narrow it themselves before reading fields. * * @example * <NDPRSubjectRights * submitTo="/api/dsr" * onSubmitSuccess={({ response, data, body }) => { * const ref = (body as { referenceId?: string })?.referenceId; * if (ref) router.push(`/dsr-confirmation?ref=${ref}`); * }} * /> */ onSubmitSuccess?: (ctx: { response: Response; data: DSRFormSubmission; body?: unknown; }) => void; } /** * Represents a type of data subject request (detailed configuration) */ declare interface RequestType { /** Unique identifier for the request type */ id: string; /** Display name for the request type */ name: string; /** Description of what this request type entails */ description: string; /** * NDPA 2023 section reference for this right * (e.g., "Section 34(1)(a)" for access, "Section 38" for portability). * Used for display purposes only — verify the exact subsection with counsel. */ ndpaSection?: string; /** * Estimated time to fulfill this type of request (in days) * NDPA requires response within 30 days */ estimatedCompletionTime: number; /** Whether additional information is required for this request type */ requiresAdditionalInfo: boolean; /** Custom fields required for this request type */ additionalFields?: Array<{ id: string; label: string; type: 'text' | 'textarea' | 'select' | 'checkbox' | 'file'; options?: string[]; required: boolean; placeholder?: string; }>; } declare interface StorageAdapter<T = unknown> { /** Load persisted data. Called once on hook mount. */ load(): T | null | Promise<T | null>; /** Persist data. Called on every state change. */ save(data: T): void | Promise<void>; /** Clear persisted data. Called on reset. */ remove(): void | Promise<void>; } export { }