lean-spec 0.2.5-dev.20251124050427 → 0.2.5-dev.20251124054130

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,55 +0,0 @@
1
- # Email Notifications Demo
2
-
3
- > **Tutorial**: [Your First Feature with AI](https://leanspec.dev/docs/tutorials/first-feature)
4
-
5
- ## Scenario
6
-
7
- You're building a user management API. Currently, when users register, their data is stored but they don't receive any confirmation. You need to add email notifications to improve the user experience.
8
-
9
- ## What's Here
10
-
11
- A minimal Express.js API with:
12
- - User registration endpoint (`POST /users`)
13
- - User listing endpoint (`GET /users`)
14
- - In-memory data store (no database needed)
15
- - Basic validation
16
-
17
- **Files:**
18
- - `src/server.js` - Express app with user routes
19
- - `src/users.js` - User management logic
20
- - `src/storage.js` - Simple in-memory storage
21
-
22
- ## Getting Started
23
-
24
- ```bash
25
- # Install dependencies
26
- npm install
27
-
28
- # Start the server
29
- npm start
30
-
31
- # In another terminal, try it out:
32
- curl -X POST http://localhost:3000/users \
33
- -H "Content-Type: application/json" \
34
- -d '{"name": "Alice", "email": "alice@example.com"}'
35
- ```
36
-
37
- ## Your Mission
38
-
39
- Add email notifications when users register. Follow the tutorial and ask your AI assistant:
40
-
41
- > "Help me add email notifications to this app using LeanSpec. When a user registers, send them a welcome email."
42
-
43
- The AI will guide you through:
44
- 1. Creating a spec for the feature
45
- 2. Designing the email notification system
46
- 3. Implementing the code
47
- 4. Testing it works
48
-
49
- ## Current Limitations
50
-
51
- - No email service configured (you'll add this)
52
- - No retry logic for failed sends
53
- - No email templates
54
-
55
- These are perfect opportunities to practice spec-driven development!
@@ -1,57 +0,0 @@
1
- import express from 'express';
2
- import { createUser, getAllUsers } from './users.js';
3
-
4
- const app = express();
5
- const PORT = 3000;
6
-
7
- app.use(express.json());
8
-
9
- // Health check
10
- app.get('/', (req, res) => {
11
- res.json({
12
- status: 'ok',
13
- message: 'User Management API',
14
- version: '1.0.0'
15
- });
16
- });
17
-
18
- // Get all users
19
- app.get('/users', (req, res) => {
20
- const users = getAllUsers();
21
- res.json({ users, count: users.length });
22
- });
23
-
24
- // Register new user
25
- app.post('/users', async (req, res) => {
26
- const { name, email } = req.body;
27
-
28
- // Basic validation
29
- if (!name || !email) {
30
- return res.status(400).json({
31
- error: 'Name and email are required'
32
- });
33
- }
34
-
35
- if (!email.includes('@')) {
36
- return res.status(400).json({
37
- error: 'Invalid email format'
38
- });
39
- }
40
-
41
- try {
42
- const user = await createUser({ name, email });
43
- res.status(201).json({
44
- message: 'User created successfully',
45
- user
46
- });
47
- } catch (error) {
48
- res.status(400).json({
49
- error: error.message
50
- });
51
- }
52
- });
53
-
54
- app.listen(PORT, () => {
55
- console.log(`Server running on http://localhost:${PORT}`);
56
- console.log('Try: POST /users with {"name": "Alice", "email": "alice@example.com"}');
57
- });
@@ -1,40 +0,0 @@
1
- /**
2
- * Simple in-memory storage for users
3
- * In a real app, this would be a database
4
- */
5
-
6
- const users = [];
7
-
8
- /**
9
- * Save a user to storage
10
- * @param {Object} user - User object to save
11
- */
12
- export function saveUser(user) {
13
- users.push(user);
14
- }
15
-
16
- /**
17
- * Get all users
18
- * @returns {Array<Object>} List of all users
19
- */
20
- export function getUsers() {
21
- return [...users]; // Return a copy
22
- }
23
-
24
- /**
25
- * Find user by email
26
- * @param {string} email - Email to search for
27
- * @returns {Object|undefined} User if found
28
- */
29
- export function findUserByEmail(email) {
30
- return users.find(u => u.email === email);
31
- }
32
-
33
- /**
34
- * Find user by ID
35
- * @param {string} id - User ID to search for
36
- * @returns {Object|undefined} User if found
37
- */
38
- export function findUserById(id) {
39
- return users.find(u => u.id === id);
40
- }
@@ -1,38 +0,0 @@
1
- import { saveUser, findUserByEmail, getUsers } from './storage.js';
2
-
3
- /**
4
- * Create a new user
5
- * @param {Object} userData - User data
6
- * @param {string} userData.name - User's name
7
- * @param {string} userData.email - User's email
8
- * @returns {Promise<Object>} Created user
9
- */
10
- export async function createUser({ name, email }) {
11
- // Check for duplicate email
12
- const existing = findUserByEmail(email);
13
- if (existing) {
14
- throw new Error('Email already registered');
15
- }
16
-
17
- const user = {
18
- id: Date.now().toString(),
19
- name,
20
- email,
21
- createdAt: new Date().toISOString()
22
- };
23
-
24
- saveUser(user);
25
-
26
- // TODO: Send welcome email
27
- // This is where you'll add email notification logic!
28
-
29
- return user;
30
- }
31
-
32
- /**
33
- * Get all users
34
- * @returns {Array<Object>} List of users
35
- */
36
- export function getAllUsers() {
37
- return getUsers();
38
- }