Skip to content
Skillpedia
Security8.1k Β· #12589

webiny-api-permissions

What it does

This skill guides your AI when adding permission rules to backend code in Webiny. It is for developers who need to control who can read, change or delete records.

When to use it

  • βœ“When a backend use case must check whether a user can read, edit, delete or publish.
  • βœ“When records should be limited to their owner.
  • βœ“When you need to write tests for permission scenarios.

Skill link

https://github.com/webiny/webiny-js/blob/next/skills/user-skills/api/permissions/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/webiny/webiny-js/blob/next/skills/user-skills/api/permissions/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute β†’

Example of what to ask your AI

β€œOnly let users edit their own products in our Webiny API, and check the permission in the update use case.”

5 new skills a week. 1 minute to read.

How it works

The skill explains how to define a permission schema for each area, then inject a typed permission check into use cases. The check methods replace manual lookups of the user's permissions.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

API Permissions

Overview

Permissions follow two layers: domain (schema) and features (DI abstractions + feature registration). Each package declares a permission schema and gets a typed Permissions abstraction injectable into use cases via DI. Methods like canRead, canEdit, canDelete, canPublish, onlyOwnRecords replace manual identityContext.getPermission() calls.

Layer 1: Domain β€” Permission Schema

Define the schema in src/domain/permissionsSchema.ts:

import { createPermissionSchema } from "webiny/api/security";

export const SM_PERMISSIONS_SCHEMA = createPermissionSchema({
  prefix: "sm",
  fullAccess: true,
  entities: [
    {
      id: "product",
      permission: "sm.product",
      scopes: ["full", "own"],
      actions: [{ name: "rwd" }, { name: "pw" }]
    },
    {
      id: "settings",
      permission: "sm.settings",
      scopes: ["full"]
    }
  ]
});

The schema MUST use as const inference (handled by createPermissionSchema) for TypeScript to narrow entity IDs in method signatures.

Schema Fields

Field Description
prefix Namespaces the DI abstraction: ${prefix}:Permissions
fullAccess true for standard full access. Pass an object with custom boolean flags for full-access extras (e.g., { canForceUnlock: true }).
entities[].id Entity identifier used in method calls: canRead("product")
entities[].permission Permission name matched against identity permissions
entities[].scopes ["full"] or ["full", "own"] β€” determines if own-scope supported
entities[].actions Action definitions β€” built-in: "rwd", "pw"; custom: boolean flags

Scopes

  • "full" β€” User can access all records (default when no own flag on permission object)
  • "own" β€” User can only access records where createdBy.id === identity.id

Simple Apps (No Entities)

Omit entities for binary full/no access:

export const MA_PERMISSIONS_SCHEMA = createPermissionSchema({
  prefix: "ma",
  fullAccess: true
});

Layer 2: Features β€” DI Artifacts + Registration

Abstraction (src/features/permissions/abstractions.ts)

import { createPermissionsAbstraction } from "webiny/api/security";
import type { Permissions } from "webiny/api/security";
import { SM_PERMISSIONS_SCHEMA } from "~/domain/permissionsSchema.js";

export const SmPermissions = createPermissionsAbstraction(SM_PERMISSIONS_SCHEMA);

export namespace SmPermissions {
  export type Interface = Permissions<typeof SM_PERMISSIONS_SCHEMA>;
}

Feature (src/features/permissions/feature.ts)

import { createPermissionsFeature } from "webiny/api/security";
import { SM_PERMISSIONS_SCHEMA } from "~/domain/permissionsSchema.js";
import { SmPermissions } from "./abstractions.js";

export const SmPermissionsFeature = createPermissionsFeature(SM_PERMISSIONS_SCHEMA, SmPermissions);

Registration

Register the feature in your context plugin:

import { SmPermissionsFeature } from "~/features/permissions/feature.js";

// In createContext:
SmPermissionsFeature.register(container);

File Structure

src/
β”œβ”€β”€ domain/
β”‚   └── permissionsSchema.ts              # createPermissionSchema()
β”œβ”€β”€ features/
β”‚   └── permissions/
β”‚       β”œβ”€β”€ abstractions.ts               # createPermissionsAbstraction() + namespace type
β”‚       └── feature.ts                    # createPermissionsFeature()
└── index.ts                              # SmPermissionsFeature.register(container)

Permission Methods

All methods follow a 3-tier bypass:

  1. identityContext.hasFullAccess() β†’ name: "*" permission (super admin)
  2. hasFullSchemaAccess() β†’ wildcard permission (e.g. "sm.*")
  3. Entity-level permission check

Method Referen

FAQ

What does the permission schema define?

The entities, their permission names, scopes and actions, such as full or own scope.

How are own-record rules handled?

The skill covers own-record scoping through a method that checks only owned records.

Can permissions be tested?

Yes. The skill includes guidance on testing permission scenarios.

Details

Original description by the author

Schema-based permission system for API features. Use this skill when implementing authorization in use cases, defining permission schemas with createPermissionSchema, creating injectable permissions via createPermissionsAbstraction/createPermissionsFeature, checking read/write/delete/publish permissions, handling own-record scoping, or testing permission scenarios. Covers the full pattern from schema definition to use case integration to test matrices.

repo: webiny/webiny-js

Popularity

GitHub stars
8.1k
Ranking position
#12589
License
β€”
Updated
11/2/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills