import { createApiSimulator } from '@x12i/api-simulator'; import { books } from './data/books.js'; import { members } from './data/members.js'; import { getBook } from './simulations/get-book.js'; import { searchBooks } from './simulations/search-books.js'; import { checkout } from './simulations/checkout-book.js'; import { returnBookHandler } from './simulations/return-book.js'; import { memberCheckouts } from './simulations/member-checkouts.js'; import { getMember } from './simulations/get-member.js'; /** * The library demo, in the structure the README recommends for a real * provider simulator: static/reference `data` in its own module, business * logic in `simulations/`, and this file wiring both up to endpoints. Two * APIs are combined into a single simulator here to show that composition, * with their own `basePath`s and independent internal `data`. */ export const simulator = createApiSimulator({ apis: [ { id: 'library-api', basePath: '/api/v1/library', data: { books }, endpoints: [ { id: 'health', method: 'GET', path: '/health', behavior: { type: 'fixed', response: { status: 200, body: { status: 'ok', service: 'library-simulator' } } } }, { id: 'list-books', method: 'GET', path: '/books', behavior: { type: 'relative', response: { body: { items: '{{data.books}}' } } } }, // Registered before /books/:bookId, but declaration order doesn't // matter -- static routes are always tried before parameter routes. { id: 'search-books', method: 'GET', path: '/books/search', delayMs: 150, behavior: { type: 'simulation', handler: searchBooks } }, { id: 'get-book', method: 'GET', path: '/books/:bookId', behavior: { type: 'simulation', handler: getBook } }, { id: 'book-shelf-note', method: 'GET', path: '/books/:bookId/shelf-note', behavior: { type: 'relative', strict: false, response: { body: { bookId: '{{request.params.bookId}}', note: 'Shelf note: {{request.headers.x-shelf-note}}' } } } }, { id: 'checkout-book', method: 'POST', path: '/books/:bookId/checkout', behavior: { type: 'simulation', handler: checkout } }, { id: 'return-book', method: 'POST', path: '/books/:bookId/return', behavior: { type: 'simulation', handler: returnBookHandler } } ] }, { id: 'members-api', basePath: '/api/v1', data: { members }, endpoints: [ { id: 'list-members', method: 'GET', path: '/members', behavior: { type: 'relative', response: { body: { items: '{{data.members}}' } } } }, { id: 'get-member', method: 'GET', path: '/members/:memberId', behavior: { type: 'simulation', handler: getMember } }, { id: 'member-checkouts', method: 'GET', path: '/members/:memberId/checkouts', behavior: { type: 'simulation', handler: memberCheckouts } } ] } ] });