From 4af1f3d41ae724c9f8eca68cbe08e8ca4479ed8f Mon Sep 17 00:00:00 2001 From: Adam Lee Date: Mon, 13 May 2024 15:35:56 +0100 Subject: [PATCH 1/9] docs: Update for pre-release --- README.md | 81 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index f962d06..b5fbc63 100644 --- a/README.md +++ b/README.md @@ -5,12 +5,12 @@ [![Latest Version on Packagist](https://img.shields.io/packagist/v/xtend-packages/rest-presenter.svg?style=flat-square)](https://packagist.org/packages/xtend-packages/rest-presenter) [![PHP from Packagist](https://img.shields.io/packagist/php-v/xtend-packages/rest-presenter)](https://packagist.org/packages/xtend-packages/rest-presenter) +[![GitHub License](https://img.shields.io/github/license/xtend-packages/rest-presenter)](https://github.com/xtend-packages/rest-presenter/blob/main/LICENSE.md) [![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/xtend-packages/rest-presenter/tests.yml?label=tests)](https://github.com/xtend-packages/rest-presenter/actions/workflows/tests.yml) [![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/xtend-packages/rest-presenter/code-styling.yml?label=code%20style)](https://github.com/xtend-packages/rest-presenter/actions/workflows/code-styling.yml) [![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/xtend-packages/rest-presenter/phpstan.yml?label=static%20analysis)](https://github.com/xtend-packages/rest-presenter/actions/workflows/phpstan.yml) [![Total Downloads](https://img.shields.io/packagist/dt/xtend-packages/rest-presenter.svg?style=flat-square)](https://packagist.org/packages/xtend-packages/rest-presenter) -[![GitHub Sponsors](https://img.shields.io/github/sponsors/adam-code-labx)](https://github.com/sponsors/adam-code-labx) -[![GitHub License](https://img.shields.io/github/license/xtend-packages/rest-presenter)](https://github.com/xtend-packages/rest-presenter/blob/main/LICENSE.md) +[![Discord](https://img.shields.io/discord/1033138523584331837?label=Discord&logo=discord)](https://discord.gg/j7EAhVVcyX) # RESTPresenter @@ -32,8 +32,10 @@ To generate your API collection, run the following command below: ```bash php artisan rest-presenter:generate-api-collection ``` - -Postman collection generated by default. We also support Insomnia simply set `REST_PRESENTER_EXPORT_PROVIDER=insomnia` in your .env file. +Postman collection generated by default. We also support Insomnia simply by setting the following in your .env file: +```bash +REST_PRESENTER_EXPORT_PROVIDER=insomnia +``` ### The following directories with generated files will be created: - `app/Api/StarterKits/Filament` (contains all generated resources) @@ -41,12 +43,42 @@ Postman collection generated by default. We also support Insomnia simply set `RE - `resources/rest-presenter/insomnia` (generated Insomnia collection) - `resources/types/` (generated TypeScript DTOs) +### API Collection Auto-Generation +Make sure you only run this command after the setup command to generate your API collection. + +```bash +php artisan rest-presenter:generate-api-collection +``` + +RESTPresenter generates a Postman collection by default.\ +To generate an Insomnia collection, set the following in your .env file: +```bash +REST_PRESENTER_EXPORT_PROVIDER=insomnia +``` + +### Security API Key +Be default RESTPresenter provides a security API key for your API collection.\ +The default key is value is `rest-presenter-secret-key` + +Please note that the API key is only for local development and should not be used in production. +You can change the API by setting the following in your .env file: +```bash +REST_PRESENTER_AUTH_API_KEY=your-new-secret-key +``` +Additionally to opt out of using this feature, set the following in your .env file: +```bash +REST_PRESENTER_AUTH_ENABLE_API_KEY=false +``` + +### Authentication +RESTPresenter currently provides a simple authentication middleware for your API collection.\ +Simply set `public static bool $isAuthenticated = true;` in any resource to use your bearer token for authentication to access the resource. + ## Starter Kits Our initial release includes the following Starter Kits to jumpstart your development: - [Sanctum Auth Starter Kit](https://github.com/xtend-packages/rest-presenter/discussions/categories/general) - [Filament API Starter Kit](https://github.com/xtend-packages/rest-presenter/discussions/categories/filament-starter-kit) - ## Key Features - Effortless REST API creation with Laravel API Resources. @@ -55,13 +87,20 @@ Our initial release includes the following Starter Kits to jumpstart your develo - Testing support to ensure reliability and stability. - Automating API creation from resources in Filament. - TypeScript auto-generation for API resource DTOs. +- Postman and Insomnia collection generation for easy API testing. +- Secure your API collection with a security API key. +- Simple authentication middleware for your API resources. ## Planned Features - Release of Sponsorware API Kits for comprehensive API integration. - Customisable kits providing a solid foundation for API development. - Future open-sourcing of full kits upon reaching sponsorship milestones. +- Widget API generation for easy integration with your frontend. +- Social Kit for login and registration with social media platforms. -more to follow soon... +Check out our [Roadmap](https://github.com/orgs/xtend-packages/projects/1/views/1) for upcoming features and improvements. Feel free to open an issue for suggestions or feature requests. Join us on Discord to start a discussion and stay updated on the latest news.\ + +[![Discord](https://img.shields.io/discord/1033138523584331837?label=Discord&logo=discord)](https://discord.gg/j7EAhVVcyX) ## What Makes This Package Unique? RESTPresenter is more than just a CRUD generator. It offers: @@ -71,10 +110,6 @@ RESTPresenter is more than just a CRUD generator. It offers: - Everything is extendable and customisable to fit your project's needs. - API Kits to jumpstart your development with pre-built features and resources. -## Roadmap -Check out our [Roadmap](https://github.com/orgs/xtend-packages/projects/1/views/1) for upcoming features and improvements. Feel free to open an issue for suggestions or feature requests. We'll soon be launching our Discord for collaborative discussions. -Meanwhile start a discussion on GitHub to share your thoughts and ideas. - ## Requirements - PHP ^8.2 @@ -120,36 +155,10 @@ This command will guide you through creating a new resource. Prompts will allow ### Generate Resources (Blueprint) Coming soon, leveraging the outstanding capabilities of [Laravel Blueprint](https://blueprint.laravelshift.com/) -### Registering Kits - -To register a kit, add it to the starterKits array in the register method of the RESTPresenterServiceProvider. For example: - -```php -namespace App\Providers; - -use Illuminate\Support\ServiceProvider; -use XtendPackages\RESTPresenter\Facades\RESTPresenter; -use XtendPackages\RESTPresenter\StarterKits\Auth\Sanctum\SanctumApiKitServiceProvider; - -class RESTPresenterServiceProvider extends ServiceProvider -{ - public function register(): void - { - RESTPresenter::register($this->app) - ->starterKits([ - SanctumApiKitServiceProvider::class, - ]); - } -} -``` - ### Configuration Configure RESTPresenter in the `config/rest-presenter.php` file to customize the package according to your project requirements. -## API Endpoints -Users can import this collection into their Insomnia application to quickly access and test the endpoints provided by RESTPresenter. This file is located [here](https://raw.githubusercontent.com/xtend-packages/rest-presenter/main/resources/insomnia/rest-presenter-Insomnia_2024-04-07.json) - ## Testing RESTPresenter includes a comprehensive testing suite to ensure your API's reliability and stability. Test generators will soon be added to facilitate testing when creating new resources. From 3df57f2ae3d893280ef7646829f11865d34e911d Mon Sep 17 00:00:00 2001 From: Adam Lee Date: Mon, 13 May 2024 15:36:45 +0100 Subject: [PATCH 2/9] chore: release v1.0.0-rc.0 --- CHANGELOG.md | 18 ++++++++++++++++++ composer.json | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b208776..ba5ba5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,23 @@ # Changelog for RESTPresenter +## [1.0.0-rc.0](https://github.com/xtend-packages/rest-presenter/compare/0.11.0...1.0.0-rc.0) (2024-05-13) + + +### Features + +* Extra Security API Key (Enabled by Default) ([b7baa38](https://github.com/xtend-packages/rest-presenter/commit/b7baa380aa8f6caa600a3f04b18a3f431a2d83a5)) +* Improve tests + remove service provider ([151bb8b](https://github.com/xtend-packages/rest-presenter/commit/151bb8bc06c3b2ff1867dbdbca1f6b2928558f0c)) + + +### Bug Fixes + +* Skip RESTPresenterSetupCommand test issue with expectsChoice ([1a7ee6b](https://github.com/xtend-packages/rest-presenter/commit/1a7ee6b96262bc9a01975266f0eafcc568713659)) + + +### Documentation + +* Update for pre-release ([4af1f3d](https://github.com/xtend-packages/rest-presenter/commit/4af1f3d41ae724c9f8eca68cbe08e8ca4479ed8f)) + ## [0.11.0](https://github.com/xtend-packages/rest-presenter/compare/0.10.1...0.11.0) (2024-05-11) diff --git a/composer.json b/composer.json index 1f5bfe6..121a59c 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "xtend-packages/rest-presenter", - "version": "0.11.0", + "version": "1.0.0-rc.0", "description": "REST API Presenter & Generator for Laravel", "keywords": [ "code-labx", From bab904222f88e64a3d025519014334ab96c75f73 Mon Sep 17 00:00:00 2001 From: Adam Lee Date: Mon, 13 May 2024 16:09:16 +0100 Subject: [PATCH 3/9] docs: Add info about tests + warning to update phpunit.xml --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index b5fbc63..fd4029b 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,16 @@ REST_PRESENTER_EXPORT_PROVIDER=insomnia - `resources/rest-presenter/postman` (generated Postman collection) - `resources/rest-presenter/insomnia` (generated Insomnia collection) - `resources/types/` (generated TypeScript DTOs) +- `tests/StarterKits/Filament` (generated tests) + +> **_WARNING:_** Please don't run any tests before you update your phpunit.xml file to include the following: + +```xml + + +``` + +Without this update, it will use your default database connection and refresh the database after each test. ### API Collection Auto-Generation Make sure you only run this command after the setup command to generate your API collection. From c40a819c5f6defa2afdd39c49ad53dd6881569bf Mon Sep 17 00:00:00 2001 From: Adam Lee Date: Mon, 13 May 2024 16:17:46 +0100 Subject: [PATCH 4/9] fix: No need to remove the API directory via XtendRouter --- src/Support/XtendRouter.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/Support/XtendRouter.php b/src/Support/XtendRouter.php index c6f78b8..91dbf87 100644 --- a/src/Support/XtendRouter.php +++ b/src/Support/XtendRouter.php @@ -6,7 +6,6 @@ use Illuminate\Container\Container; use Illuminate\Contracts\Events\Dispatcher; -use Illuminate\Filesystem\Filesystem; use Illuminate\Routing\PendingResourceRegistration; use Illuminate\Routing\Router; use Illuminate\Routing\RouteRegistrar; @@ -22,15 +21,6 @@ final class XtendRouter extends Router public function __construct(Dispatcher $events, ?Container $container = null) { parent::__construct($events, $container); - - $filesystem = app(Filesystem::class); - if (! $filesystem->isDirectory(app_path('Api'))) { - return; - } - if (! app()->runningUnitTests()) { - return; - } - $filesystem->deleteDirectory(app_path('Api')); } public function register(): RouteRegistrar From eff7851c1962e37bce763e89eeaede60670e7295 Mon Sep 17 00:00:00 2001 From: Adam Lee Date: Mon, 13 May 2024 16:18:32 +0100 Subject: [PATCH 5/9] chore: release v1.0.0-rc.1 --- CHANGELOG.md | 12 ++++++++++++ composer.json | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba5ba5d..c460cbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog for RESTPresenter +## [1.0.0-rc.1](https://github.com/xtend-packages/rest-presenter/compare/1.0.0-rc.0...1.0.0-rc.1) (2024-05-13) + + +### Bug Fixes + +* No need to remove the API directory via XtendRouter ([c40a819](https://github.com/xtend-packages/rest-presenter/commit/c40a819c5f6defa2afdd39c49ad53dd6881569bf)) + + +### Documentation + +* Add info about tests + warning to update phpunit.xml ([bab9042](https://github.com/xtend-packages/rest-presenter/commit/bab904222f88e64a3d025519014334ab96c75f73)) + ## [1.0.0-rc.0](https://github.com/xtend-packages/rest-presenter/compare/0.11.0...1.0.0-rc.0) (2024-05-13) diff --git a/composer.json b/composer.json index 121a59c..a259d36 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "xtend-packages/rest-presenter", - "version": "1.0.0-rc.0", + "version": "1.0.0-rc.1", "description": "REST API Presenter & Generator for Laravel", "keywords": [ "code-labx", From 79de5b1791e4209a32cea61c992704ac390514cf Mon Sep 17 00:00:00 2001 From: Adam Lee Date: Mon, 13 May 2024 16:27:25 +0100 Subject: [PATCH 6/9] fix: Include API key with test generation --- .../Generator/stubs/tests/resource.pest.php.stub | 10 ++++++++-- .../Generator/stubs/tests/resource.test.php.stub | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Commands/Generator/stubs/tests/resource.pest.php.stub b/src/Commands/Generator/stubs/tests/resource.pest.php.stub index 1f7bee3..e4a35b1 100644 --- a/src/Commands/Generator/stubs/tests/resource.pest.php.stub +++ b/src/Commands/Generator/stubs/tests/resource.pest.php.stub @@ -16,7 +16,10 @@ describe('{{ modelClassName }}', function (): void { $response = getJson( uri: route('api.v1.filament.{{ $modelVarPlural }}.show', ${{ $modelVarSingular }}), - headers: ['x-rest-presenter' => '{{ modelClassName }}'], + headers: [ + 'x-rest-presenter-api-key' => config('rest-presenter.auth.key'), + 'x-rest-presenter' => '{{ modelClassName }}' + ], )->assertOk()->json(); expect($response) @@ -29,7 +32,10 @@ describe('{{ modelClassName }}', function (): void { test('can list all {{ $modelVarPlural }}', function (): void { $response = getJson( uri: route('api.v1.filament.{{ $modelVarPlural }}.index'), - headers: ['x-rest-presenter' => '{{ modelClassName }}'], + headers: [ + 'x-rest-presenter-api-key' => config('rest-presenter.auth.key'), + 'x-rest-presenter' => '{{ modelClassName }}' + ], )->assertOk()->json(); expect($response) diff --git a/src/Commands/Generator/stubs/tests/resource.test.php.stub b/src/Commands/Generator/stubs/tests/resource.test.php.stub index 91011cb..e37b647 100644 --- a/src/Commands/Generator/stubs/tests/resource.test.php.stub +++ b/src/Commands/Generator/stubs/tests/resource.test.php.stub @@ -36,7 +36,10 @@ class {{ testClassName }} extends TestCase $response = $this->json( method: 'GET', uri: route('api.v1.filament.{{ $modelVarPlural }}.show', ${{ $modelVarSingular }}->id), - headers: ['x-rest-presenter' => '{{ modelClassName }}'] + headers: [ + 'x-rest-presenter-api-key' => config('rest-presenter.auth.key'), + 'x-rest-presenter' => '{{ modelClassName }}' + ], ); $response->assertStatus(200); @@ -58,7 +61,10 @@ class {{ testClassName }} extends TestCase $response = $this->json( method: 'GET', uri: route('api.v1.filament.{{ $modelVarPlural }}.index'), - headers: ['x-rest-presenter' => '{{ modelClassName }}'] + headers: [ + 'x-rest-presenter-api-key' => config('rest-presenter.auth.key'), + 'x-rest-presenter' => '{{ modelClassName }}' + ], ); $response->assertStatus(200); From af9418e5bf4d006abbfd4b2405add0892cb99af1 Mon Sep 17 00:00:00 2001 From: Adam Lee Date: Mon, 13 May 2024 16:56:32 +0100 Subject: [PATCH 7/9] chore: release v1.0.0-rc.2 --- CHANGELOG.md | 7 +++++++ composer.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c460cbc..743a3e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog for RESTPresenter +## [1.0.0-rc.2](https://github.com/xtend-packages/rest-presenter/compare/1.0.0-rc.1...1.0.0-rc.2) (2024-05-13) + + +### Bug Fixes + +* Include API key with test generation ([79de5b1](https://github.com/xtend-packages/rest-presenter/commit/79de5b1791e4209a32cea61c992704ac390514cf)) + ## [1.0.0-rc.1](https://github.com/xtend-packages/rest-presenter/compare/1.0.0-rc.0...1.0.0-rc.1) (2024-05-13) diff --git a/composer.json b/composer.json index a259d36..c3bd4c3 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "xtend-packages/rest-presenter", - "version": "1.0.0-rc.1", + "version": "1.0.0-rc.2", "description": "REST API Presenter & Generator for Laravel", "keywords": [ "code-labx", From dd12bb60ca1e83f90de06871fa9a475178ce3dd1 Mon Sep 17 00:00:00 2001 From: Adam Lee Date: Mon, 13 May 2024 22:53:11 +0100 Subject: [PATCH 8/9] docs: Update to use correct version + test failure advice --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fd4029b..97aba37 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Please follow the steps below to get started: Install package ("minimum-stability": "dev", may be required in your composer.json file): ```bash -composer require xtend-packages/rest-presenter +composer require xtend-packages/rest-presenter:^1.0.0 ```` Run the direct setup command for our Filament starter kit to avoid prompts: ```bash @@ -53,6 +53,10 @@ REST_PRESENTER_EXPORT_PROVIDER=insomnia Without this update, it will use your default database connection and refresh the database after each test. +### Tests Failing! Missing Factory Relationships? +If you encounter any issues with the tests, please update your factories to include relationships for your models.\ +For example, if you have a Post model but your factory is missing author_id, you will need to update your factory to include this relationship. + ### API Collection Auto-Generation Make sure you only run this command after the setup command to generate your API collection. @@ -130,7 +134,7 @@ RESTPresenter is more than just a CRUD generator. It offers: You can install the package via composer: ```bash -composer require xtend-packages/rest-presenter +composer require xtend-packages/rest-presenter:^1.0.0 ``` Please note: if you receive an error during installing this package, you may need to update your minimum stability requirement to dev in your composer.json file: From ef891b9c4c3c9d198f30446871d2a9df873cc7d9 Mon Sep 17 00:00:00 2001 From: Adam Lee Date: Tue, 14 May 2024 23:01:06 +0100 Subject: [PATCH 9/9] fix: Hide duplicated logo for filament plugin --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 97aba37..a99396c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ - + XtendLaravel