← All @molecule/* packages · App templates
@molecule/api-complianceCore interface · compliance · API (Node) · v1.0.1 · Apache-2.0
GDPR and data compliance core interface for molecule.dev — user data export, deletion, consent management, and processing logs
npm install @molecule/api-compliance@molecule/api-compliance is the compliance core interface on the API (Node) side: the API your app calls, with no vendor inside.
Choose the implementation by bonding one of its 1 provider: @molecule/api-compliance-gdpr.
import {
setProvider,
exportUserData,
deleteUserData,
getConsent,
setConsent,
} from '@molecule/api-compliance'
import { provider } from '@molecule/api-compliance-gdpr'
// Wire the provider at startup
setProvider(provider)
// Export user data for a data portability request
const exportData = await exportUserData('user-123', 'json')
// Handle a deletion request (right to erasure)
const result = await deleteUserData('user-123', { retainLegalObligations: true })
// Manage user consent
await setConsent('user-123', { purpose: 'marketing', granted: false })
const consent = await getConsent('user-123')Providers (1): @molecule/api-compliance-gdpr
Works with: @molecule/api-bond, @molecule/api-i18n
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Compliance core interface for molecule.dev.
Provides the ComplianceProvider interface for GDPR and data compliance
operations including user data export, deletion, consent management,
and data processing logs. Bond a concrete provider
(e.g. @molecule/api-compliance-gdpr) at startup via setProvider().
import {
setProvider,
exportUserData,
deleteUserData,
getConsent,
setConsent,
} from '@molecule/api-compliance'
import { provider } from '@molecule/api-compliance-gdpr'
// Wire the provider at startup
setProvider(provider)
// Export user data for a data portability request
const exportData = await exportUserData('user-123', 'json')
// Handle a deletion request (right to erasure)
const result = await deleteUserData('user-123', { retainLegalObligations: true })
// Manage user consent
await setConsent('user-123', { purpose: 'marketing', granted: false })
const consent = await getConsent('user-123')
core
npm install @molecule/api-compliance @molecule/api-bond @molecule/api-i18n
ComplianceConfigConfiguration options for a compliance provider.
interface ComplianceConfig {
/** Data retention period in days. */
retentionDays?: number
/** Whether to automatically purge expired data. */
autoPurge?: boolean
/** Data categories managed by this provider. */
categories?: DataCategory[]
}
ComplianceProviderCompliance provider interface.
All compliance providers must implement this interface to provide data export, deletion, consent management, and processing log capabilities required by data protection regulations.
interface ComplianceProvider {
/**
* Exports all data associated with a user in a portable format.
*
* @param userId - The identifier of the user whose data to export.
* @param format - The export format (defaults to 'json').
* @returns The exported user data package.
*/
exportUserData(userId: string, format?: ExportFormat): Promise<UserDataExport>
/**
* Deletes user data according to the specified options. May retain
* certain categories if required by legal obligations.
*
* @param userId - The identifier of the user whose data to delete.
* @param options - Optional deletion parameters.
* @returns The result of the deletion request.
*/
deleteUserData(userId: string, options?: DeletionOptions): Promise<DeletionResult>
/**
* Retrieves the current consent record for a user.
*
* @param userId - The identifier of the user.
* @returns The user's consent record.
*/
getConsent(userId: string): Promise<ConsentRecord>
/**
* Updates consent for a specific data processing purpose.
*
* @param userId - The identifier of the user.
* @param consent - The consent update to apply.
*/
setConsent(userId: string, consent: ConsentUpdate): Promise<void>
/**
* Retrieves the data processing log for a user, showing all
* recorded processing activities on their data.
*
* @param userId - The identifier of the user.
* @returns Array of processing log entries.
*/
getDataProcessingLog(userId: string): Promise<ProcessingLogEntry[]>
}
ConsentEntryA single consent entry for a specific data processing purpose.
interface ConsentEntry {
/** The purpose or category of data processing. */
purpose: string
/** Whether consent has been granted. */
granted: boolean
/** When consent was last updated. */
updatedAt: Date
/** Legal basis for processing. */
legalBasis?: LegalBasis
}
ConsentRecordFull consent record for a user.
interface ConsentRecord {
/** The user this consent record belongs to. */
userId: string
/** Individual consent entries by purpose. */
consents: ConsentEntry[]
/** When the consent record was last modified. */
updatedAt: Date
}
ConsentUpdateUpdate payload for modifying user consent.
interface ConsentUpdate {
/** The purpose or category of data processing. */
purpose: string
/** Whether consent is being granted or revoked. */
granted: boolean
/** Legal basis for processing. */
legalBasis?: LegalBasis
}
DeletionOptionsOptions for user data deletion requests.
interface DeletionOptions {
/** Specific data categories to delete (defaults to all). */
categories?: DataCategory[]
/** Whether to retain data required by legal obligations. */
retainLegalObligations?: boolean
/** Reason for the deletion request. */
reason?: string
}
DeletionResultResult of a data deletion request.
interface DeletionResult {
/** The user whose data was deleted. */
userId: string
/** Current status of the deletion. */
status: DeletionStatus
/** Categories that were deleted. */
deletedCategories: DataCategory[]
/** Categories that were retained (e.g., for legal reasons). */
retainedCategories: DataCategory[]
/** Timestamp when the deletion was requested. */
requestedAt: Date
/** Timestamp when the deletion was completed (if applicable). */
completedAt?: Date
}
ProcessingLogEntryA log entry recording a data processing activity.
interface ProcessingLogEntry {
/** Unique identifier for the log entry. */
id: string
/** The user whose data was processed. */
userId: string
/** Description of the processing activity. */
activity: string
/** Data category that was processed. */
category: DataCategory
/** Legal basis for the processing. */
legalBasis: LegalBasis
/** Who or what performed the processing. */
processor: string
/** When the processing occurred. */
timestamp: Date
/** Additional details about the processing. */
details?: Record<string, unknown>
}
UserDataExportExported user data package.
interface UserDataExport {
/** The user whose data was exported. */
userId: string
/** Timestamp when the export was generated. */
exportedAt: Date
/** Format of the exported data. */
format: ExportFormat
/** Exported data organized by category. */
data: Record<string, unknown>
/** Categories included in the export. */
categories: DataCategory[]
}
DataCategoryCategories of user data that can be managed for compliance purposes.
type DataCategory =
| 'profile'
| 'activity'
| 'preferences'
| 'communications'
| 'billing'
| 'analytics'
| 'content'
| 'authentication'
DeletionStatusStatus of a data deletion request.
type DeletionStatus = 'pending' | 'in_progress' | 'completed' | 'failed' | 'partial'
ExportFormatSupported data export formats.
type ExportFormat = 'json' | 'csv'
LegalBasisLegal bases for data processing under regulations like GDPR.
type LegalBasis =
| 'consent'
| 'contract'
| 'legal_obligation'
| 'vital_interests'
| 'public_task'
| 'legitimate_interests'
deleteUserData(userId, options)Deletes user data using the bonded provider.
function deleteUserData(userId: string, options?: DeletionOptions): Promise<DeletionResult>
userId — The identifier of the user whose data to delete.options — Optional deletion parameters.Returns: The result of the deletion request.
exportUserData(userId, format)Exports all data associated with a user using the bonded provider.
function exportUserData(userId: string, format?: ExportFormat): Promise<UserDataExport>
userId — The identifier of the user whose data to export.format — The export format (defaults to 'json').Returns: The exported user data package.
getConsent(userId)Retrieves the current consent record for a user using the bonded provider.
function getConsent(userId: string): Promise<ConsentRecord>
userId — The identifier of the user.Returns: The user's consent record.
getDataProcessingLog(userId)Retrieves the data processing log for a user using the bonded provider.
function getDataProcessingLog(userId: string): Promise<ProcessingLogEntry[]>
userId — The identifier of the user.Returns: Array of processing log entries.
getProvider()Retrieves the bonded compliance provider, throwing if none is configured.
function getProvider(): ComplianceProvider
Returns: The bonded compliance provider.
hasProvider()Checks whether a compliance provider is currently bonded.
function hasProvider(): boolean
Returns: true if a compliance provider is bonded.
setConsent(userId, consent)Updates consent for a specific data processing purpose using the bonded provider.
function setConsent(userId: string, consent: ConsentUpdate): Promise<void>
userId — The identifier of the user.consent — The consent update to apply.Returns: Resolves when the bonded provider applies the update.
setProvider(provider)Registers a compliance provider as the active singleton. Called by bond packages during application startup.
function setProvider(provider: ComplianceProvider): void
provider — The compliance provider implementation to bond.| Provider | Package |
|---|---|
| Compliance | @molecule/api-compliance-gdpr |
Peer dependencies:
@molecule/api-bond ^1.0.1@molecule/api-i18n ^1.0.1@molecule/api-bond@molecule/api-i18nCompliance endpoints are attack surface — the rules a generator gets wrong:
userId the request
names lets any user exfiltrate or erase another user's data. Derive the id
from the session; an admin-facing variant needs an explicit admin
authorizer.DeletionResult.status
('partial' and 'failed' are real outcomes), and surface retained
categories (retainLegalObligations) instead of claiming everything was
deleted.getConsent() in the handler/job that
does the processing — a client-side flag is not consent enforcement.setProvider(provider) in the app's
bond setup); every convenience function throws until then.Integration checklist — drive the real UI (live preview, no mocks), adapt each item to this app's actual screens/flows, and check every box off one by one. A box you can't check is an integration bug to fix — not a skip: