npm package: @rivtor/kernel
Description: Production-ready authentication, payments, and compliance kernel for B2B SaaS
Author: Rivtor
Latest version: 1.0.1

# @rivtor/kernel

[![npm version](https://badge.fury.io/js/%40rivtor%Fkernel.svg)](https://www.npmjs.com/package/@rivtor/kernel)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Production-ready authentication, payments, and compliance kernel for B2B SaaS applications.

## Overview

`@rivtor/kernel` is a proprietary governance kernel that automates the hardest parts of EU software compliance:

- **Authentication** - Secure Supabase auth wrapper with pre-built components
- **Payments & VAT** - Stripe integration with EU VAT validation (VIES)
- **Legal Compliance** - GDPR-compliant legal components and data export
- **GDPR Deletion** - Cascading deletion engine with external API cleanup
- **Accessibility** - WCAG 2.1 AA compliant components (EAA 2025 ready)
- **Data Residency** - Egress blocking for EU data compliance
- **Audit Logging** - Enterprise-grade shadow recording

## Installation

```bash
npm install @rivtor/kernel
```

## Quick Start

### Server-Side (API Routes)

```typescript
import { auth, billing } from '@rivtor/kernel';

// Protect API routes
export async function GET(request: Request) {
  const user = await auth.requireUser(request);
  return Response.json({ user });
}

// Create Stripe checkout with VAT validation
export async function POST(request: Request) {
  const { priceId, vatNumber } = await request.json();
  const user = await auth.requireUser(request);

  const session = await billing.createCheckoutSession({
    priceId,
    userId: user.id,
    vatNumber, // Optional: EU VAT number for reverse charge
    successUrl: '/dashboard?checkout=success',
    cancelUrl: '/pricing?checkout=cancelled',
  });

  return Response.json({ url: session.url });
}
```

### Client-Side (React Components)

```tsx
import { RivtorAuth, CookieConsent } from '@rivtor/kernel/react';

export default function Layout({ children }: { children: React.ReactNode }) {
  return (
    <html>
      <body>
        <CookieConsent />
        {children}
      </body>
    </html>
  );
}

// Login page
export default function LoginPage() {
  return <RivtorAuth redirectUrl="/dashboard" />;
}
```

## Modules

### Module A: Vault (Authentication)

Secure Supabase authentication with pre-built components.

```typescript
import { auth } from '@rivtor/kernel';

// Client-side
await auth.loginWithGoogle();
await auth.logout();

// Server-side
const user = await auth.requireUser(request);
const token = await auth.verifyToken(request);
```

### Module B: Register (Payments & Billing)

Stripe integration with EU VAT validation.

```typescript
import { billing } from '@rivtor/kernel';

// Create checkout with VAT validation
const session = await billing.createCheckoutSession({
  priceId: 'price_...',
  userId: user.id,
  vatNumber: 'DE123456789', // Validates against VIES
});

// Validate VAT number
const isValid = await billing.validateVat('DE123456789');

// Get user invoices
const invoices = await billing.getInvoices(userId);
```

### Module C: Shield (Legal Compliance)

GDPR-compliant legal components.

```tsx
import { PrivacyPolicy, TermsOfService } from '@rivtor/kernel/react';

<PrivacyPolicy
  companyName="Acme Inc"
  email="privacy@acme.com"
  updatedAt="2025-01-01"
/>

<TermsOfService
  companyName="Acme Inc"
  email="legal@acme.com"
  jurisdiction="Delaware, USA"
/>
```

### Module 1: Erasure Engine (GDPR)

One-click user deletion with cascading cleanup.

```typescript
import { privacy } from '@rivtor/kernel';

// GDPR Article 17 - Right to be Forgotten
const result = await privacy.obliterate(userId);
// Deletes from: users, projects, websites, logs
// Anonymizes: invoices
// Calls: SendGrid, OpenAI APIs

// Export user data (GDPR request)
const data = await privacy.exportUserData(userId);
```

### Module 2: EAA Enforcer (Accessibility)

WCAG 2.1 AA compliant components.

```tsx
import { RivtorButton, RivtorInput, RivtorForm } from '@rivtor/kernel/react';

<RivtorButton aria-label="Submit form">Submit</RivtorButton>
// Automatically validates ARIA labels and contrast

<RivtorInput
  label="Email"
  type="email"
  required
  // Automatic label association and error handling
/>
```

### Module 3: Sovereignty Shield (Data Residency)

Block data from leaving the EU region.

```typescript
import { residency } from '@rivtor/kernel';

// middleware.ts
export { middleware } from '@rivtor/kernel/residency';

// All outgoing requests are validated
// Non-EU destinations are blocked
```

### Module 4: Audit Log (Enterprise)

Shadow recording for all database mutations.

```tsx
import { RivtorAuditLog } from '@rivtor/kernel/react';

<RivtorAuditLog
  userId={user.id}
  filters={{ action: 'UPDATE', table: 'projects' }}
/>
```

## Environment Variables

```bash
# Supabase (Required)
NEXT_PUBLIC_SUPABASE_URL=your_supabase_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_service_role_key

# Stripe (Required)
STRIPE_SECRET_KEY=sk_...
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_...
STRIPE_WEBHOOK_SECRET=whsec_...

# App Configuration
NEXT_PUBLIC_APP_URL=https://yourapp.com
NEXT_PUBLIC_APP_NAME=Your App
SUPPORT_EMAIL=support@yourapp.com
LEGAL_EMAIL=legal@yourapp.com

# Data Residency (Optional)
RIVTOR_DATA_RESIDENCY_ENABLED=true
RIVTOR_DATA_REGION=eu
RIVTOR_RESIDENCY_STRICT_MODE=true

# Accessibility (Optional)
RIVTOR_ENFORCE_CONTRAST=true
RIVTOR_ENFORCE_ARIA=true
RIVTOR_CONTRAST_RATIO=4.5
```

## Philosophy

The Rivtor Kernel is built on the principle that **AI should not write auth, payments, or compliance code**.

These domains require:
- Deep security knowledge
- Legal compliance expertise
- Production hardening
- Continuous updates for regulations

By providing pre-built, tested, and compliant modules, we enable AI to focus on business logic while ensuring the critical infrastructure is secure and compliant.

## License

MIT © Rivtor

## Support

- Email: legal@rivtor.com
- Documentation: [GitHub Wiki](https://github.com/rivtor/rivtor-kernel/wiki)

---

**Built with care by [Rivtor](https://rivtor.com)**