diff --git a/packages/db-schema/README.md b/packages/db-schema/README.md new file mode 100644 index 0000000..dd62013 --- /dev/null +++ b/packages/db-schema/README.md @@ -0,0 +1,24 @@ +# @reviq/db-schema + +Database schema types generated from PostgreSQL using kysely-codegen. + +## Usage + +```typescript +import type { Database } from "@reviq/db-schema"; +``` + +## Regenerating Types + +When the database schema changes, regenerate the types: + +```bash +bun run --cwd packages/db-schema generate +``` + +This requires `DATABASE_URL` to be set and pointing to a database with the current schema. + +## Exports + +- `Database` - The full database type for use with Kysely +- Table types for all database tables (e.g., `Users`, `Orgs`, `Sessions`) diff --git a/packages/db/README.md b/packages/db/README.md new file mode 100644 index 0000000..1a16420 --- /dev/null +++ b/packages/db/README.md @@ -0,0 +1,33 @@ +# @reviq/db + +Database client and helper functions for the RevIQ platform. + +## Usage + +```typescript +import { createDb } from "@reviq/db"; + +const db = createDb(process.env.DATABASE_URL); + +// Use db with Kysely queries +const users = await db.selectFrom("users").selectAll().execute(); + +// Clean up when done +await db.destroy(); +``` + +## Exports + +### Client +- `createDb(url)` - Create a Kysely database instance + +### Helper Functions +- `executeBootstrap(trx, input)` - Bootstrap a new database with superuser and org +- `generateToken()` - Generate an API token +- `hashToken(token)` - Hash a token for storage +- `parseToken(token)` - Parse and validate a token +- `TOKEN_PREFIX` - The `reviq_` prefix for API tokens + +### Types +- `Database` - Re-exported from `@reviq/db-schema` +- `BootstrapInput` / `BootstrapResult` - Types for bootstrap operation diff --git a/packages/testing/README.md b/packages/testing/README.md new file mode 100644 index 0000000..5d79cf3 --- /dev/null +++ b/packages/testing/README.md @@ -0,0 +1,34 @@ +# Testing Packages + +Shared testing utilities for the RevIQ platform. + +## Packages + +### @reviq/test-helpers + +Database testing utilities including test database setup, transactions, and fixtures. + +```typescript +import { createTestDb, withTestTransaction, describeE2E } from "@reviq/test-helpers"; +``` + +### @reviq/virtual-authenticator + +WebAuthn virtual authenticator for testing passkey flows without real hardware. + +```typescript +import { VirtualAuthenticator } from "@reviq/virtual-authenticator"; +``` + +## Usage + +These packages are used internally for e2e and integration tests. Add them as dev dependencies: + +```json +{ + "devDependencies": { + "@reviq/test-helpers": "workspace:*", + "@reviq/virtual-authenticator": "workspace:*" + } +} +``` diff --git a/packages/testing/test-helpers/README.md b/packages/testing/test-helpers/README.md new file mode 100644 index 0000000..b185c4d --- /dev/null +++ b/packages/testing/test-helpers/README.md @@ -0,0 +1,52 @@ +# @reviq/test-helpers + +Database testing utilities for integration and e2e tests. + +## Usage + +```typescript +import { + describeE2E, + createTestDb, + withTestTransaction, + createTestUser, +} from "@reviq/test-helpers"; + +describeE2E("My API tests", () => { + it("should create a user", async () => { + await withTestTransaction(async (trx) => { + const user = await createTestUser(trx, { + email: "test@example.com", + }); + expect(user.id).toBeDefined(); + }); + }); +}); +``` + +## Exports + +### Test Setup +- `describeE2E(name, fn)` - Wrapper for describe() that skips when `SKIP_DB_TESTS=1` +- `SKIP_DB_TESTS` - Boolean indicating if db tests should be skipped + +### Database Utilities +- `createTestDb()` - Create an isolated test database +- `destroyTestDb(db)` - Destroy a test database +- `getSharedDb()` - Get the shared test database instance +- `destroySharedDb()` - Destroy the shared database +- `initTestDb()` - Initialize the test database +- `runMigrations(url)` - Run database migrations +- `truncateAllTables(db)` - Clear all data from tables +- `getTestDatabaseUrl()` - Get the test database connection URL + +### Transaction Helpers +- `withTestTransaction(fn)` - Run a function in a rolled-back transaction + +### Fixtures +- `createTestUser(trx, opts)` - Create a test user + +### Constants +- `TEST_RP` - Test relying party configuration for WebAuthn +- `DEFAULT_TEST_AAGUID` - Default AAGUID for virtual authenticator +- `KNOWN_AAGUIDS` - Map of known authenticator AAGUIDs diff --git a/packages/testing/virtual-authenticator/README.md b/packages/testing/virtual-authenticator/README.md new file mode 100644 index 0000000..009779c --- /dev/null +++ b/packages/testing/virtual-authenticator/README.md @@ -0,0 +1,39 @@ +# @reviq/virtual-authenticator + +WebAuthn virtual authenticator for testing passkey registration and authentication flows. + +## Usage + +```typescript +import { VirtualAuthenticator } from "@reviq/virtual-authenticator"; + +const authenticator = new VirtualAuthenticator({ + aaguid: "00000000-0000-0000-0000-000000000000", +}); + +// Create a credential during registration +const credential = await authenticator.create( + publicKeyCredentialCreationOptions, +); + +// Use the credential during authentication +const assertion = await authenticator.get( + publicKeyCredentialRequestOptions, +); +``` + +## Exports + +### Classes +- `VirtualAuthenticator` - Simulates a WebAuthn authenticator + +### Utilities +- `base64urlToUint8Array(str)` - Decode base64url to bytes +- `uint8ArrayToBase64url(bytes)` - Encode bytes to base64url +- `parseAaguid(str)` - Parse an AAGUID string to bytes + +### Constants +- `DEFAULT_AAGUID` - Default AAGUID for the virtual authenticator + +### Types +- `VirtualAuthenticatorOptions` - Configuration options for the authenticator