Skip to content

πŸ”§ Patch Release v2.0.2 - ApiPermission Enum Enhancement

Choose a tag to compare

@PaulGossen PaulGossen released this 09 Nov 10:51
· 49 commits to main since this release

πŸ“‹ Overview

This patch release enhances the ApiPermission enum by adding a new DELIVERY permission level and normalizing case naming conventions.


⚠️ BREAKING CHANGES

ApiPermission Enum

Case Name Change:

// v2.0.1 (Old)
ApiPermission::READ_ONLY

// v2.0.2 (New)
ApiPermission::READONLY

Value Change:

// v2.0.1 (Old)
'read-only'

// v2.0.2 (New)
'readonly'

✨ New Features

New Permission Level: DELIVERY

Added a new permission level specifically for delivery-only API access:

use GoSuccess\Digistore24\Api\Enum\ApiPermission;

// Available permission levels
ApiPermission::READONLY   // Value: 'readonly'  - Read-only access
ApiPermission::DELIVERY   // Value: 'delivery'  - Delivery operations only
ApiPermission::WRITABLE   // Value: 'writable'  - Full write access

Use Cases for DELIVERY Permission:

  • API keys used exclusively for order delivery/fulfillment
  • Limited access scope for third-party integrations
  • Separation of concerns between read, delivery, and write operations

πŸ§ͺ Quality Assurance

  • βœ… 1145/1145 Unit Tests Passing (+8 new tests, 2294 assertions)
  • βœ… PHPStan Level 9: 0 errors (654 files analyzed, +1 file)
  • βœ… PHP CS Fixer: 0 violations (PSR-12 compliant)
  • βœ… New Test File: ApiPermissionTest.php with comprehensive coverage

πŸ“ Test Coverage

The new ApiPermissionTest includes:

  1. βœ… Value Validation - All cases have correct string values
  2. βœ… Label Testing - All cases return proper human-readable labels
  3. βœ… Case-Insensitive Conversion - fromString() handles mixed case
  4. βœ… Invalid Input Handling - Graceful null returns for invalid values
  5. βœ… Labels Mapping - Complete value-to-label array generation
  6. βœ… Values Array - All valid string values extraction
  7. βœ… Validation Method - isValid() checks for valid permissions
  8. βœ… Edge Cases - Null, empty string, and invalid value handling

πŸ”§ Migration Guide

For users upgrading from v2.0.1 β†’ v2.0.2

If you're using ApiPermission enum directly in your code:

// Old (v2.0.1)
if ($permission === ApiPermission::READ_ONLY) {
    // read-only logic
}

// New (v2.0.2)
if ($permission === ApiPermission::READONLY) {
    // read-only logic
}

// New DELIVERY case
if ($permission === ApiPermission::DELIVERY) {
    // delivery-only logic
}

String Value Changes:

// Old (v2.0.1)
ApiPermission::fromString('read-only'); // βœ… Worked

// New (v2.0.2)
ApiPermission::fromString('readonly');  // βœ… Now works
ApiPermission::fromString('read-only'); // ❌ Returns null
ApiPermission::fromString('delivery');  // βœ… New DELIVERY case

Note: The fromString() method is case-insensitive, so 'READONLY', 'ReadOnly', and 'readonly' all work.


πŸ“¦ Files Changed

3 files changed: 81 insertions(+), 3 deletions(-)

Modified Files (2)

  • src/Enum/ApiPermission.php - Added DELIVERY case, renamed READ_ONLY β†’ READONLY
  • RELEASE_NOTES.md - Updated release documentation

New Files (1)

  • tests/Unit/Enum/ApiPermissionTest.php - Comprehensive test suite (8 tests)

πŸ’‘ Why This Change?

1. Consistency

  • PHP property naming convention: use readonly keyword (not read_only)
  • Hyphenated values ('read-only') are inconsistent with camelCase/PascalCase
  • Aligns with modern PHP 8.4 conventions

2. Separation of Concerns

  • READONLY - View data only (GET operations)
  • DELIVERY - Fulfill orders, update delivery status (limited POST/PUT)
  • WRITABLE - Full CRUD operations (unrestricted access)

3. Security

  • Granular permission control for API keys
  • Minimize attack surface by limiting key capabilities
  • Better audit trail with specific permission levels

🎯 Impact Analysis

Who is affected?

  • Low Impact: Most users don't directly interact with ApiPermission enum
  • Medium Impact: Users with custom permission checking logic
  • High Impact: Users storing permission strings in databases (migration required)

Database Migration (if storing permissions):

-- Update existing 'read-only' values to 'readonly'
UPDATE api_keys SET permission = 'readonly' WHERE permission = 'read-only';

-- Verify no old values remain
SELECT * FROM api_keys WHERE permission = 'read-only';

πŸ“„ Changelog Summary

Added

  • ApiPermission::DELIVERY case for delivery-only operations
  • ApiPermissionTest with 8 comprehensive test methods
  • Label for DELIVERY permission: "Delivery"

Changed (Breaking)

  • ApiPermission::READ_ONLY β†’ ApiPermission::READONLY
  • String value: 'read-only' β†’ 'readonly'

Improved

  • Test coverage increased from 1137 to 1145 tests (+8)
  • Assertions increased from 2286 to 2294 (+8)
  • PHPStan now analyzes 654 files (was 653)

Full Changelog: v2.0.1...v2.0.2