{"_id":"@dbs-portal/tool-mock","_rev":"3-31209277d710c4fdabd3c01a959c17f7","name":"@dbs-portal/tool-mock","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"@dbs-portal/tool-mock","version":"1.0.0","keywords":["msw","mock","api","testing","development","dbs-portal","monorepo"],"author":{"name":"DBS Portal Team"},"license":"MIT","_id":"@dbs-portal/tool-mock@1.0.0","maintainers":[{"name":"longvq","email":"vqlong1604@gmail.com"}],"homepage":"https://github.com/your-org/dbs-portal#readme","bugs":{"url":"https://github.com/your-org/dbs-portal/issues"},"dist":{"shasum":"6246afdd9d5ff69cc9626a63531cd61b930c003d","tarball":"https://registry.npmjs.org/@dbs-portal/tool-mock/-/tool-mock-1.0.0.tgz","fileCount":228,"integrity":"sha512-0sLkWhOvECu+Bm6DaGJTpdDZbh8B7nHOZwofX1lMvQyCjoWKQXwZPBgS5M6vDVZD1ziLaSaPP3CgkENnF1urwA==","signatures":[{"sig":"MEQCIAlASvdlY+QYArew+AHsNzs4vQwKjgl1iHSe1WEEEAz/AiAnmW+OqIas5JvolY+CF0G65PShlzLqVAGfnhxsNxJzxA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":2712659},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./core":{"types":"./dist/core/index.d.ts","import":"./dist/core/index.js"},"./build":{"types":"./dist/build/index.d.ts","import":"./dist/build/index.js"},"./testing":{"types":"./dist/testing/index.d.ts","import":"./dist/testing/index.js"},"./handlers":{"types":"./dist/handlers/index.d.ts","import":"./dist/handlers/index.js"},"./factories":{"types":"./dist/factories/index.d.ts","import":"./dist/factories/index.js"},"./integration":{"types":"./dist/integration/index.d.ts","import":"./dist/integration/index.js"},"./vite-plugin":{"types":"./dist/build/vite-plugin.d.ts","import":"./dist/build/vite-plugin.js"}},"gitHead":"9452c55773023315a6ee6224db3f064b9ee028c4","scripts":{"dev":"tsc --watch","lint":"biome lint src","test":"vitest run","build":"tsc && vite build","clean":"rm -rf dist","format":"biome format src --write","test:watch":"vitest","type-check":"tsc --noEmit","test:coverage":"vitest run --coverage","prepublishOnly":"yarn build"},"_npmUser":{"name":"longvq","email":"vqlong1604@gmail.com"},"repository":{"url":"git+https://github.com/your-org/dbs-portal.git","type":"git","directory":"packages/tools/mock"},"_npmVersion":"10.8.2","description":"API mocking toolkit using MSW for DBS Portal development workflows","directories":{},"_nodeVersion":"20.19.0","dependencies":{"msw":"^2.6.4","zod":"^3.24.1","uuid":"^11.0.3","date-fns":"^4.1.0","lodash-es":"^4.17.21","@dbs-portal/core-api":"workspace:*","@dbs-portal/core-auth":"workspace:*","@dbs-portal/core-shared":"workspace:*"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"devDependencies":{"vite":"^6.1.0","vitest":"^3.0.5","typescript":"^5.7.2","@types/node":"^22.10.2","@types/uuid":"^10.0.0","@biomejs/biome":"1.9.4","@types/lodash-es":"^4.17.12","@vitejs/plugin-react":"^4.3.4","@dbs-portal/tool-build":"workspace:*","@dbs-portal/tool-tsconfig":"workspace:*"},"peerDependencies":{"react":"^18.0.0","react-dom":"^18.0.0"},"peerDependenciesMeta":{"react":{"optional":true},"react-dom":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/tool-mock_1.0.0_1754541057812_0.5489880987883726","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@dbs-portal/tool-mock","version":"1.0.1","keywords":["msw","mock","api","testing","development","dbs-portal","monorepo"],"author":{"name":"DBS Portal Team"},"license":"MIT","_id":"@dbs-portal/tool-mock@1.0.1","maintainers":[{"name":"longvq","email":"vqlong1604@gmail.com"}],"homepage":"https://github.com/your-org/dbs-portal#readme","bugs":{"url":"https://github.com/your-org/dbs-portal/issues"},"dist":{"shasum":"79b8df63c02cd9ca349524450435d9ddc1c144d3","tarball":"https://registry.npmjs.org/@dbs-portal/tool-mock/-/tool-mock-1.0.1.tgz","fileCount":226,"integrity":"sha512-wHwdw1ySWshWs4HLPINpUHqO+vI6lmfqC1FyN8uZ++HtNNnsMlqYNB4LkyEFUKOS/8G7ry7NG+cX2WvncjgpOQ==","signatures":[{"sig":"MEUCIGYLhHmivPPQaqxA4IqhusYE0ythUuzejxXmXP+v9szSAiEAw6B6GtuuF0TOTRb4qQufK5EtPPnFzQAipVQe/MQ0vDg=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":1257502},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"gitHead":"9452c55773023315a6ee6224db3f064b9ee028c4","scripts":{"dev":"tsc --watch","lint":"biome lint src","test":"vitest run","build":"tsc && vite build","clean":"rm -rf dist","format":"biome format src --write","test:watch":"vitest","type-check":"tsc --noEmit","test:coverage":"vitest run --coverage","prepublishOnly":"yarn build"},"_npmUser":{"name":"longvq","email":"vqlong1604@gmail.com"},"repository":{"url":"git+https://github.com/your-org/dbs-portal.git","type":"git","directory":"packages/tools/mock"},"_npmVersion":"10.8.2","description":"API mocking toolkit using MSW for DBS Portal development workflows","directories":{},"_nodeVersion":"20.19.0","dependencies":{"msw":"^2.6.4","zod":"^3.24.1","uuid":"^11.0.3","date-fns":"^4.1.0","lodash-es":"^4.17.21","@dbs-portal/core-api":"workspace:*","@dbs-portal/core-auth":"workspace:*","@dbs-portal/tool-mock":"^1.0.0","@dbs-portal/core-shared":"workspace:*"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"devDependencies":{"vite":"^6.1.0","vitest":"^3.0.5","typescript":"^5.7.2","@types/node":"^22.10.2","@types/uuid":"^10.0.0","@biomejs/biome":"1.9.4","@types/lodash-es":"^4.17.12","@vitejs/plugin-react":"^4.3.4","@dbs-portal/tool-build":"workspace:*","@dbs-portal/tool-tsconfig":"workspace:*"},"peerDependencies":{"react":"^18.0.0","react-dom":"^18.0.0"},"peerDependenciesMeta":{"react":{"optional":true},"react-dom":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/tool-mock_1.0.1_1754547169338_0.9190334250899663","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@dbs-portal/tool-mock","version":"1.0.2","description":"API mocking toolkit using MSW for DBS Portal development workflows","type":"module","main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"import":"./dist/index.js","types":"./dist/index.d.ts"}},"scripts":{"build":"tsc && vite build","dev":"tsc --watch","test":"vitest run","test:watch":"vitest","test:coverage":"vitest run --coverage","lint":"biome lint src","format":"biome format src --write","type-check":"tsc --noEmit","clean":"rm -rf dist","prepublishOnly":"yarn build"},"dependencies":{"@dbs-portal/core-api":"workspace:*","@dbs-portal/core-auth":"workspace:*","@dbs-portal/core-shared":"workspace:*","@dbs-portal/tool-mock":"^1.0.0","date-fns":"^4.1.0","lodash-es":"^4.17.21","msw":"^2.6.4","uuid":"^11.0.3","zod":"^3.24.1"},"devDependencies":{"@biomejs/biome":"1.9.4","@dbs-portal/tool-build":"workspace:*","@dbs-portal/tool-tsconfig":"workspace:*","@types/lodash-es":"^4.17.12","@types/node":"^22.10.2","@types/uuid":"^10.0.0","@vitejs/plugin-react":"^4.3.4","typescript":"^5.7.2","vite":"^6.1.0","vitest":"^3.0.5"},"peerDependencies":{"react":"^18.0.0","react-dom":"^18.0.0"},"peerDependenciesMeta":{"react":{"optional":true},"react-dom":{"optional":true}},"keywords":["msw","mock","api","testing","development","dbs-portal","monorepo"],"author":{"name":"DBS Portal Team"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/your-org/dbs-portal.git","directory":"packages/tools/mock"},"bugs":{"url":"https://github.com/your-org/dbs-portal/issues"},"homepage":"https://github.com/your-org/dbs-portal#readme","publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"_id":"@dbs-portal/tool-mock@1.0.2","gitHead":"9452c55773023315a6ee6224db3f064b9ee028c4","_nodeVersion":"20.19.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-ww3Q93pK2/3Z3Vt9vtSql2Gnq0CK16nNlfWh+wdeaA2XQkMbR16a/hh4dneWR7z9v0Nmt0AwJPw5n5lKEIPZqQ==","shasum":"c394e03ac16af253d8445ca0fcb8e3ef1408b957","tarball":"https://registry.npmjs.org/@dbs-portal/tool-mock/-/tool-mock-1.0.2.tgz","fileCount":226,"unpackedSize":1257502,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDIOswGJyGNvxVeBxLtwKe+28zHyqJ2qPFSzoxZQQw/1AIgYSbi+DzZyC/rRsFKbMBNyzoUS6wLi2yLYCQHh/Xnc8s="}]},"_npmUser":{"name":"longvq","email":"vqlong1604@gmail.com"},"directories":{},"maintainers":[{"name":"longvq","email":"vqlong1604@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/tool-mock_1.0.2_1754547369633_0.22989049945142703"},"_hasShrinkwrap":false}},"time":{"created":"2025-08-07T04:30:57.690Z","modified":"2025-08-07T06:16:10.008Z","1.0.0":"2025-08-07T04:30:58.060Z","1.0.1":"2025-08-07T06:12:49.542Z","1.0.2":"2025-08-07T06:16:09.841Z"},"bugs":{"url":"https://github.com/your-org/dbs-portal/issues"},"author":{"name":"DBS Portal Team"},"license":"MIT","homepage":"https://github.com/your-org/dbs-portal#readme","keywords":["msw","mock","api","testing","development","dbs-portal","monorepo"],"repository":{"type":"git","url":"git+https://github.com/your-org/dbs-portal.git","directory":"packages/tools/mock"},"description":"API mocking toolkit using MSW for DBS Portal development workflows","maintainers":[{"name":"longvq","email":"vqlong1604@gmail.com"}],"readme":"# @dbs-portal/tool-mock\n\nA comprehensive API mocking toolkit for the DBS Portal monorepo, built on top of Mock Service Worker (MSW). This package provides developer-friendly tools for creating reliable API simulations that accelerate development workflows without requiring backend services.\n\n## 🚀 Features\n\n### Core Capabilities\n- **Environment-Aware Setup**: Automatically enables/disables based on environment (development, testing, production)\n- **Type-Safe Mocking**: Full TypeScript support with existing API contracts and response types\n- **Zero Configuration**: Works out-of-the-box with sensible defaults and automatic environment detection\n- **Seamless Integration**: Built-in integration with @dbs-portal/core-api and @dbs-portal/core-auth packages\n\n### Developer Experience\n- **Easy API Switching**: Toggle between real APIs and mocked APIs with environment variables\n- **CRUD Templates**: Pre-built handler factories for common CRUD operations\n- **Data Factories**: Realistic mock data generation with customizable factories\n- **Error Simulation**: Network conditions, timeouts, and error scenario testing\n- **Hot Reloading**: Dynamic handler updates during development\n\n### Build System Integration\n- **Vite Plugin**: Seamless integration with Vite development server\n- **Turborepo Support**: Optimized for monorepo build workflows\n- **Service Worker Management**: Automatic MSW service worker setup and management\n- **Development Server**: Built-in development server with MSW integration\n\n### Testing & Quality\n- **Testing Utilities**: Comprehensive test helpers and assertions\n- **Storybook Integration**: Easy component development with mocked APIs\n- **Performance Monitoring**: Request/response timing and performance metrics\n- **Debug Tools**: Detailed logging and debugging capabilities\n\n## 🏗️ Architecture\n\n### Package Structure\n```\npackages/tools/mock/\n├── src/\n│   ├── core/           # Core MSW setup and configuration\n│   ├── handlers/       # Handler factories and management\n│   ├── factories/      # Mock data generation\n│   ├── integration/    # Core package integrations\n│   ├── build/          # Build system utilities\n│   ├── testing/        # Testing utilities\n│   └── utils/          # Shared utilities\n├── templates/          # Template files and examples\n├── docs/              # Additional documentation\n└── examples/          # Usage examples\n```\n\n### Core Components\n\n#### 1. Setup & Configuration\n- **Environment Detection**: Automatic browser/Node.js environment detection\n- **Configuration Management**: Centralized configuration with environment overrides\n- **MSW Initialization**: Browser and Node.js MSW setup with proper lifecycle management\n\n#### 2. Handler System\n- **Handler Registry**: Centralized handler management with dynamic registration\n- **Factory Functions**: Type-safe handler creation for common patterns\n- **CRUD Handlers**: Pre-built handlers for Create, Read, Update, Delete operations\n- **Auth Handlers**: Authentication and authorization mocking utilities\n\n#### 3. Data Generation\n- **Mock Factories**: Realistic data generation with customizable overrides\n- **Response Builder**: Fluent API for building complex mock responses\n- **Pagination Support**: Built-in pagination handling for list endpoints\n- **Validation**: Request/response validation with schema support\n\n#### 4. Integration Layer\n- **API Client Integration**: Seamless integration with @dbs-portal/core-api\n- **Auth Integration**: Authentication mocking with @dbs-portal/core-auth\n- **React Query Support**: Optimized for TanStack Query workflows\n- **Zustand Integration**: State management integration for mock data\n\n## 🛠️ Usage Patterns\n\n### Quick Start\n```typescript\nimport { setupMocks, createCrudHandlers } from '@dbs-portal/tool-mock'\n\n// Auto-setup based on environment\nawait setupMocks()\n\n// Create CRUD handlers for a resource\nconst userHandlers = createCrudHandlers({\n  basePath: '/api/users',\n  dataFactory: (overrides = {}) => ({\n    id: generateId(),\n    email: 'user@example.com',\n    firstName: 'John',\n    lastName: 'Doe',\n    ...overrides,\n  }),\n})\n```\n\n### Environment Configuration\n```bash\n# Enable MSW in development\nVITE_ENABLE_MOCKING=true\n\n# Set mock mode\nVITE_MOCK_MODE=development\n\n# Configure response delay\nVITE_MOCK_DELAY=300\n\n# Enable detailed logging\nVITE_MOCK_LOGGING=true\n```\n\n### Advanced Usage\n```typescript\nimport { \n  createMockAwareApiClient,\n  createAuthHandlers,\n  mockResponseBuilder \n} from '@dbs-portal/tool-mock'\n\n// Create API client with MSW integration\nconst apiClient = await createMockAwareApiClient({\n  baseURL: '/api',\n  enableMocking: true,\n  mockHandlers: [\n    ...createAuthHandlers('/api/auth'),\n    ...createCrudHandlers({\n      basePath: '/api/products',\n      dataFactory: productFactory,\n      pagination: { defaultPageSize: 20 },\n    }),\n  ],\n})\n\n// Custom response building\nconst customHandler = http.get('/api/custom', () => {\n  return mockResponseBuilder()\n    .data({ message: 'Custom response' })\n    .status(200)\n    .delay([100, 300])\n    .build()\n})\n```\n\n## 🔧 Integration with Core Packages\n\n### @dbs-portal/core-api Integration\n- **HTTP Client Mocking**: Seamless integration with existing HTTP client\n- **Request Interceptors**: Automatic request/response interception\n- **Query Key Compatibility**: Maintains existing React Query key structures\n- **Error Handling**: Consistent error handling with real API patterns\n\n### @dbs-portal/core-auth Integration\n- **Authentication Mocking**: JWT token simulation and validation\n- **Authorization Testing**: Role and permission-based access control\n- **Session Management**: Mock session lifecycle and token refresh\n- **User Context**: Realistic user data and authentication state\n\n## 📦 Monorepo Integration\n\n### Package Dependencies\n```json\n{\n  \"dependencies\": {\n    \"@dbs-portal/core-api\": \"workspace:*\",\n    \"@dbs-portal/core-auth\": \"workspace:*\",\n    \"@dbs-portal/core-shared\": \"workspace:*\",\n    \"msw\": \"^2.0.0\"\n  }\n}\n```\n\n### Build System\n- **Turborepo Integration**: Optimized build caching and task dependencies\n- **TypeScript Compilation**: Proper type generation and distribution\n- **Vite Configuration**: Development and build optimization\n- **Package Boundaries**: Strict import/export boundaries with other packages\n\n### Development Workflow\n1. **Package Installation**: Automatic MSW service worker setup\n2. **Development Server**: Integrated with Vite dev server\n3. **Hot Reloading**: Dynamic handler updates without restart\n4. **Testing**: Seamless test environment setup\n\n## 🎯 Design Principles\n\n### Developer-First\n- **Minimal Configuration**: Works with zero setup for common use cases\n- **Intuitive API**: Clear, discoverable API surface with TypeScript support\n- **Fast Feedback**: Immediate visual feedback for API changes\n- **Error Prevention**: Type safety and validation to prevent common mistakes\n\n### Production-Ready\n- **Performance**: Optimized for development speed without production impact\n- **Reliability**: Robust error handling and graceful degradation\n- **Security**: No production code inclusion and secure development practices\n- **Maintainability**: Clean architecture and comprehensive documentation\n\n### Extensible\n- **Plugin System**: Extensible handler and factory system\n- **Custom Integrations**: Easy integration with custom API patterns\n- **Framework Agnostic**: Core utilities work with any frontend framework\n- **Future-Proof**: Designed for easy updates and feature additions\n\n## 📚 Documentation Structure\n\n- **README.md**: Overview and quick start guide\n- **API.md**: Comprehensive API reference\n- **INTEGRATION.md**: Integration guides for core packages\n- **EXAMPLES.md**: Real-world usage examples\n- **MIGRATION.md**: Migration guide from existing mocking solutions\n- **TROUBLESHOOTING.md**: Common issues and solutions\n\n## 🚦 Getting Started\n\n1. **Installation**: Package is automatically available in the monorepo\n2. **Environment Setup**: Configure environment variables for your needs\n3. **Basic Usage**: Start with auto-setup and default handlers\n4. **Custom Handlers**: Add custom handlers for specific API endpoints\n5. **Integration**: Integrate with existing API clients and authentication\n\nSee the [API documentation](./API.md) for detailed usage instructions and the [examples directory](./examples/) for real-world implementation patterns.\n","readmeFilename":"README.md"}