Skip to content
This repository was archived by the owner on Feb 5, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
# Files and directories to exclude from the generated archive (export-ignore).
# These will be omitted from GitHub/Packagist ZIP archives to keep packages small.

# Exclude specific files/dirs from packages/client, keeping build dirs.
/packages/client/src/ export-ignore
/packages/client/.* export-ignore
/packages/client/*.* export-ignore

# Tests and test fixtures
/tests/ export-ignore

Expand Down
5 changes: 0 additions & 5 deletions packages/client/.gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# Dependencies
node_modules/

# Build output
build/
build-module/
build-types/

# TypeScript
*.tsbuildinfo

Expand Down
67 changes: 67 additions & 0 deletions packages/client/build-types/api.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import type { Ability, AbilityInput, AbilityOutput } from './types';
/**
* Get all available abilities.
*
* @return Promise resolving to array of abilities.
*/
export declare function getAbilities(): Promise<Ability[]>;
/**
* Get a specific ability by name.
*
* @param name The ability name.
* @return Promise resolving to the ability or null if not found.
*/
export declare function getAbility(name: string): Promise<Ability | null>;
/**
* Register a client-side ability.
*
* Client abilities are executed locally in the browser and must include
* a callback function. The ability will be validated by the store action,
* and an error will be thrown if validation fails.
*
* @param ability The ability definition including callback.
* @throws {Error} If the ability fails validation.
*
* @example
* ```js
* registerAbility({
* name: 'my-plugin/navigate',
* label: 'Navigate to URL',
* description: 'Navigates to a URL within WordPress admin',
* input_schema: {
* type: 'object',
* properties: {
* url: { type: 'string' }
* },
* required: ['url']
* },
* callback: async ({ url }) => {
* window.location.href = url;
* return { success: true };
* }
* });
* ```
*/
export declare function registerAbility(ability: Ability): void;
/**
* Unregister an ability from the store.
*
* Remove a client-side ability from the store.
* Note: This will return an error for server-side abilities.
*
* @param name The ability name to unregister.
*/
export declare function unregisterAbility(name: string): void;
/**
* Execute an ability.
*
* Determines whether to execute locally (client abilities) or remotely (server abilities)
* based on whether the ability has a callback function.
*
* @param name The ability name.
* @param input Optional input parameters for the ability.
* @return Promise resolving to the ability execution result.
* @throws Error if the ability is not found or execution fails.
*/
export declare function executeAbility(name: string, input?: AbilityInput): Promise<AbilityOutput>;
//# sourceMappingURL=api.d.ts.map
1 change: 1 addition & 0 deletions packages/client/build-types/api.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions packages/client/build-types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* WordPress Abilities API Client
*
* This package provides a client for interacting with the
* WordPress Abilities API, allowing you to list, retrieve, and execute
* abilities from client-side code.
*
* @package
*/
import * as api from './api';
import { store } from './store';
/**
* TypeScript declaration for the global wp object
*/
declare global {
interface Window {
wp: {
abilities?: typeof api & {
store: typeof store;
};
[key: string]: any;
};
}
}
/**
* Public API functions
*/
export { getAbilities, getAbility, executeAbility, registerAbility, unregisterAbility, } from './api';
/**
* The store can be used directly with @wordpress/data via selectors
* in React components with useSelect.
*
* @example
* ```js
* import { useSelect } from '@wordpress/data';
* import { store as abilitiesStore } from '@wordpress/abilities';
*
* function MyComponent() {
* const abilities = useSelect(
* (select) => select(abilitiesStore).getAbilities(),
* []
* );
* // Use abilities...
* }
* ```
*/
export { store } from './store';
/**
* Type definitions
*/
export type { Ability, AbilitiesState, AbilityCallback, PermissionCallback, AbilityInput, AbilityOutput, ValidationError, } from './types';
/**
* Validation utilities
*/
export { validateValueFromSchema } from './validation';
//# sourceMappingURL=index.d.ts.map
1 change: 1 addition & 0 deletions packages/client/build-types/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions packages/client/build-types/store/actions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Internal dependencies
*/
import type { Ability } from '../types';
/**
* Returns an action object used to receive abilities into the store.
*
* @param abilities Array of abilities to store.
* @return Action object.
*/
export declare function receiveAbilities(abilities: Ability[]): {
type: string;
abilities: Ability[];
};
/**
* Registers an ability in the store.
*
* This action validates the ability before registration. If validation fails,
* an error will be thrown.
*
* @param ability The ability to register.
* @return Action object or function.
* @throws {Error} If validation fails.
*/
export declare function registerAbility(ability: Ability): ({ select, dispatch }: {
select: any;
dispatch: any;
}) => void;
/**
* Returns an action object used to unregister a client-side ability.
*
* @param name The name of the ability to unregister.
* @return Action object.
*/
export declare function unregisterAbility(name: string): {
type: string;
name: string;
};
//# sourceMappingURL=actions.d.ts.map
1 change: 1 addition & 0 deletions packages/client/build-types/store/actions.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions packages/client/build-types/store/constants.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Store constants
*/
export declare const STORE_NAME = "abilities-api/abilities";
export declare const ENTITY_KIND = "root";
export declare const ENTITY_NAME = "abilities";
export declare const RECEIVE_ABILITIES = "RECEIVE_ABILITIES";
export declare const REGISTER_ABILITY = "REGISTER_ABILITY";
export declare const UNREGISTER_ABILITY = "UNREGISTER_ABILITY";
//# sourceMappingURL=constants.d.ts.map
1 change: 1 addition & 0 deletions packages/client/build-types/store/constants.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions packages/client/build-types/store/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as actions from './actions';
import * as selectors from './selectors';
/**
* The abilities store definition.
*/
export declare const store: import("@wordpress/data/build-types/types").StoreDescriptor<import("@wordpress/data/build-types/types").ReduxStoreConfig<unknown, typeof actions, typeof selectors>>;
//# sourceMappingURL=index.d.ts.map
1 change: 1 addition & 0 deletions packages/client/build-types/store/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions packages/client/build-types/store/reducer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Internal dependencies
*/
import type { Ability } from '../types';
interface AbilitiesAction {
type: string;
abilities?: Ability[];
ability?: Ability;
name?: string;
}
declare const _default: import("redux").Reducer<{
abilitiesByName: Record<string, Ability>;
}, AbilitiesAction, Partial<{
abilitiesByName: Record<string, Ability> | undefined;
}>>;
export default _default;
//# sourceMappingURL=reducer.d.ts.map
1 change: 1 addition & 0 deletions packages/client/build-types/store/reducer.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions packages/client/build-types/store/resolvers.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Resolver for getAbilities selector.
* Fetches all abilities from the server.
*/
export declare function getAbilities(): ({ dispatch, registry }: {
dispatch: any;
registry: any;
}) => Promise<void>;
/**
* Resolver for getAbility selector.
* Fetches a specific ability from the server if not already in store.
*
* @param name Ability name.
*/
export declare function getAbility(name: string): ({ dispatch, registry, select }: {
dispatch: any;
registry: any;
select: any;
}) => Promise<void>;
//# sourceMappingURL=resolvers.d.ts.map
1 change: 1 addition & 0 deletions packages/client/build-types/store/resolvers.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions packages/client/build-types/store/selectors.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Internal dependencies
*/
import type { Ability, AbilitiesState } from '../types';
/**
* Returns all registered abilities.
*
* @param state Store state.
* @return Array of abilities.
*/
export declare const getAbilities: ((state: AbilitiesState) => Ability[]) & import("rememo").EnhancedSelector;
/**
* Returns a specific ability by name.
*
* @param state Store state.
* @param name Ability name.
* @return Ability object or null if not found.
*/
export declare function getAbility(state: AbilitiesState, name: string): Ability | null;
//# sourceMappingURL=selectors.d.ts.map
1 change: 1 addition & 0 deletions packages/client/build-types/store/selectors.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

93 changes: 93 additions & 0 deletions packages/client/build-types/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* WordPress Abilities API Types
*/
/**
* Callback function for client-side abilities.
*/
export type AbilityCallback = (input: AbilityInput) => AbilityOutput | Promise<AbilityOutput>;
/**
* Permission callback function for client-side abilities.
* Returns true if the ability can be executed, false otherwise.
*/
export type PermissionCallback = (input?: AbilityInput) => boolean | Promise<boolean>;
/**
* Represents an ability in the WordPress Abilities API.
*
* @see WP_Ability
*/
export interface Ability {
/**
* The unique name/identifier of the ability, with its namespace.
* Example: 'my-plugin/my-ability'
* @see WP_Ability::get_name()
*/
name: string;
/**
* The human-readable label for the ability.
* @see WP_Ability::get_label()
*/
label: string;
/**
* The detailed description of the ability.
* @see WP_Ability::get_description()
*/
description: string;
/**
* JSON Schema for the ability's input parameters.
* @see WP_Ability::get_input_schema()
*/
input_schema?: Record<string, any>;
/**
* JSON Schema for the ability's output format.
* @see WP_Ability::get_output_schema()
*/
output_schema?: Record<string, any>;
/**
* Callback function for client-side abilities.
* If present, the ability will be executed locally in the browser.
* If not present, the ability will be executed via REST API on the server.
*/
callback?: AbilityCallback;
/**
* Client Permission callback for abilities.
* Called before executing the ability to check if it's allowed.
* If it returns false, the ability execution will be denied.
*/
permissionCallback?: PermissionCallback;
/**
* Metadata about the ability.
* @see WP_Ability::get_meta()
*/
meta?: {
/**
* The type of ability - 'resource' uses GET, 'tool' uses POST.
*/
type?: 'resource' | 'tool';
[key: string]: any;
};
}
/**
* The state shape for the abilities store.
*/
export interface AbilitiesState {
/**
* Map of ability names to ability objects.
*/
abilitiesByName: Record<string, Ability>;
}
/**
* Input parameters for ability execution.
* Can be any JSON-serializable value: primitive, array, object, or null.
*/
export type AbilityInput = any;
/**
* Result from ability execution.
* The actual shape depends on the ability's output schema.
*/
export type AbilityOutput = any;
/**
* Validation error - just a message string.
* The Abilities API wraps this with the appropriate error code.
*/
export type ValidationError = string;
//# sourceMappingURL=types.d.ts.map
1 change: 1 addition & 0 deletions packages/client/build-types/types.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading