npm package: @jondoesflow/environment-variable-manager
Description: Manage Dataverse environment variables - view, edit, and export environment variables and their values by solution (A respectful copy of MscrmTools Environment Variable Manager)
Author: JonDoesFlow
Latest version: 1.0.1

# Environment Variable Manager for Power Platform Toolbox

A comprehensive tool for managing Dataverse environment variables - view, create, update, and delete environment variables and their values directly from Power Platform Toolbox.

*(A respectful copy of [MscrmTools Environment Variable Manager](https://github.com/MscrmTools/MscrmTools.EnvironmentVariableManager))*

## What Does This Tool Do?

The Environment Variable Manager provides a streamlined interface for managing environment variables in your Dataverse environment. Environment variables are essential for storing configuration values that can change across different environments (Development, Test, Production) without requiring code changes.

### Key Features

- **📋 View All Variables**: Browse all environment variables in your Dataverse environment with an intuitive sidebar list
- **🔍 Search & Filter**: Quickly find variables using the search function and solution filters
- **✏️ Edit Definitions**: Update display names, descriptions, and default values
- **🎯 Manage Values**: Set and update environment-specific values that override default values
- **📋 Copy Values**: One-click copy of variable values to clipboard
- **� Real-time Statistics**: View total and active variable counts at a glance
- **� Export to Excel**: Download environment variables to Excel spreadsheet with solution details

## Why Use This Tool?

- **Centralized Management**: All environment variables in one place, no need to navigate through multiple Dataverse tables
- **Visual Interface**: Clean, modern UI that makes managing variables intuitive
- **Type Safety**: Proper handling of different variable types (String, Number, Boolean, JSON, Data Source)
- **Quick Access**: Fast search and filtering to find the variables you need
- **Efficient Workflow**: View, edit, and update operations without leaving the tool
- **Solution-Aware**: Filter variables by solution and view only what's relevant
- **Connection Aware**: Automatically refreshes when you switch between Dataverse environments

## Official Documentation

- [Dataverse Environment Variables](https://learn.microsoft.com/en-us/power-apps/maker/data-platform/environmentvariables)
- [Environment Variable Definitions](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/reference/entities/environmentvariabledefinition)
- [Environment Variable Values](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/reference/entities/environmentvariablevalue)

## Usage

### Getting Started

1. **Connect to Environment**: Ensure you have an active connection to a Dataverse environment in Power Platform Toolbox
2. **Load Tool**: Open the Environment Variable Manager from the toolbox
3. **View Variables**: All environment variables will load automatically in the sidebar

### Exporting to Excel

1. Select a solution from the solution filter dropdown
2. Click the **"📥 Export to Excel"** button in the toolbar
3. The exported spreadsheet will include:
   - Solution name, version, and type (managed/unmanaged)
   - List of all environment variables with logical names, display names, and descriptions

### Managing Values

1. **Select a Variable**: Click on any variable in the sidebar to view its details
2. **Set Current Value**: Click the **"Set Value"** or **"Update Value"** button
3. **Enter Value**: Provide the environment-specific value
4. **Save**: Click **"Set Value"** or **"Update Value"** to save

### Editing Variables

1. Select a variable from the list
2. Click **"Edit Definition"** in the details panel
3. Update the display name, description, or default value
4. Click **"Update"** to save changes

**Note**: Schema names cannot be changed after creation. This tool is designed for editing existing variables in solutions, not creating or deleting them.

## Use Cases

### Power Platform Developers
- View and update API endpoints and connection strings across environments
- Configure feature flags and environment-specific settings
- Export variable configurations for documentation

### Power Platform Administrators
- Maintain consistent configuration across Dev/Test/Prod environments
- Update values without requiring code deployments
- Audit and review all environment variables by solution
- Export environment variables for compliance and documentation

### Solution Architects
- Review solution configurations and environment variables
- Document configuration requirements through variable descriptions
- Ensure proper separation of concerns between code and configuration

## Technical Details

### Supported Variable Types

| Type | Value | Description |
|------|-------|-------------|
| **String** | 100000000 | Text values, URLs, connection strings |
| **Number** | 100000001 | Numeric values, integers, decimals |
| **Boolean** | 100000002 | True/False values |
| **JSON** | 100000003 | Complex JSON objects and arrays |
| **Data Source** | 100000004 | Reference to Dataverse data sources |

### Variable Components

Each environment variable consists of:

1. **Definition** (`environmentvariabledefinition`)
   - Schema name (unique identifier)
   - Display name
   - Description
   - Type
   - Default value

2. **Value** (`environmentvariablevalue`)
   - Current value (overrides default)
   - Environment-specific
   - Optional (falls back to default if not set)

### API Operations

The tool uses the Dataverse Web API to perform:
- `GET` - Retrieve variable definitions, values, and solutions
- `POST` - Create new values for existing variables
- `PATCH` - Update existing definitions and values

## Development

### Project Structure

```
environment-variable-manager/
├── src/
│   ├── app.ts              # Main application logic
│   └── types.d.ts          # TypeScript type definitions
├── scripts/
│   ├── copy-files.js       # Build script to copy static files
│   └── finalize-package.js # Package preparation script
├── index.html              # UI structure
├── styles.css              # Complete styling
├── package.json            # Package configuration
├── tsconfig.json           # TypeScript configuration
├── .gitignore              # Git ignore rules
├── .npmignore              # NPM publish ignore rules
└── README.md               # This file
```

### Technologies Used

- **TypeScript**: Type-safe application logic
- **HTML5/CSS3**: Modern, responsive UI
- **Dataverse Web API**: Backend data operations
- **Power Platform Toolbox APIs**: Integration with PPTB

### Building the Tool

```bash
# Install dependencies
npm install

# Development mode (watch for changes)
npm run dev

# Build for production
npm run build

# Prepare package for publishing
npm run finalize-package
```

### Build Process

1. **TypeScript Compilation**: `tsc` compiles `src/app.ts` to `dist/app.js`
2. **File Copying**: Static files (HTML, CSS) are copied to `dist/`
3. **Package Finalization**: Prepares clean `package.json` for NPM publishing

## Known Limitations

- Schema names cannot be modified after creation (Dataverse platform limitation)
- Cannot create or delete environment variables (by design - use solution management)
- Bulk operations are not currently supported
- Cannot manage permissions or security roles for variables
- JSON validation is client-side only
- Requires System Administrator role in the connected environment

## Best Practices

1. **Solution Management**: Create environment variables through solutions, then manage values with this tool
2. **Descriptive Names**: Use clear, descriptive display names and add detailed descriptions
3. **Default Values**: Provide sensible default values when possible
4. **Document Usage**: Use the description field to document where and how the variable is used
5. **Test Changes**: Always test variable changes in non-production environments first
6. **Export Regularly**: Use the Excel export feature to maintain documentation of your environment variables
7. **Solution Filtering**: Filter by solution to focus on relevant variables and avoid confusion

## Contributing

Contributions are welcome! Please feel free to submit issues or pull requests on GitHub.

## License

MIT License - see LICENSE file for details

## Acknowledgments

A respectful copy of [MscrmTools Environment Variable Manager](https://github.com/MscrmTools/MscrmTools.EnvironmentVariableManager). Originally created for XrmToolBox by MscrmTools, this version has been rebuilt for Power Platform Toolbox with modern web technologies.

## Support

For questions, issues, or feature requests:
- GitHub Issues: https://github.com/jondoesflow/environment-variable-manager/issues
- Website: https://www.jondoesflow.com
- Power Platform Toolbox: https://powerplatformtoolbox.com

## Changelog

### Version 1.0.0
- Initial release
- View and edit operations for environment variables
- Search and filter functionality by solution
- Support for all variable types (String, Number, Boolean, JSON, Data Source)
- System Administrator role verification
- Change tracking with confirmation prompts
- Solution-aware filtering (only shows solutions with environment variables)
- Responsive design
- Real-time connection monitoring
- Copy to clipboard functionality
- Export to Excel with solution details