|
| 1 | +# Migration Guide: v0.9.0 Plugin Updates |
| 2 | + |
| 3 | +This guide covers the changes made to ObjectQL plugins to align with `@objectstack/spec` v0.9.0. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +All ObjectQL plugins have been updated to: |
| 8 | +1. Use `@objectstack/spec` v0.9.0 role definitions |
| 9 | +2. Implement Zod validation for configuration |
| 10 | +3. Use structured logging from `@objectstack/core` |
| 11 | + |
| 12 | +## Breaking Changes |
| 13 | + |
| 14 | +### 1. Configuration Validation |
| 15 | + |
| 16 | +All plugin configurations are now validated using Zod schemas at runtime. Invalid configurations will throw validation errors immediately upon plugin instantiation. |
| 17 | + |
| 18 | +**Before:** |
| 19 | +```typescript |
| 20 | +const securityPlugin = new ObjectQLSecurityPlugin({ |
| 21 | + enabled: true, |
| 22 | + storageType: 'memory', |
| 23 | + cacheTTL: 60000 |
| 24 | +}); |
| 25 | +``` |
| 26 | + |
| 27 | +**After:** |
| 28 | +```typescript |
| 29 | +import { SecurityPluginConfigSchema } from '@objectql/plugin-security'; |
| 30 | + |
| 31 | +const securityPlugin = new ObjectQLSecurityPlugin({ |
| 32 | + enabled: true, |
| 33 | + storageType: 'memory', |
| 34 | + cacheTTL: 60000 // Will be validated by Zod schema |
| 35 | +}); |
| 36 | + |
| 37 | +// Configuration is automatically validated |
| 38 | +// Invalid values will throw ZodError |
| 39 | +``` |
| 40 | + |
| 41 | +### 2. Role Type Definitions |
| 42 | + |
| 43 | +The `@objectql/plugin-security` now imports the `Role` type from `@objectstack/spec/auth` instead of defining it locally. |
| 44 | + |
| 45 | +**Before:** |
| 46 | +```typescript |
| 47 | +// Role was implicitly defined as string[] |
| 48 | +const permissions = { |
| 49 | + roles: ['admin', 'manager'] |
| 50 | +}; |
| 51 | +``` |
| 52 | + |
| 53 | +**After:** |
| 54 | +```typescript |
| 55 | +import type { Role } from '@objectql/plugin-security'; |
| 56 | + |
| 57 | +// Role now follows @objectstack/spec convention |
| 58 | +// Role names MUST be lowercase snake_case |
| 59 | +const permissions = { |
| 60 | + roles: ['admin', 'manager', 'sales_manager'] |
| 61 | +}; |
| 62 | +``` |
| 63 | + |
| 64 | +**Important:** Role names MUST follow the snake_case naming convention to prevent security issues. |
| 65 | + |
| 66 | +### 3. Logging Changes |
| 67 | + |
| 68 | +All plugins now use structured logging instead of console.log/error. |
| 69 | + |
| 70 | +**Before:** |
| 71 | +```typescript |
| 72 | +// Plugins logged to console |
| 73 | +console.log('[plugin-security] Installing...'); |
| 74 | +``` |
| 75 | + |
| 76 | +**After:** |
| 77 | +```typescript |
| 78 | +// Plugins use structured logger |
| 79 | +logger.info('Installing security plugin', { |
| 80 | + config: { enabled: true } |
| 81 | +}); |
| 82 | +``` |
| 83 | + |
| 84 | +This enables: |
| 85 | +- Structured log entries with metadata |
| 86 | +- Configurable log levels |
| 87 | +- Better integration with observability tools |
| 88 | +- Consistent logging format across all plugins |
| 89 | + |
| 90 | +## Plugin-Specific Changes |
| 91 | + |
| 92 | +### @objectql/plugin-security |
| 93 | + |
| 94 | +**New Exports:** |
| 95 | +```typescript |
| 96 | +export { |
| 97 | + SecurityPluginConfigSchema, |
| 98 | + PermissionStorageTypeSchema, |
| 99 | + DatabaseConfigSchema |
| 100 | +} from '@objectql/plugin-security'; |
| 101 | +``` |
| 102 | + |
| 103 | +**Updated Dependencies:** |
| 104 | +```json |
| 105 | +{ |
| 106 | + "@objectstack/core": "^0.9.0", |
| 107 | + "@objectstack/spec": "^0.9.0", |
| 108 | + "zod": "^3.23.8" |
| 109 | +} |
| 110 | +``` |
| 111 | + |
| 112 | +### @objectql/plugin-validator |
| 113 | + |
| 114 | +**New Exports:** |
| 115 | +```typescript |
| 116 | +export { ValidatorPluginConfigSchema } from '@objectql/plugin-validator'; |
| 117 | +``` |
| 118 | + |
| 119 | +**Configuration Changes:** |
| 120 | +- `languageFallback` is now an array of strings: `string[]` instead of `string` |
| 121 | +- Default value changed from `'en'` to `['en', 'zh-CN']` |
| 122 | + |
| 123 | +**Before:** |
| 124 | +```typescript |
| 125 | +const validator = new ValidatorPlugin({ |
| 126 | + language: 'en', |
| 127 | + languageFallback: 'zh-CN' // string |
| 128 | +}); |
| 129 | +``` |
| 130 | + |
| 131 | +**After:** |
| 132 | +```typescript |
| 133 | +const validator = new ValidatorPlugin({ |
| 134 | + language: 'en', |
| 135 | + languageFallback: ['zh-CN', 'en'] // string[] |
| 136 | +}); |
| 137 | +``` |
| 138 | + |
| 139 | +### @objectql/plugin-formula |
| 140 | + |
| 141 | +**New Exports:** |
| 142 | +```typescript |
| 143 | +export { FormulaPluginConfigSchema } from '@objectql/plugin-formula'; |
| 144 | +``` |
| 145 | + |
| 146 | +**Configuration Changes:** |
| 147 | +- Added new configuration options for caching and validation |
| 148 | +- `strict`, `timeout`, and `customFunctions` are now available |
| 149 | + |
| 150 | +**New Options:** |
| 151 | +```typescript |
| 152 | +const formula = new FormulaPlugin({ |
| 153 | + strict: true, |
| 154 | + timeout: 1000, |
| 155 | + enableCache: false, |
| 156 | + cacheTTL: 60000, |
| 157 | + autoEvaluateOnQuery: true |
| 158 | +}); |
| 159 | +``` |
| 160 | + |
| 161 | +## Migration Steps |
| 162 | + |
| 163 | +### Step 1: Update Dependencies |
| 164 | + |
| 165 | +Update your `package.json` to use the latest plugin versions: |
| 166 | + |
| 167 | +```json |
| 168 | +{ |
| 169 | + "dependencies": { |
| 170 | + "@objectql/plugin-security": "^4.0.5", |
| 171 | + "@objectql/plugin-validator": "^4.0.5", |
| 172 | + "@objectql/plugin-formula": "^4.0.5" |
| 173 | + } |
| 174 | +} |
| 175 | +``` |
| 176 | + |
| 177 | +### Step 2: Install Dependencies |
| 178 | + |
| 179 | +```bash |
| 180 | +pnpm install |
| 181 | +``` |
| 182 | + |
| 183 | +### Step 3: Update Plugin Configurations |
| 184 | + |
| 185 | +Review and update your plugin configurations to ensure they conform to the new Zod schemas. |
| 186 | + |
| 187 | +**Security Plugin:** |
| 188 | +```typescript |
| 189 | +import { ObjectQLSecurityPlugin } from '@objectql/plugin-security'; |
| 190 | + |
| 191 | +const securityPlugin = new ObjectQLSecurityPlugin({ |
| 192 | + enabled: true, |
| 193 | + storageType: 'memory', |
| 194 | + permissions: [...], |
| 195 | + exemptObjects: [], |
| 196 | + enableRowLevelSecurity: true, |
| 197 | + enableFieldLevelSecurity: true, |
| 198 | + precompileRules: true, |
| 199 | + enableCache: true, |
| 200 | + cacheTTL: 60000, |
| 201 | + throwOnDenied: true, |
| 202 | + enableAudit: false |
| 203 | +}); |
| 204 | +``` |
| 205 | + |
| 206 | +**Validator Plugin:** |
| 207 | +```typescript |
| 208 | +import { ValidatorPlugin } from '@objectql/plugin-validator'; |
| 209 | + |
| 210 | +const validatorPlugin = new ValidatorPlugin({ |
| 211 | + language: 'en', |
| 212 | + languageFallback: ['en', 'zh-CN'], // Note: array now |
| 213 | + enableQueryValidation: true, |
| 214 | + enableMutationValidation: true |
| 215 | +}); |
| 216 | +``` |
| 217 | + |
| 218 | +**Formula Plugin:** |
| 219 | +```typescript |
| 220 | +import { FormulaPlugin } from '@objectql/plugin-formula'; |
| 221 | + |
| 222 | +const formulaPlugin = new FormulaPlugin({ |
| 223 | + strict: true, |
| 224 | + timeout: 1000, |
| 225 | + enableCache: false, |
| 226 | + cacheTTL: 60000, |
| 227 | + autoEvaluateOnQuery: true |
| 228 | +}); |
| 229 | +``` |
| 230 | + |
| 231 | +### Step 4: Update Role Names |
| 232 | + |
| 233 | +Ensure all role names follow the lowercase snake_case convention: |
| 234 | + |
| 235 | +**Before:** |
| 236 | +```typescript |
| 237 | +const permissions = { |
| 238 | + object_permissions: { |
| 239 | + read: ['Admin', 'SalesManager'] // Invalid! |
| 240 | + } |
| 241 | +}; |
| 242 | +``` |
| 243 | + |
| 244 | +**After:** |
| 245 | +```typescript |
| 246 | +const permissions = { |
| 247 | + object_permissions: { |
| 248 | + read: ['admin', 'sales_manager'] // Valid |
| 249 | + } |
| 250 | +}; |
| 251 | +``` |
| 252 | + |
| 253 | +### Step 5: Test Your Application |
| 254 | + |
| 255 | +Run your tests to ensure everything works correctly: |
| 256 | + |
| 257 | +```bash |
| 258 | +pnpm test |
| 259 | +``` |
| 260 | + |
| 261 | +## Benefits of These Changes |
| 262 | + |
| 263 | +1. **Type Safety**: Zod validation ensures configuration errors are caught early |
| 264 | +2. **Better Observability**: Structured logging enables better monitoring and debugging |
| 265 | +3. **Spec Compliance**: Alignment with `@objectstack/spec` ensures consistency across the ecosystem |
| 266 | +4. **Security**: Role naming conventions prevent common security pitfalls |
| 267 | +5. **Developer Experience**: Better error messages and validation feedback |
| 268 | + |
| 269 | +## Troubleshooting |
| 270 | + |
| 271 | +### ZodError on Plugin Initialization |
| 272 | + |
| 273 | +If you see a `ZodError`, check your configuration against the schema: |
| 274 | + |
| 275 | +```typescript |
| 276 | +import { SecurityPluginConfigSchema } from '@objectql/plugin-security'; |
| 277 | + |
| 278 | +// Validate your config manually |
| 279 | +const result = SecurityPluginConfigSchema.safeParse(yourConfig); |
| 280 | +if (!result.success) { |
| 281 | + console.error('Configuration errors:', result.error.format()); |
| 282 | +} |
| 283 | +``` |
| 284 | + |
| 285 | +### Role Name Validation Errors |
| 286 | + |
| 287 | +Ensure all role names are lowercase and use underscores: |
| 288 | +- ✅ `admin`, `sales_manager`, `ceo`, `region_east_vp` |
| 289 | +- ❌ `Admin`, `SalesManager`, `CEO`, `Region East VP` |
| 290 | + |
| 291 | +### Missing Dependencies |
| 292 | + |
| 293 | +If you see import errors, ensure all dependencies are installed: |
| 294 | + |
| 295 | +```bash |
| 296 | +pnpm install @objectstack/core@^0.9.0 @objectstack/spec@^0.9.0 zod@^3.23.8 |
| 297 | +``` |
| 298 | + |
| 299 | +## Support |
| 300 | + |
| 301 | +For questions or issues, please: |
| 302 | +1. Check the [GitHub Issues](https://github.com/objectstack-ai/objectql/issues) |
| 303 | +2. Review the [API Documentation](https://objectql.dev) |
| 304 | +3. Join our [Discord Community](https://discord.gg/objectstack) |
0 commit comments