hazo_config 1.0.0

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.
@@ -0,0 +1,51 @@
1
+ ---
2
+ description: General rules always to be used
3
+ globs: *
4
+ alwaysApply: true
5
+ ---
6
+
7
+ [General]
8
+ - Start all chats wtih 🐸
9
+ - End all chats with 🦊
10
+ - Only implement if you're 90% sure of requirement or the fix. Otherwise ask questions or things for me to check.
11
+ - after making a change, for the pages that had both direct and indirect impact, make a curl request to ensrue there are no errors. Check the terminal as well for errors. Also make sure to test any API endpoints and fix appropriately. If after 3 attempts you cannot fix, provide a summary of the issue and advice on next steps.
12
+
13
+ [Style]
14
+ - Always use snake_case
15
+ - Include a description of purpose of file at top of each new file
16
+ - Include comments at the top of each function or major section of code
17
+ - Add comments for each file and also major section
18
+ - Add a class name identifier for div tags prefixed with "cls_" so that they can be easily identified and searched. Reused divs should have the same name.
19
+
20
+ [UI_Behaviour]
21
+ - All data input fields (not interaction fields), it should be non-editable but there is a lucide pencil icon next to it. When pressed, it'll allow to edit the inptu field, and a lucide circle-check-big will be used for the "Submit"/"save"/"update" button, and a lucide circle-x will be used for the cancel button.
22
+
23
+
24
+ [Technology]
25
+ - use the following tech stack:
26
+ - React
27
+ - Next.js
28
+ - TailwindCSS
29
+ - TypeScript
30
+ - Shadcn/UI
31
+ - use npm shadcn@latest add * to add components. Do not use shadcn-ui
32
+
33
+ [Architecture]
34
+ - store all configuration values in config.ini file. Always put hard coded values that have chance to change in config.ini
35
+ - store any sensitive data in .env file (to be excluded in git)
36
+ - create reusable components to prevent having redundant code and to improve maintainability
37
+ - Ensure you have a minimum of one file per route
38
+ - Group pages into directories for maintainability
39
+
40
+ [Database]
41
+ - database schema can be gound on .cursor/rules/db_schema.md
42
+
43
+ [Logging]
44
+ - use winston as the logging service for backend logging under a filename from config.ini logging.logfile. Hvae a log file per day.
45
+ - When there's an error that happens, always log on the serverside.
46
+ - Use the config.
47
+ - In the logging, always include the filename, line number, message and relevant data to help troubleshoot in future in the json log entry
48
+ - When error messages are shown to the user, they should always be logged verbatem in the serverside log file as well
49
+ - pretty print the json output
50
+ - don't import the logger in the client side code
51
+ - whenever there's any actions on the database, or any API calls, please add details of the payload and update as well as the resulsts in the log file to help debug issues. For API calls, don't save any base64 data as it is too large.
@@ -0,0 +1,33 @@
1
+ import type { StorybookConfig } from '@storybook/react-vite'
2
+ import { mergeConfig } from 'vite'
3
+ import path from 'path'
4
+
5
+ const config: StorybookConfig = {
6
+ stories: ['../src/**/*.stories.@(js|jsx|ts|tsx|mdx)'],
7
+ addons: [
8
+ '@storybook/addon-links',
9
+ '@storybook/addon-essentials',
10
+ '@storybook/addon-interactions',
11
+ ],
12
+ framework: {
13
+ name: '@storybook/react-vite',
14
+ options: {},
15
+ },
16
+ docs: {
17
+ autodocs: 'tag',
18
+ },
19
+ async viteFinal(config) {
20
+ return mergeConfig(config, {
21
+ resolve: {
22
+ alias: {
23
+ '@': path.resolve(__dirname, '../src'),
24
+ },
25
+ },
26
+ optimizeDeps: {
27
+ include: ['@storybook/react'],
28
+ },
29
+ })
30
+ },
31
+ }
32
+ export default config
33
+
@@ -0,0 +1,19 @@
1
+ import type { Preview } from '@storybook/react'
2
+
3
+ // Import global styles
4
+ import '../src/styles/globals.css'
5
+
6
+ const preview: Preview = {
7
+ parameters: {
8
+ actions: { argTypesRegex: '^on[A-Z].*' },
9
+ controls: {
10
+ matchers: {
11
+ color: /(background|color)$/i,
12
+ date: /Date$/i,
13
+ },
14
+ },
15
+ },
16
+ }
17
+
18
+ export default preview
19
+
package/CODE_REVIEW.md ADDED
@@ -0,0 +1,81 @@
1
+ # Code Review Summary
2
+
3
+ ## Overview
4
+ The HazoConfig library has been reviewed and integrated into the component library with Storybook testing support.
5
+
6
+ ## Components Created
7
+
8
+ ### 1. MockConfigProvider (`src/lib/mock_config_provider.ts`)
9
+ - **Purpose**: In-memory config provider for browser/Storybook testing
10
+ - **Features**:
11
+ - Implements `ConfigProvider` interface
12
+ - Stores configuration in memory (no file system dependency)
13
+ - Supports all CRUD operations
14
+ - Includes `getAllSections()` and `reset()` methods for testing
15
+
16
+ ### 2. ConfigViewer (`src/components/config_viewer.tsx`)
17
+ - **Purpose**: Display and edit configuration values with inline editing
18
+ - **Features**:
19
+ - Displays all configuration sections
20
+ - Inline editing with pencil icon (following UI_Behaviour rules)
21
+ - Save/cancel buttons (circle-check-big and circle-x icons)
22
+ - Non-editable display by default
23
+ - Auto-refresh after updates
24
+
25
+ ### 3. ConfigEditor (`src/components/config_editor.tsx`)
26
+ - **Purpose**: Advanced configuration editor with section navigation
27
+ - **Features**:
28
+ - Section sidebar navigation
29
+ - Direct editing of all values
30
+ - Add new key-value pairs
31
+ - Refresh and Save buttons
32
+ - Full-screen layout
33
+
34
+ ## Storybook Stories
35
+
36
+ ### ConfigViewer Stories
37
+ - `Default` - Full sample configuration
38
+ - `DatabaseConfig` - Database section only
39
+ - `LoggingConfig` - Logging section only
40
+ - `ApiConfig` - API section only
41
+ - `EmptyConfig` - Empty configuration
42
+ - `MultipleSections` - Multiple sections example
43
+
44
+ ### ConfigEditor Stories
45
+ - `Default` - Full configuration with all sections
46
+ - `MinimalConfig` - Simple configuration
47
+ - `EmptyConfig` - Empty state
48
+ - `ComplexConfig` - Complex multi-section configuration
49
+
50
+ ## Code Quality
51
+
52
+ ### ✅ Strengths
53
+ 1. **Type Safety**: Full TypeScript support with proper interfaces
54
+ 2. **Code Style**: Follows snake_case convention
55
+ 3. **Documentation**: All files include purpose descriptions and function comments
56
+ 4. **UI Compliance**: Follows UI_Behaviour rules (pencil icon, non-editable by default)
57
+ 5. **Class Naming**: Uses `cls_` prefix for div class names
58
+ 6. **Separation of Concerns**: Mock provider separate from real implementation
59
+
60
+ ### ⚠️ Notes
61
+ 1. **Node.js Dependencies**: The `HazoConfig` class uses Node.js `fs` module and cannot run in browser. This is expected and correct for a Node.js library.
62
+ 2. **Type Definitions**: Added `@types/node` and `@types/ini` to devDependencies for proper TypeScript support.
63
+ 3. **Unused Variable**: `originalContent` in `HazoConfig` is set but not read - this is intentional for future formatting preservation features.
64
+
65
+ ## Dependencies Added
66
+ - `ini` - For INI file parsing
67
+ - `@types/node` - Node.js type definitions
68
+ - `@types/ini` - INI package type definitions
69
+
70
+ ## Testing
71
+ All components are testable in Storybook:
72
+ - Run `npm run storybook` to view and test components
73
+ - All stories use `MockConfigProvider` for browser compatibility
74
+ - Components can be tested with different configuration scenarios
75
+
76
+ ## Next Steps
77
+ 1. Install dependencies: `npm install`
78
+ 2. Run Storybook: `npm run storybook`
79
+ 3. Test components in Storybook interface
80
+ 4. Add more components as needed for config management UI
81
+
package/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # Hazo Config Component Library
2
+
3
+ A React component library for managing configuration with Storybook for component testing and documentation.
4
+
5
+ ## Tech Stack
6
+
7
+ - **React** - UI library
8
+ - **TypeScript** - Type safety
9
+ - **TailwindCSS** - Styling
10
+ - **Shadcn/UI** - Component primitives
11
+ - **Storybook** - Component development and testing
12
+ - **Vite** - Build tool
13
+
14
+ ## Getting Started
15
+
16
+ ### Installation
17
+
18
+ Install dependencies:
19
+
20
+ ```bash
21
+ npm install
22
+ ```
23
+
24
+ ### Development
25
+
26
+ Run Storybook to develop and test components:
27
+
28
+ ```bash
29
+ npm run storybook
30
+ ```
31
+
32
+ This will start Storybook on `http://localhost:6006`
33
+
34
+ ### Building
35
+
36
+ Build the library:
37
+
38
+ ```bash
39
+ npm run build
40
+ ```
41
+
42
+ Build Storybook for static deployment:
43
+
44
+ ```bash
45
+ npm run build-storybook
46
+ ```
47
+
48
+ ## Project Structure
49
+
50
+ ```
51
+ hazo_config/
52
+ ├── src/
53
+ │ ├── components/ # React components
54
+ │ │ ├── example_component.tsx
55
+ │ │ └── example_component.stories.tsx
56
+ │ ├── lib/ # Utility functions
57
+ │ │ └── utils.ts
58
+ │ ├── styles/ # Global styles
59
+ │ │ └── globals.css
60
+ │ └── index.ts # Main entry point
61
+ ├── .storybook/ # Storybook configuration
62
+ ├── components.json # Shadcn/UI configuration
63
+ ├── tailwind.config.js # TailwindCSS configuration
64
+ └── tsconfig.json # TypeScript configuration
65
+ ```
66
+
67
+ ## Adding Components
68
+
69
+ 1. Create your component in `src/components/`
70
+ 2. Create a corresponding `.stories.tsx` file for Storybook
71
+ 3. Export the component from `src/components/index.ts`
72
+ 4. Export from `src/index.ts` to make it available in the library
73
+
74
+ ## Adding Shadcn/UI Components
75
+
76
+ Use the Shadcn CLI to add components:
77
+
78
+ ```bash
79
+ npx shadcn@latest add [component-name]
80
+ ```
81
+
82
+ ## Code Style
83
+
84
+ - Use **snake_case** for file names and variables
85
+ - Include file purpose description at the top of each file
86
+ - Add comments for functions and major code sections
87
+ - Use `cls_` prefix for div class names (e.g., `cls_example_component`)
88
+
89
+ ## License
90
+
91
+ MIT
92
+
@@ -0,0 +1,21 @@
1
+ {
2
+ "$schema": "https://ui.shadcn.com/schema.json",
3
+ "style": "default",
4
+ "rsc": false,
5
+ "tsx": true,
6
+ "tailwind": {
7
+ "config": "tailwind.config.js",
8
+ "css": "src/styles/globals.css",
9
+ "baseColor": "slate",
10
+ "cssVariables": true,
11
+ "prefix": ""
12
+ },
13
+ "aliases": {
14
+ "components": "@/components",
15
+ "utils": "@/lib/utils",
16
+ "ui": "@/components/ui",
17
+ "lib": "@/lib",
18
+ "hooks": "@/hooks"
19
+ }
20
+ }
21
+
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "hazo_config",
3
+ "version": "1.0.0",
4
+ "description": "Config wrapper with error handling",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc -p tsconfig.build.json",
9
+ "storybook": "npx storybook dev -p 6006",
10
+ "build-storybook": "npx storybook build",
11
+ "test": "echo \"Error: no test specified\" && exit 1"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/pub12/hazo_config.git"
16
+ },
17
+ "keywords": [
18
+ "config",
19
+ "manager",
20
+ "config",
21
+ "component-library",
22
+ "react",
23
+ "typescript"
24
+ ],
25
+ "author": "Pubs Abayasiri",
26
+ "license": "MIT",
27
+ "bugs": {
28
+ "url": "https://github.com/pub12/hazo_config/issues"
29
+ },
30
+ "homepage": "https://github.com/pub12/hazo_config#readme",
31
+ "dependencies": {
32
+ "react": "^18.2.0",
33
+ "react-dom": "^18.2.0",
34
+ "class-variance-authority": "^0.7.0",
35
+ "clsx": "^2.1.0",
36
+ "tailwind-merge": "^2.2.0",
37
+ "lucide-react": "^0.344.0",
38
+ "ini": "^4.1.0"
39
+ },
40
+ "devDependencies": {
41
+ "@storybook/addon-essentials": "^8.0.0",
42
+ "@storybook/addon-interactions": "^8.0.0",
43
+ "@storybook/addon-links": "^8.0.0",
44
+ "@storybook/blocks": "^8.0.0",
45
+ "@storybook/react": "^8.0.0",
46
+ "@storybook/react-vite": "^8.0.0",
47
+ "@storybook/test": "^8.0.0",
48
+ "@types/node": "^20.11.0",
49
+ "@types/react": "^18.2.0",
50
+ "@types/react-dom": "^18.2.0",
51
+ "@types/ini": "^4.1.0",
52
+ "@vitejs/plugin-react": "^4.2.0",
53
+ "autoprefixer": "^10.4.17",
54
+ "postcss": "^8.4.33",
55
+ "storybook": "^8.0.0",
56
+ "tailwindcss": "^3.4.1",
57
+ "typescript": "^5.3.3",
58
+ "vite": "^5.0.11"
59
+ },
60
+ "peerDependencies": {
61
+ "react": "^18.2.0",
62
+ "react-dom": "^18.2.0"
63
+ }
64
+ }
@@ -0,0 +1,7 @@
1
+ module.exports = {
2
+ plugins: {
3
+ tailwindcss: {},
4
+ autoprefixer: {},
5
+ },
6
+ }
7
+
@@ -0,0 +1,116 @@
1
+ // Storybook stories for ConfigEditor component
2
+ // Demonstrates the config editor component with mock config provider
3
+
4
+ import type { Meta, StoryObj } from '@storybook/react'
5
+ import { ConfigEditor } from './config_editor'
6
+ import { MockConfigProvider } from '@/lib/mock_config_provider'
7
+
8
+ /**
9
+ * Sample configuration data for testing
10
+ */
11
+ const sample_config = {
12
+ database: {
13
+ host: 'localhost',
14
+ port: '5432',
15
+ name: 'myapp_db',
16
+ user: 'admin',
17
+ password: 'secret123',
18
+ },
19
+ logging: {
20
+ logfile: 'logs/app.log',
21
+ level: 'info',
22
+ max_size: '10MB',
23
+ format: 'json',
24
+ },
25
+ api: {
26
+ base_url: 'https://api.example.com',
27
+ timeout: '5000',
28
+ retry_count: '3',
29
+ rate_limit: '100',
30
+ },
31
+ server: {
32
+ host: '0.0.0.0',
33
+ port: '3000',
34
+ env: 'production',
35
+ cors_enabled: 'true',
36
+ },
37
+ }
38
+
39
+ /**
40
+ * Meta configuration for ConfigEditor stories
41
+ */
42
+ const meta: Meta<typeof ConfigEditor> = {
43
+ title: 'Components/ConfigEditor',
44
+ component: ConfigEditor,
45
+ parameters: {
46
+ layout: 'fullscreen',
47
+ },
48
+ tags: ['autodocs'],
49
+ argTypes: {
50
+ config_provider: {
51
+ control: false,
52
+ description: 'The config provider instance',
53
+ },
54
+ className: {
55
+ control: 'text',
56
+ description: 'Additional CSS classes',
57
+ },
58
+ },
59
+ }
60
+
61
+ export default meta
62
+ type Story = StoryObj<typeof ConfigEditor>
63
+
64
+ /**
65
+ * Default story with full configuration
66
+ */
67
+ export const Default: Story = {
68
+ args: {
69
+ config_provider: new MockConfigProvider(sample_config),
70
+ },
71
+ }
72
+
73
+ /**
74
+ * Story with minimal configuration
75
+ */
76
+ export const MinimalConfig: Story = {
77
+ args: {
78
+ config_provider: new MockConfigProvider({
79
+ app: {
80
+ name: 'My App',
81
+ version: '1.0.0',
82
+ },
83
+ }),
84
+ },
85
+ }
86
+
87
+ /**
88
+ * Story with empty configuration
89
+ */
90
+ export const EmptyConfig: Story = {
91
+ args: {
92
+ config_provider: new MockConfigProvider(),
93
+ },
94
+ }
95
+
96
+ /**
97
+ * Story with complex configuration
98
+ */
99
+ export const ComplexConfig: Story = {
100
+ args: {
101
+ config_provider: new MockConfigProvider({
102
+ ...sample_config,
103
+ features: {
104
+ feature_a: 'enabled',
105
+ feature_b: 'disabled',
106
+ feature_c: 'beta',
107
+ },
108
+ integrations: {
109
+ stripe_api_key: 'sk_test_123456',
110
+ sendgrid_api_key: 'SG.abcdef',
111
+ aws_region: 'us-east-1',
112
+ },
113
+ }),
114
+ },
115
+ }
116
+