Download the PHP package rafalmasiarek/dashboard-kit-addon-api without Composer
On this page you can find all versions of the php package rafalmasiarek/dashboard-kit-addon-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rafalmasiarek/dashboard-kit-addon-api
More information about rafalmasiarek/dashboard-kit-addon-api
Files in rafalmasiarek/dashboard-kit-addon-api
Package dashboard-kit-addon-api
Short Description API plugin for dashboard-kit: token auth with scopes, versioned module routes, OpenAPI registry.
License BUSL-1.1
Informations about the package dashboard-kit-addon-api
dashboard-kit-addon-api
API plugin for rafalmasiarek/dashboard-kit. Adds Bearer token authentication with per-route scope enforcement, admin UI for token and scope management, user self-service token page, and a structured audit trail.
Requirements
- PHP 8.2+
rafalmasiarek/dashboard-kit- MySQL 8 or SQLite
Installation
The plugin is registered automatically when the package is installed. No additional configuration is required.
Features
Token authentication
Every versioned API route (/v1/...) is protected by a Bearer token:
Tokens are created by users from /settings/api-tokens or by admins from /admin/api/tokens.
Scope enforcement
Routes declare required scopes. A token must carry all required scopes to pass:
Super-scopes * and admin:* bypass all scope checks. Namespace wildcards (notes:*) satisfy any notes:{action} requirement.
Scope management
Admins define global scopes and assign subsets to individual users:
- Create scopes at
/admin/api/scopes(e.g.notes:read,notes:write) - Assign scopes to a user via Admin → Users → API Scopes
- User can now create tokens using only their assigned scopes
- Admins can create tokens with any scope regardless of assignments
JSON response envelope
All API responses follow a consistent shape:
Error responses:
Audit trail
Every API request is logged to the logger.api channel (falls back to logger.audit):
Token values are never logged in full — only the first 8 characters are stored as a correlation prefix.
Defining API routes
Routes are declared under the api key in module.php. The contract — parameters, request body, and responses — is defined once at the top level. The framework uses it for both OpenAPI generation and runtime behavior: type casting, error map derivation, and response envelope building.
Handler return shape
| Return value | Result |
|---|---|
['data' => $payload] |
200 OK |
['data' => ..., 'http' => 201, 'message' => 'Created'] |
Custom status and message |
['error' => 'CODE'] |
HTTP status and message from responses declaration |
['error' => 'CODE', 'message' => 'Custom message.'] |
Overrides the message from responses |
['error' => 'CODE', 'field' => 'email', 'detail' => '...'] |
Adds field and detail to errors[0] |
['error' => 'CODE', 'http' => 410] |
Overrides the HTTP status from responses |
field and detail are appended to the errors array alongside code:
All override keys can be combined freely:
What the framework does automatically
- Casts path and query params to declared types (
integer,number,boolean,string) - Derives the error map from
responsesentries that carry a'code'key - Validates the request body root type and per-property types before calling the handler
- Calls
JsonHandler::ok()orJsonHandler::err()with the correct envelope - Builds OpenAPI
parameters,requestBody, andresponsesfrom the same top-level keys - For paginated endpoints: injects
page/limit/offsetinto$params, computes thepaginationfield, and addspage/per_pagequery params to the OpenAPI spec automatically
params
Declares path and query parameters. The type field drives both OpenAPI and runtime casting:
Supported types: integer, number, boolean, string.
body
Optional. Declares the JSON schema of the request body. Used as the OpenAPI requestBody schema and made available to the handler as $body:
The framework validates the body before calling the handler and returns an error if the structure is invalid:
| Error code | HTTP | Condition |
|---|---|---|
MALFORMED_JSON |
400 | Content-Type: application/json sent with non-JSON content |
INVALID_BODY_TYPE |
400 | Body root type does not match the declared type |
INVALID_FIELD_TYPE |
422 | A declared property has the wrong type |
These errors are returned by the framework directly — they do not need to be listed in the route's responses declaration.
responses
Declares all possible response codes. Entries with a 'code' key become part of the runtime error map; entries with a 'schema' key describe the data payload in the OpenAPI spec:
pagination
Optional. Enables automatic pagination for list endpoints. When declared, the framework injects page, limit, and offset into $params and computes the pagination envelope field from the total key returned by the handler:
Client query params: ?page=2&per_page=10. The response includes a top-level pagination object:
The pagination field is absent from non-paginated endpoints. The OpenAPI spec automatically includes page and per_page query parameters and a representative pagination example for 2xx responses.
OpenAPI specification
A full OpenAPI 3.1 spec is generated automatically from all module route definitions and served at a configurable endpoint:
The openapi sub-key on a route carries documentation-only metadata:
Standard 401/403 responses are auto-injected for all routes that declare scopes.
Other plugins can extend the spec when the API plugin is installed:
To use a dedicated log channel, add logger.api to your dashboard-kit logging configuration:
Admin routes
| Route | Description |
|---|---|
GET /admin/api/scopes |
List all scopes |
POST /admin/api/scopes |
Create a scope |
POST /admin/api/scopes/{id}/delete |
Delete a scope |
GET /admin/api/tokens |
List all tokens (all users) |
POST /admin/api/tokens |
Create a token (any scope) |
POST /admin/api/tokens/{token}/revoke |
Revoke any token |
GET /admin/api/users/{id}/scopes |
View/edit scope assignments for a user |
POST /admin/api/users/{id}/scopes |
Save scope assignments |
User routes
| Route | Description |
|---|---|
GET /settings/api-tokens |
List own tokens, create new token |
POST /settings/api-tokens |
Create token (assigned scopes only) |
POST /settings/api-tokens/{token}/revoke |
Revoke own token |
Database tables
Auto-migrated on first boot:
| Table | Description |
|---|---|
user_tokens |
Issued tokens with optional subject and expiry |
token_scopes |
Token → scope assignments |
scopes |
Global scope registry (name, category, description) |
user_scopes |
Per-user scope assignments |
System tables managed by dashboard-kit core (never prefixed):
| Table | Description |
|---|---|
_schema_state |
Schema hash per table — drives the schema sync fast path |
_table_version |
Per-table write counters — drives SELECT cache invalidation |
_query_cache |
Cached SELECT results with TTL |
License
Business Source License 1.1 — see LICENSE. For alternative licensing, contact us.
All versions of dashboard-kit-addon-api with dependencies
rafalmasiarek/dashboard-kit Version *
slim/slim Version ^4.0
slim/psr7 Version ^1.0