Installation
@admicaa/netpress-permissions is published as a standalone package that depends on @admicaa/netpress as a peer. This page walks through installing it and getting the tables in place.
Requirements
- Node.js 18 or newer
- A running NetPress application (
@admicaa/netpress>=0.1.6) - A configured database connection (SQL or Mongo)
If you have not set up the framework itself yet, start with the core NetPress package and app scaffold first: <https://github.com/admicaa/netpress>
Install The Package
npm install @admicaa/netpress-permissions
The package ships with no runtime dependencies of its own. Knex and Better SQLite are devDependencies used for the test suite only.
Publish The Package Assets
Run the vendor:publish command from your NetPress application:
npm run artisan -- vendor:publish --provider=NetpressPermissionsServiceProvider
This will prompt you to pick a database connection (if you have more than one configured) and will create:
config/permissions.js— the application-level configurationdatabase/migrations/*_create_permission_tables.js— the migrationapp/Providers/PermissionsServiceProvider.js— a thin wrapper you can customise- registers the provider automatically in
bootstrap/providers.js
If you pick a Mongo connection the generated migration automatically targets that Mongo connection (schema.connection('mongo')).
Run The Migration
npm run migrate
The migration creates five tables (or collections) derived from your config:
rolespermissionsrole_has_permissionsmodel_has_rolesmodel_has_permissions
See Migrations for a deeper dive on the schema.
Verify
Fire up a quick REPL or write a minimal test:
import { Role, Permission } from '@admicaa/netpress-permissions';
const editor = await Role.findOrCreate('editor');
const publish = await Permission.findOrCreate('posts.publish');
await editor.givePermissionTo(publish);
If the findOrCreate calls succeed, the package is wired up correctly and you are ready to head to Roles and Permissions.