diff --git a/.changeset/mcp-migration-to-cli.md b/.changeset/mcp-migration-to-cli.md deleted file mode 100644 index a33b9515..00000000 --- a/.changeset/mcp-migration-to-cli.md +++ /dev/null @@ -1,74 +0,0 @@ ---- -'@opensaas/stack-cli': minor -'create-opensaas-app': minor ---- - -# Add MCP Server for AI-Assisted Development - -## New Features - -### CLI Package (@opensaas/stack-cli) - -- **New `opensaas mcp` command group** for AI-assisted development: - - `opensaas mcp install` - Install MCP server in Claude Code - - `opensaas mcp uninstall` - Remove MCP server from Claude Code - - `opensaas mcp start` - Start MCP server directly (for debugging) - -- **Feature-driven development tools**: - - Interactive feature implementation wizards (authentication, blog, comments, file-upload, semantic-search) - - Live documentation search from stack.opensaas.au - - Code generation following OpenSaaS best practices - - Smart feature suggestions based on your current app - - Config validation - -- **MCP tools available in Claude Code**: - - `opensaas_implement_feature` - Start feature wizard - - `opensaas_feature_docs` - Search documentation - - `opensaas_list_features` - Browse available features - - `opensaas_suggest_features` - Get personalized recommendations - - `opensaas_validate_feature` - Validate implementations - -### create-opensaas-app - -- **Interactive MCP setup prompt** during project creation -- Option to enable AI development tools automatically -- Automatic installation of MCP server if user opts in -- Helpful instructions if MCP installation is declined or fails - -## Installation - -Enable AI development tools for an existing project: - -```bash -npx @opensaas/stack-cli mcp install -``` - -Or during project creation: - -```bash -npm create opensaas-app@latest my-app -# When prompted: Enable AI development tools? → yes -``` - -## Benefits - -- **Build apps faster**: Describe what you want to build, get complete implementations -- **Feature-driven development**: Work with high-level features instead of low-level config -- **Best practices baked in**: Generated code follows OpenSaaS Stack patterns -- **Live documentation**: Always up-to-date docs from the official site -- **Single toolkit**: All developer commands in one CLI - -## Example Usage - -With Claude Code installed and the MCP server enabled, you can: - -``` -You: "I want to build a food tracking app" - -Claude Code uses MCP tools to: -1. Ask clarifying questions about requirements -2. Implement authentication feature (wizard) -3. Create custom Food and FoodLog lists -4. Generate complete code with UI and access control -5. Provide testing and deployment guidance -``` diff --git a/.changeset/prisma-7-upgrade.md b/.changeset/prisma-7-upgrade.md deleted file mode 100644 index e94b82f4..00000000 --- a/.changeset/prisma-7-upgrade.md +++ /dev/null @@ -1,89 +0,0 @@ ---- -'@opensaas/stack-core': minor -'@opensaas/stack-cli': minor -'@opensaas/stack-rag': patch ---- - -Upgrade to Prisma 7 with database adapter support - -## Breaking Changes - -### Required `prismaClientConstructor` - -Prisma 7 requires database adapters. All configs must now include `prismaClientConstructor`: - -```typescript -import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3' -import Database from 'better-sqlite3' - -export default config({ - db: { - provider: 'sqlite', - prismaClientConstructor: (PrismaClient) => { - const db = new Database(process.env.DATABASE_URL || './dev.db') - const adapter = new PrismaBetterSQLite3(db) - return new PrismaClient({ adapter }) - }, - }, -}) -``` - -### Removed `url` from `DatabaseConfig` - -The `url` field has been removed from the `DatabaseConfig` type. Database connection URLs are now passed directly to adapters in `prismaClientConstructor`: - -```typescript -// ❌ Before (Prisma 6) -db: { - provider: 'sqlite', - url: 'file:./dev.db', // url in config -} - -// ✅ After (Prisma 7) -db: { - provider: 'sqlite', - prismaClientConstructor: (PrismaClient) => { - const adapter = new PrismaBetterSQLite3({ url: './dev.db' }) // url in adapter - return new PrismaClient({ adapter }) - }, -} -``` - -### Generated Schema Changes - -- Generator provider changed from `prisma-client-js` to `prisma-client` -- Removed `url` field from datasource block -- Database URL now passed via adapter in `prismaClientConstructor` - -### Required Dependencies - -Install the appropriate adapter for your database: - -- **SQLite**: `@prisma/adapter-better-sqlite3` + `better-sqlite3` -- **PostgreSQL**: `@prisma/adapter-pg` + `pg` -- **MySQL**: `@prisma/adapter-mysql` + `mysql2` - -## Migration Steps - -1. Install Prisma 7 and adapter: - - ```bash - pnpm add @prisma/client@7 @prisma/adapter-better-sqlite3 better-sqlite3 - pnpm add -D prisma@7 - ``` - -2. Update your `opensaas.config.ts` to include `prismaClientConstructor` (see example above) - -3. Regenerate schema and client: - - ```bash - pnpm generate - npx prisma generate - ``` - -4. Push schema to database: - ```bash - pnpm db:push - ``` - -See the updated documentation in CLAUDE.md for more examples including PostgreSQL and custom adapters. diff --git a/.changeset/session-type-augmentation.md b/.changeset/session-type-augmentation.md deleted file mode 100644 index a05b0a56..00000000 --- a/.changeset/session-type-augmentation.md +++ /dev/null @@ -1,76 +0,0 @@ ---- -'@opensaas/stack-core': minor -'@opensaas/stack-auth': minor ---- - -Add strongly-typed session support via module augmentation - -This change enables developers to define custom session types with full TypeScript autocomplete and type safety throughout their OpenSaas applications using the module augmentation pattern. - -**Core Changes:** - -- Converted `Session` from `type` to `interface` to enable module augmentation -- Updated all session references to properly handle `Session | null` -- Added comprehensive JSDoc documentation with module augmentation examples -- Updated `AccessControl`, `AccessContext`, and access control engine to support nullable sessions -- Added "Session Typing" section to core package documentation - -**Auth Package:** - -- Added "Session Type Safety" section to documentation -- Documented how Better Auth users can create session type declarations -- Provided step-by-step guide for matching sessionFields to TypeScript types -- Created `getSession()` helper pattern for transforming Better Auth sessions - -**Developer Experience:** - -Developers can now augment the `Session` interface to get autocomplete everywhere: - -```typescript -// types/session.d.ts -import '@opensaas/stack-core' - -declare module '@opensaas/stack-core' { - interface Session { - userId?: string - email?: string - role?: 'admin' | 'user' - } -} -``` - -This provides autocomplete in: - -- Access control functions -- Hooks (resolveInput, validateInput, etc.) -- Context object -- Server actions - -**Benefits:** - -- Zero boilerplate - module augmentation provides types everywhere automatically -- Full type safety for session properties -- Autocomplete in all contexts that use session -- Developer controls session shape (no assumptions about structure) -- Works with any auth provider (Better Auth, custom, etc.) -- Fully backward compatible - existing code continues to work -- Follows TypeScript best practices (similar to NextAuth.js pattern) - -**Example:** - -```typescript -// Before: No autocomplete -const isAdmin: AccessControl = ({ session }) => { - return session?.role === 'admin' // ❌ 'role' is 'unknown' -} - -// After: Full autocomplete and type checking -const isAdmin: AccessControl = ({ session }) => { - return session?.role === 'admin' // ✅ Autocomplete + type checking - // ↑ Shows: userId, email, role -} -``` - -**Migration:** - -No migration required - this is a fully backward compatible change. Existing projects continue to work with untyped sessions. Projects can opt-in to typed sessions by creating a `types/session.d.ts` file with module augmentation. diff --git a/.changeset/strict-plugin-types.md b/.changeset/strict-plugin-types.md deleted file mode 100644 index 7229f04d..00000000 --- a/.changeset/strict-plugin-types.md +++ /dev/null @@ -1,58 +0,0 @@ ---- -'@opensaas/stack-core': patch -'@opensaas/stack-auth': patch -'@opensaas/stack-rag': patch -'@opensaas/stack-cli': patch ---- - -Add strict typing for plugin runtime services - -This change implements fully typed plugin runtime services, providing autocomplete and type safety for `context.plugins` throughout the codebase. - -**Core Changes:** - -- Extended `Plugin` type with optional `runtimeServiceTypes` metadata for type-safe code generation -- Converted `OpenSaasConfig` and `AccessContext` from `type` to `interface` to enable module augmentation -- Plugins can now declare their runtime service type information - -**Auth Plugin:** - -- Added `AuthRuntimeServices` interface defining runtime service types -- Exported runtime types from package -- Users now get full autocomplete for `context.plugins.auth.getUser()` and `context.plugins.auth.getCurrentUser()` - -**RAG Plugin:** - -- Added `RAGRuntimeServices` interface defining runtime service types -- Exported runtime types from package -- Users now get full autocomplete for `context.plugins.rag.generateEmbedding()` and `context.plugins.rag.generateEmbeddings()` - -**CLI Generator:** - -- Enhanced plugin types generator to import and use plugin runtime service types -- Generated `.opensaas/plugin-types.ts` now includes proper type imports -- `PluginServices` interface extends `Record | undefined>` for type compatibility -- Maintains backwards compatibility with plugins that don't provide type metadata - -**UI Package:** - -- Updated `AdminUI` props to accept contexts with typed plugin services -- Ensures compatibility between generated context types and UI components - -**Benefits:** - -- Full TypeScript autocomplete for all plugin runtime methods -- Compile-time type checking catches errors early -- Better IDE experience with hover documentation and jump-to-definition -- Backwards compatible - third-party plugins without type metadata continue to work -- Zero type errors in examples - -**Example:** - -```typescript -const context = await getContext() - -// Fully typed with autocomplete -context.plugins.auth.getUser('123') // (userId: string) => Promise -context.plugins.rag.generateEmbedding('text') // (text: string, providerName?: string) => Promise -``` diff --git a/packages/auth/CHANGELOG.md b/packages/auth/CHANGELOG.md index 36bd0205..bfc9efee 100644 --- a/packages/auth/CHANGELOG.md +++ b/packages/auth/CHANGELOG.md @@ -1,5 +1,125 @@ # @opensaas/stack-auth +## 0.2.0 + +### Minor Changes + +- [#121](https://github.com/OpenSaasAU/stack/pull/121) [`3851a3c`](https://github.com/OpenSaasAU/stack/commit/3851a3cf72e78dc6f01a73c6fff97deca6fad043) Thanks [@borisno2](https://github.com/borisno2)! - Add strongly-typed session support via module augmentation + + This change enables developers to define custom session types with full TypeScript autocomplete and type safety throughout their OpenSaas applications using the module augmentation pattern. + + **Core Changes:** + - Converted `Session` from `type` to `interface` to enable module augmentation + - Updated all session references to properly handle `Session | null` + - Added comprehensive JSDoc documentation with module augmentation examples + - Updated `AccessControl`, `AccessContext`, and access control engine to support nullable sessions + - Added "Session Typing" section to core package documentation + + **Auth Package:** + - Added "Session Type Safety" section to documentation + - Documented how Better Auth users can create session type declarations + - Provided step-by-step guide for matching sessionFields to TypeScript types + - Created `getSession()` helper pattern for transforming Better Auth sessions + + **Developer Experience:** + + Developers can now augment the `Session` interface to get autocomplete everywhere: + + ```typescript + // types/session.d.ts + import '@opensaas/stack-core' + + declare module '@opensaas/stack-core' { + interface Session { + userId?: string + email?: string + role?: 'admin' | 'user' + } + } + ``` + + This provides autocomplete in: + - Access control functions + - Hooks (resolveInput, validateInput, etc.) + - Context object + - Server actions + + **Benefits:** + - Zero boilerplate - module augmentation provides types everywhere automatically + - Full type safety for session properties + - Autocomplete in all contexts that use session + - Developer controls session shape (no assumptions about structure) + - Works with any auth provider (Better Auth, custom, etc.) + - Fully backward compatible - existing code continues to work + - Follows TypeScript best practices (similar to NextAuth.js pattern) + + **Example:** + + ```typescript + // Before: No autocomplete + const isAdmin: AccessControl = ({ session }) => { + return session?.role === 'admin' // ❌ 'role' is 'unknown' + } + + // After: Full autocomplete and type checking + const isAdmin: AccessControl = ({ session }) => { + return session?.role === 'admin' // ✅ Autocomplete + type checking + // ↑ Shows: userId, email, role + } + ``` + + **Migration:** + + No migration required - this is a fully backward compatible change. Existing projects continue to work with untyped sessions. Projects can opt-in to typed sessions by creating a `types/session.d.ts` file with module augmentation. + +### Patch Changes + +- [#107](https://github.com/OpenSaasAU/stack/pull/107) [`f4f3966`](https://github.com/OpenSaasAU/stack/commit/f4f3966faedba07d2cf412fab826d81e30c63a6c) Thanks [@borisno2](https://github.com/borisno2)! - Add strict typing for plugin runtime services + + This change implements fully typed plugin runtime services, providing autocomplete and type safety for `context.plugins` throughout the codebase. + + **Core Changes:** + - Extended `Plugin` type with optional `runtimeServiceTypes` metadata for type-safe code generation + - Converted `OpenSaasConfig` and `AccessContext` from `type` to `interface` to enable module augmentation + - Plugins can now declare their runtime service type information + + **Auth Plugin:** + - Added `AuthRuntimeServices` interface defining runtime service types + - Exported runtime types from package + - Users now get full autocomplete for `context.plugins.auth.getUser()` and `context.plugins.auth.getCurrentUser()` + + **RAG Plugin:** + - Added `RAGRuntimeServices` interface defining runtime service types + - Exported runtime types from package + - Users now get full autocomplete for `context.plugins.rag.generateEmbedding()` and `context.plugins.rag.generateEmbeddings()` + + **CLI Generator:** + - Enhanced plugin types generator to import and use plugin runtime service types + - Generated `.opensaas/plugin-types.ts` now includes proper type imports + - `PluginServices` interface extends `Record | undefined>` for type compatibility + - Maintains backwards compatibility with plugins that don't provide type metadata + + **UI Package:** + - Updated `AdminUI` props to accept contexts with typed plugin services + - Ensures compatibility between generated context types and UI components + + **Benefits:** + - Full TypeScript autocomplete for all plugin runtime methods + - Compile-time type checking catches errors early + - Better IDE experience with hover documentation and jump-to-definition + - Backwards compatible - third-party plugins without type metadata continue to work + - Zero type errors in examples + + **Example:** + + ```typescript + const context = await getContext() + + // Fully typed with autocomplete + context.plugins.auth.getUser('123') // (userId: string) => Promise + context.plugins.rag.generateEmbedding('text') // (text: string, providerName?: string) => Promise + ``` + ## 0.1.7 ### Patch Changes diff --git a/packages/auth/package.json b/packages/auth/package.json index 36bc1f10..46f89dc0 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -1,6 +1,6 @@ { "name": "@opensaas/stack-auth", - "version": "0.1.7", + "version": "0.2.0", "description": "Better-auth integration for OpenSaas Stack", "type": "module", "main": "./dist/index.js", diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index f2ce0c08..097dfb10 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -1,5 +1,205 @@ # @opensaas/stack-cli +## 0.2.0 + +### Minor Changes + +- [#107](https://github.com/OpenSaasAU/stack/pull/107) [`f4f3966`](https://github.com/OpenSaasAU/stack/commit/f4f3966faedba07d2cf412fab826d81e30c63a6c) Thanks [@borisno2](https://github.com/borisno2)! - # Add MCP Server for AI-Assisted Development + + ## New Features + + ### CLI Package (@opensaas/stack-cli) + - **New `opensaas mcp` command group** for AI-assisted development: + - `opensaas mcp install` - Install MCP server in Claude Code + - `opensaas mcp uninstall` - Remove MCP server from Claude Code + - `opensaas mcp start` - Start MCP server directly (for debugging) + - **Feature-driven development tools**: + - Interactive feature implementation wizards (authentication, blog, comments, file-upload, semantic-search) + - Live documentation search from stack.opensaas.au + - Code generation following OpenSaaS best practices + - Smart feature suggestions based on your current app + - Config validation + - **MCP tools available in Claude Code**: + - `opensaas_implement_feature` - Start feature wizard + - `opensaas_feature_docs` - Search documentation + - `opensaas_list_features` - Browse available features + - `opensaas_suggest_features` - Get personalized recommendations + - `opensaas_validate_feature` - Validate implementations + + ### create-opensaas-app + - **Interactive MCP setup prompt** during project creation + - Option to enable AI development tools automatically + - Automatic installation of MCP server if user opts in + - Helpful instructions if MCP installation is declined or fails + + ## Installation + + Enable AI development tools for an existing project: + + ```bash + npx @opensaas/stack-cli mcp install + ``` + + Or during project creation: + + ```bash + npm create opensaas-app@latest my-app + # When prompted: Enable AI development tools? → yes + ``` + + ## Benefits + - **Build apps faster**: Describe what you want to build, get complete implementations + - **Feature-driven development**: Work with high-level features instead of low-level config + - **Best practices baked in**: Generated code follows OpenSaaS Stack patterns + - **Live documentation**: Always up-to-date docs from the official site + - **Single toolkit**: All developer commands in one CLI + + ## Example Usage + + With Claude Code installed and the MCP server enabled, you can: + + ``` + You: "I want to build a food tracking app" + + Claude Code uses MCP tools to: + 1. Ask clarifying questions about requirements + 2. Implement authentication feature (wizard) + 3. Create custom Food and FoodLog lists + 4. Generate complete code with UI and access control + 5. Provide testing and deployment guidance + ``` + +- [#132](https://github.com/OpenSaasAU/stack/pull/132) [`fcf5cb8`](https://github.com/OpenSaasAU/stack/commit/fcf5cb8bbd55d802350b8d97e342dd7f6368163b) Thanks [@borisno2](https://github.com/borisno2)! - Upgrade to Prisma 7 with database adapter support + + ## Breaking Changes + + ### Required `prismaClientConstructor` + + Prisma 7 requires database adapters. All configs must now include `prismaClientConstructor`: + + ```typescript + import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3' + import Database from 'better-sqlite3' + + export default config({ + db: { + provider: 'sqlite', + prismaClientConstructor: (PrismaClient) => { + const db = new Database(process.env.DATABASE_URL || './dev.db') + const adapter = new PrismaBetterSQLite3(db) + return new PrismaClient({ adapter }) + }, + }, + }) + ``` + + ### Removed `url` from `DatabaseConfig` + + The `url` field has been removed from the `DatabaseConfig` type. Database connection URLs are now passed directly to adapters in `prismaClientConstructor`: + + ```typescript + // ❌ Before (Prisma 6) + db: { + provider: 'sqlite', + url: 'file:./dev.db', // url in config + } + + // ✅ After (Prisma 7) + db: { + provider: 'sqlite', + prismaClientConstructor: (PrismaClient) => { + const adapter = new PrismaBetterSQLite3({ url: './dev.db' }) // url in adapter + return new PrismaClient({ adapter }) + }, + } + ``` + + ### Generated Schema Changes + - Generator provider changed from `prisma-client-js` to `prisma-client` + - Removed `url` field from datasource block + - Database URL now passed via adapter in `prismaClientConstructor` + + ### Required Dependencies + + Install the appropriate adapter for your database: + - **SQLite**: `@prisma/adapter-better-sqlite3` + `better-sqlite3` + - **PostgreSQL**: `@prisma/adapter-pg` + `pg` + - **MySQL**: `@prisma/adapter-mysql` + `mysql2` + + ## Migration Steps + 1. Install Prisma 7 and adapter: + + ```bash + pnpm add @prisma/client@7 @prisma/adapter-better-sqlite3 better-sqlite3 + pnpm add -D prisma@7 + ``` + + 2. Update your `opensaas.config.ts` to include `prismaClientConstructor` (see example above) + 3. Regenerate schema and client: + + ```bash + pnpm generate + npx prisma generate + ``` + + 4. Push schema to database: + ```bash + pnpm db:push + ``` + + See the updated documentation in CLAUDE.md for more examples including PostgreSQL and custom adapters. + +### Patch Changes + +- [#107](https://github.com/OpenSaasAU/stack/pull/107) [`f4f3966`](https://github.com/OpenSaasAU/stack/commit/f4f3966faedba07d2cf412fab826d81e30c63a6c) Thanks [@borisno2](https://github.com/borisno2)! - Add strict typing for plugin runtime services + + This change implements fully typed plugin runtime services, providing autocomplete and type safety for `context.plugins` throughout the codebase. + + **Core Changes:** + - Extended `Plugin` type with optional `runtimeServiceTypes` metadata for type-safe code generation + - Converted `OpenSaasConfig` and `AccessContext` from `type` to `interface` to enable module augmentation + - Plugins can now declare their runtime service type information + + **Auth Plugin:** + - Added `AuthRuntimeServices` interface defining runtime service types + - Exported runtime types from package + - Users now get full autocomplete for `context.plugins.auth.getUser()` and `context.plugins.auth.getCurrentUser()` + + **RAG Plugin:** + - Added `RAGRuntimeServices` interface defining runtime service types + - Exported runtime types from package + - Users now get full autocomplete for `context.plugins.rag.generateEmbedding()` and `context.plugins.rag.generateEmbeddings()` + + **CLI Generator:** + - Enhanced plugin types generator to import and use plugin runtime service types + - Generated `.opensaas/plugin-types.ts` now includes proper type imports + - `PluginServices` interface extends `Record | undefined>` for type compatibility + - Maintains backwards compatibility with plugins that don't provide type metadata + + **UI Package:** + - Updated `AdminUI` props to accept contexts with typed plugin services + - Ensures compatibility between generated context types and UI components + + **Benefits:** + - Full TypeScript autocomplete for all plugin runtime methods + - Compile-time type checking catches errors early + - Better IDE experience with hover documentation and jump-to-definition + - Backwards compatible - third-party plugins without type metadata continue to work + - Zero type errors in examples + + **Example:** + + ```typescript + const context = await getContext() + + // Fully typed with autocomplete + context.plugins.auth.getUser('123') // (userId: string) => Promise + context.plugins.rag.generateEmbedding('text') // (text: string, providerName?: string) => Promise + ``` + +- Updated dependencies [[`fcf5cb8`](https://github.com/OpenSaasAU/stack/commit/fcf5cb8bbd55d802350b8d97e342dd7f6368163b), [`3851a3c`](https://github.com/OpenSaasAU/stack/commit/3851a3cf72e78dc6f01a73c6fff97deca6fad043), [`f4f3966`](https://github.com/OpenSaasAU/stack/commit/f4f3966faedba07d2cf412fab826d81e30c63a6c)]: + - @opensaas/stack-core@0.2.0 + ## 0.1.7 ### Patch Changes diff --git a/packages/cli/package.json b/packages/cli/package.json index 35973754..731de10d 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@opensaas/stack-cli", - "version": "0.1.7", + "version": "0.2.0", "description": "CLI tools for OpenSaas Stack", "type": "module", "main": "./dist/index.js", diff --git a/packages/core/CHANGELOG.md b/packages/core/CHANGELOG.md index 066ca88b..899d1357 100644 --- a/packages/core/CHANGELOG.md +++ b/packages/core/CHANGELOG.md @@ -1,5 +1,205 @@ # @opensaas/stack-core +## 0.2.0 + +### Minor Changes + +- [#132](https://github.com/OpenSaasAU/stack/pull/132) [`fcf5cb8`](https://github.com/OpenSaasAU/stack/commit/fcf5cb8bbd55d802350b8d97e342dd7f6368163b) Thanks [@borisno2](https://github.com/borisno2)! - Upgrade to Prisma 7 with database adapter support + + ## Breaking Changes + + ### Required `prismaClientConstructor` + + Prisma 7 requires database adapters. All configs must now include `prismaClientConstructor`: + + ```typescript + import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3' + import Database from 'better-sqlite3' + + export default config({ + db: { + provider: 'sqlite', + prismaClientConstructor: (PrismaClient) => { + const db = new Database(process.env.DATABASE_URL || './dev.db') + const adapter = new PrismaBetterSQLite3(db) + return new PrismaClient({ adapter }) + }, + }, + }) + ``` + + ### Removed `url` from `DatabaseConfig` + + The `url` field has been removed from the `DatabaseConfig` type. Database connection URLs are now passed directly to adapters in `prismaClientConstructor`: + + ```typescript + // ❌ Before (Prisma 6) + db: { + provider: 'sqlite', + url: 'file:./dev.db', // url in config + } + + // ✅ After (Prisma 7) + db: { + provider: 'sqlite', + prismaClientConstructor: (PrismaClient) => { + const adapter = new PrismaBetterSQLite3({ url: './dev.db' }) // url in adapter + return new PrismaClient({ adapter }) + }, + } + ``` + + ### Generated Schema Changes + - Generator provider changed from `prisma-client-js` to `prisma-client` + - Removed `url` field from datasource block + - Database URL now passed via adapter in `prismaClientConstructor` + + ### Required Dependencies + + Install the appropriate adapter for your database: + - **SQLite**: `@prisma/adapter-better-sqlite3` + `better-sqlite3` + - **PostgreSQL**: `@prisma/adapter-pg` + `pg` + - **MySQL**: `@prisma/adapter-mysql` + `mysql2` + + ## Migration Steps + 1. Install Prisma 7 and adapter: + + ```bash + pnpm add @prisma/client@7 @prisma/adapter-better-sqlite3 better-sqlite3 + pnpm add -D prisma@7 + ``` + + 2. Update your `opensaas.config.ts` to include `prismaClientConstructor` (see example above) + 3. Regenerate schema and client: + + ```bash + pnpm generate + npx prisma generate + ``` + + 4. Push schema to database: + ```bash + pnpm db:push + ``` + + See the updated documentation in CLAUDE.md for more examples including PostgreSQL and custom adapters. + +- [#121](https://github.com/OpenSaasAU/stack/pull/121) [`3851a3c`](https://github.com/OpenSaasAU/stack/commit/3851a3cf72e78dc6f01a73c6fff97deca6fad043) Thanks [@borisno2](https://github.com/borisno2)! - Add strongly-typed session support via module augmentation + + This change enables developers to define custom session types with full TypeScript autocomplete and type safety throughout their OpenSaas applications using the module augmentation pattern. + + **Core Changes:** + - Converted `Session` from `type` to `interface` to enable module augmentation + - Updated all session references to properly handle `Session | null` + - Added comprehensive JSDoc documentation with module augmentation examples + - Updated `AccessControl`, `AccessContext`, and access control engine to support nullable sessions + - Added "Session Typing" section to core package documentation + + **Auth Package:** + - Added "Session Type Safety" section to documentation + - Documented how Better Auth users can create session type declarations + - Provided step-by-step guide for matching sessionFields to TypeScript types + - Created `getSession()` helper pattern for transforming Better Auth sessions + + **Developer Experience:** + + Developers can now augment the `Session` interface to get autocomplete everywhere: + + ```typescript + // types/session.d.ts + import '@opensaas/stack-core' + + declare module '@opensaas/stack-core' { + interface Session { + userId?: string + email?: string + role?: 'admin' | 'user' + } + } + ``` + + This provides autocomplete in: + - Access control functions + - Hooks (resolveInput, validateInput, etc.) + - Context object + - Server actions + + **Benefits:** + - Zero boilerplate - module augmentation provides types everywhere automatically + - Full type safety for session properties + - Autocomplete in all contexts that use session + - Developer controls session shape (no assumptions about structure) + - Works with any auth provider (Better Auth, custom, etc.) + - Fully backward compatible - existing code continues to work + - Follows TypeScript best practices (similar to NextAuth.js pattern) + + **Example:** + + ```typescript + // Before: No autocomplete + const isAdmin: AccessControl = ({ session }) => { + return session?.role === 'admin' // ❌ 'role' is 'unknown' + } + + // After: Full autocomplete and type checking + const isAdmin: AccessControl = ({ session }) => { + return session?.role === 'admin' // ✅ Autocomplete + type checking + // ↑ Shows: userId, email, role + } + ``` + + **Migration:** + + No migration required - this is a fully backward compatible change. Existing projects continue to work with untyped sessions. Projects can opt-in to typed sessions by creating a `types/session.d.ts` file with module augmentation. + +### Patch Changes + +- [#107](https://github.com/OpenSaasAU/stack/pull/107) [`f4f3966`](https://github.com/OpenSaasAU/stack/commit/f4f3966faedba07d2cf412fab826d81e30c63a6c) Thanks [@borisno2](https://github.com/borisno2)! - Add strict typing for plugin runtime services + + This change implements fully typed plugin runtime services, providing autocomplete and type safety for `context.plugins` throughout the codebase. + + **Core Changes:** + - Extended `Plugin` type with optional `runtimeServiceTypes` metadata for type-safe code generation + - Converted `OpenSaasConfig` and `AccessContext` from `type` to `interface` to enable module augmentation + - Plugins can now declare their runtime service type information + + **Auth Plugin:** + - Added `AuthRuntimeServices` interface defining runtime service types + - Exported runtime types from package + - Users now get full autocomplete for `context.plugins.auth.getUser()` and `context.plugins.auth.getCurrentUser()` + + **RAG Plugin:** + - Added `RAGRuntimeServices` interface defining runtime service types + - Exported runtime types from package + - Users now get full autocomplete for `context.plugins.rag.generateEmbedding()` and `context.plugins.rag.generateEmbeddings()` + + **CLI Generator:** + - Enhanced plugin types generator to import and use plugin runtime service types + - Generated `.opensaas/plugin-types.ts` now includes proper type imports + - `PluginServices` interface extends `Record | undefined>` for type compatibility + - Maintains backwards compatibility with plugins that don't provide type metadata + + **UI Package:** + - Updated `AdminUI` props to accept contexts with typed plugin services + - Ensures compatibility between generated context types and UI components + + **Benefits:** + - Full TypeScript autocomplete for all plugin runtime methods + - Compile-time type checking catches errors early + - Better IDE experience with hover documentation and jump-to-definition + - Backwards compatible - third-party plugins without type metadata continue to work + - Zero type errors in examples + + **Example:** + + ```typescript + const context = await getContext() + + // Fully typed with autocomplete + context.plugins.auth.getUser('123') // (userId: string) => Promise + context.plugins.rag.generateEmbedding('text') // (text: string, providerName?: string) => Promise + ``` + ## 0.1.7 ### Patch Changes diff --git a/packages/core/package.json b/packages/core/package.json index 5554d898..1ed5f0a0 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@opensaas/stack-core", - "version": "0.1.7", + "version": "0.2.0", "description": "Core stack for OpenSaas - schema definition, access control, and runtime utilities", "type": "module", "main": "./dist/index.js", diff --git a/packages/create-opensaas-app/CHANGELOG.md b/packages/create-opensaas-app/CHANGELOG.md index 6727e52c..0bac1288 100644 --- a/packages/create-opensaas-app/CHANGELOG.md +++ b/packages/create-opensaas-app/CHANGELOG.md @@ -1,5 +1,74 @@ # create-opensaas-app +## 0.2.0 + +### Minor Changes + +- [#107](https://github.com/OpenSaasAU/stack/pull/107) [`f4f3966`](https://github.com/OpenSaasAU/stack/commit/f4f3966faedba07d2cf412fab826d81e30c63a6c) Thanks [@borisno2](https://github.com/borisno2)! - # Add MCP Server for AI-Assisted Development + + ## New Features + + ### CLI Package (@opensaas/stack-cli) + - **New `opensaas mcp` command group** for AI-assisted development: + - `opensaas mcp install` - Install MCP server in Claude Code + - `opensaas mcp uninstall` - Remove MCP server from Claude Code + - `opensaas mcp start` - Start MCP server directly (for debugging) + - **Feature-driven development tools**: + - Interactive feature implementation wizards (authentication, blog, comments, file-upload, semantic-search) + - Live documentation search from stack.opensaas.au + - Code generation following OpenSaaS best practices + - Smart feature suggestions based on your current app + - Config validation + - **MCP tools available in Claude Code**: + - `opensaas_implement_feature` - Start feature wizard + - `opensaas_feature_docs` - Search documentation + - `opensaas_list_features` - Browse available features + - `opensaas_suggest_features` - Get personalized recommendations + - `opensaas_validate_feature` - Validate implementations + + ### create-opensaas-app + - **Interactive MCP setup prompt** during project creation + - Option to enable AI development tools automatically + - Automatic installation of MCP server if user opts in + - Helpful instructions if MCP installation is declined or fails + + ## Installation + + Enable AI development tools for an existing project: + + ```bash + npx @opensaas/stack-cli mcp install + ``` + + Or during project creation: + + ```bash + npm create opensaas-app@latest my-app + # When prompted: Enable AI development tools? → yes + ``` + + ## Benefits + - **Build apps faster**: Describe what you want to build, get complete implementations + - **Feature-driven development**: Work with high-level features instead of low-level config + - **Best practices baked in**: Generated code follows OpenSaaS Stack patterns + - **Live documentation**: Always up-to-date docs from the official site + - **Single toolkit**: All developer commands in one CLI + + ## Example Usage + + With Claude Code installed and the MCP server enabled, you can: + + ``` + You: "I want to build a food tracking app" + + Claude Code uses MCP tools to: + 1. Ask clarifying questions about requirements + 2. Implement authentication feature (wizard) + 3. Create custom Food and FoodLog lists + 4. Generate complete code with UI and access control + 5. Provide testing and deployment guidance + ``` + ## 0.1.7 ## 0.1.6 diff --git a/packages/create-opensaas-app/package.json b/packages/create-opensaas-app/package.json index c6c50bba..34a82b43 100644 --- a/packages/create-opensaas-app/package.json +++ b/packages/create-opensaas-app/package.json @@ -1,6 +1,6 @@ { "name": "create-opensaas-app", - "version": "0.1.7", + "version": "0.2.0", "description": "Create a new OpenSaas Stack application", "type": "module", "bin": { diff --git a/packages/rag/CHANGELOG.md b/packages/rag/CHANGELOG.md index 6614decf..2031554e 100644 --- a/packages/rag/CHANGELOG.md +++ b/packages/rag/CHANGELOG.md @@ -1,5 +1,135 @@ # @opensaas/stack-rag +## 0.2.0 + +### Patch Changes + +- [#132](https://github.com/OpenSaasAU/stack/pull/132) [`fcf5cb8`](https://github.com/OpenSaasAU/stack/commit/fcf5cb8bbd55d802350b8d97e342dd7f6368163b) Thanks [@borisno2](https://github.com/borisno2)! - Upgrade to Prisma 7 with database adapter support + + ## Breaking Changes + + ### Required `prismaClientConstructor` + + Prisma 7 requires database adapters. All configs must now include `prismaClientConstructor`: + + ```typescript + import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3' + import Database from 'better-sqlite3' + + export default config({ + db: { + provider: 'sqlite', + prismaClientConstructor: (PrismaClient) => { + const db = new Database(process.env.DATABASE_URL || './dev.db') + const adapter = new PrismaBetterSQLite3(db) + return new PrismaClient({ adapter }) + }, + }, + }) + ``` + + ### Removed `url` from `DatabaseConfig` + + The `url` field has been removed from the `DatabaseConfig` type. Database connection URLs are now passed directly to adapters in `prismaClientConstructor`: + + ```typescript + // ❌ Before (Prisma 6) + db: { + provider: 'sqlite', + url: 'file:./dev.db', // url in config + } + + // ✅ After (Prisma 7) + db: { + provider: 'sqlite', + prismaClientConstructor: (PrismaClient) => { + const adapter = new PrismaBetterSQLite3({ url: './dev.db' }) // url in adapter + return new PrismaClient({ adapter }) + }, + } + ``` + + ### Generated Schema Changes + - Generator provider changed from `prisma-client-js` to `prisma-client` + - Removed `url` field from datasource block + - Database URL now passed via adapter in `prismaClientConstructor` + + ### Required Dependencies + + Install the appropriate adapter for your database: + - **SQLite**: `@prisma/adapter-better-sqlite3` + `better-sqlite3` + - **PostgreSQL**: `@prisma/adapter-pg` + `pg` + - **MySQL**: `@prisma/adapter-mysql` + `mysql2` + + ## Migration Steps + 1. Install Prisma 7 and adapter: + + ```bash + pnpm add @prisma/client@7 @prisma/adapter-better-sqlite3 better-sqlite3 + pnpm add -D prisma@7 + ``` + + 2. Update your `opensaas.config.ts` to include `prismaClientConstructor` (see example above) + 3. Regenerate schema and client: + + ```bash + pnpm generate + npx prisma generate + ``` + + 4. Push schema to database: + ```bash + pnpm db:push + ``` + + See the updated documentation in CLAUDE.md for more examples including PostgreSQL and custom adapters. + +- [#107](https://github.com/OpenSaasAU/stack/pull/107) [`f4f3966`](https://github.com/OpenSaasAU/stack/commit/f4f3966faedba07d2cf412fab826d81e30c63a6c) Thanks [@borisno2](https://github.com/borisno2)! - Add strict typing for plugin runtime services + + This change implements fully typed plugin runtime services, providing autocomplete and type safety for `context.plugins` throughout the codebase. + + **Core Changes:** + - Extended `Plugin` type with optional `runtimeServiceTypes` metadata for type-safe code generation + - Converted `OpenSaasConfig` and `AccessContext` from `type` to `interface` to enable module augmentation + - Plugins can now declare their runtime service type information + + **Auth Plugin:** + - Added `AuthRuntimeServices` interface defining runtime service types + - Exported runtime types from package + - Users now get full autocomplete for `context.plugins.auth.getUser()` and `context.plugins.auth.getCurrentUser()` + + **RAG Plugin:** + - Added `RAGRuntimeServices` interface defining runtime service types + - Exported runtime types from package + - Users now get full autocomplete for `context.plugins.rag.generateEmbedding()` and `context.plugins.rag.generateEmbeddings()` + + **CLI Generator:** + - Enhanced plugin types generator to import and use plugin runtime service types + - Generated `.opensaas/plugin-types.ts` now includes proper type imports + - `PluginServices` interface extends `Record | undefined>` for type compatibility + - Maintains backwards compatibility with plugins that don't provide type metadata + + **UI Package:** + - Updated `AdminUI` props to accept contexts with typed plugin services + - Ensures compatibility between generated context types and UI components + + **Benefits:** + - Full TypeScript autocomplete for all plugin runtime methods + - Compile-time type checking catches errors early + - Better IDE experience with hover documentation and jump-to-definition + - Backwards compatible - third-party plugins without type metadata continue to work + - Zero type errors in examples + + **Example:** + + ```typescript + const context = await getContext() + + // Fully typed with autocomplete + context.plugins.auth.getUser('123') // (userId: string) => Promise + context.plugins.rag.generateEmbedding('text') // (text: string, providerName?: string) => Promise + ``` + ## 0.1.7 ### Patch Changes diff --git a/packages/rag/package.json b/packages/rag/package.json index b52cc8f8..5f979997 100644 --- a/packages/rag/package.json +++ b/packages/rag/package.json @@ -1,6 +1,6 @@ { "name": "@opensaas/stack-rag", - "version": "0.1.7", + "version": "0.2.0", "description": "RAG and AI embeddings integration for OpenSaas Stack", "type": "module", "main": "./dist/index.js", diff --git a/packages/storage-s3/CHANGELOG.md b/packages/storage-s3/CHANGELOG.md index d82d8760..b37948cd 100644 --- a/packages/storage-s3/CHANGELOG.md +++ b/packages/storage-s3/CHANGELOG.md @@ -1,5 +1,12 @@ # @opensaas/stack-storage-s3 +## 0.2.0 + +### Patch Changes + +- Updated dependencies []: + - @opensaas/stack-storage@0.2.0 + ## 0.1.7 ### Patch Changes diff --git a/packages/storage-s3/package.json b/packages/storage-s3/package.json index ad1588a9..c8c93a3c 100644 --- a/packages/storage-s3/package.json +++ b/packages/storage-s3/package.json @@ -1,6 +1,6 @@ { "name": "@opensaas/stack-storage-s3", - "version": "0.1.7", + "version": "0.2.0", "description": "AWS S3 storage provider for OpenSaas Stack file uploads", "type": "module", "exports": { diff --git a/packages/storage-vercel/CHANGELOG.md b/packages/storage-vercel/CHANGELOG.md index edd00b86..7763ebaa 100644 --- a/packages/storage-vercel/CHANGELOG.md +++ b/packages/storage-vercel/CHANGELOG.md @@ -1,5 +1,12 @@ # @opensaas/stack-storage-vercel +## 0.2.0 + +### Patch Changes + +- Updated dependencies []: + - @opensaas/stack-storage@0.2.0 + ## 0.1.7 ### Patch Changes diff --git a/packages/storage-vercel/package.json b/packages/storage-vercel/package.json index 445bcc50..920d0cc5 100644 --- a/packages/storage-vercel/package.json +++ b/packages/storage-vercel/package.json @@ -1,6 +1,6 @@ { "name": "@opensaas/stack-storage-vercel", - "version": "0.1.7", + "version": "0.2.0", "description": "Vercel Blob storage provider for OpenSaas Stack file uploads", "type": "module", "exports": { diff --git a/packages/storage/CHANGELOG.md b/packages/storage/CHANGELOG.md index 91d3ad64..4fe85170 100644 --- a/packages/storage/CHANGELOG.md +++ b/packages/storage/CHANGELOG.md @@ -1,5 +1,7 @@ # @opensaas/stack-storage +## 0.2.0 + ## 0.1.7 ### Patch Changes diff --git a/packages/storage/package.json b/packages/storage/package.json index d5ff1b02..95d4b446 100644 --- a/packages/storage/package.json +++ b/packages/storage/package.json @@ -1,6 +1,6 @@ { "name": "@opensaas/stack-storage", - "version": "0.1.7", + "version": "0.2.0", "description": "File and image upload field types with pluggable storage providers for OpenSaas Stack", "type": "module", "exports": { diff --git a/packages/tiptap/CHANGELOG.md b/packages/tiptap/CHANGELOG.md index 274af87d..c517896f 100644 --- a/packages/tiptap/CHANGELOG.md +++ b/packages/tiptap/CHANGELOG.md @@ -1,5 +1,7 @@ # @opensaas/stack-tiptap +## 0.2.0 + ## 0.1.7 ### Patch Changes diff --git a/packages/tiptap/package.json b/packages/tiptap/package.json index de8094f2..a27c147f 100644 --- a/packages/tiptap/package.json +++ b/packages/tiptap/package.json @@ -1,6 +1,6 @@ { "name": "@opensaas/stack-tiptap", - "version": "0.1.7", + "version": "0.2.0", "description": "Tiptap rich text editor integration for OpenSaas Stack", "type": "module", "main": "./dist/index.js", diff --git a/packages/ui/CHANGELOG.md b/packages/ui/CHANGELOG.md index b24c4b47..32a64c07 100644 --- a/packages/ui/CHANGELOG.md +++ b/packages/ui/CHANGELOG.md @@ -1,5 +1,7 @@ # @opensaas/stack-ui +## 0.2.0 + ## 0.1.7 ### Patch Changes diff --git a/packages/ui/package.json b/packages/ui/package.json index b8121311..335f9f0b 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -1,6 +1,6 @@ { "name": "@opensaas/stack-ui", - "version": "0.1.7", + "version": "0.2.0", "description": "Composable React UI components for OpenSaas Stack", "type": "module", "main": "./dist/index.js",