Skip to content

Commit fabe5af

Browse files
committed
fix: Update AbilityInput type to accept any JSON value
1 parent 48513c8 commit fabe5af

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

packages/client/src/api.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export async function getAbility( name: string ): Promise< Ability | null > {
4242
*/
4343
export async function executeAbility(
4444
name: string,
45-
input: AbilityInput = {}
45+
input: AbilityInput = null
4646
): Promise< AbilityOutput > {
4747
const ability = await getAbility( name );
4848
if ( ! ability ) {
@@ -60,14 +60,20 @@ export async function executeAbility(
6060
method,
6161
};
6262

63-
if ( method === 'GET' && Object.keys( input ).length > 0 ) {
63+
if ( method === 'GET' && input !== null && typeof input === 'object' && ! Array.isArray( input ) && Object.keys( input ).length > 0 ) {
64+
// For GET requests with object inputs, convert to URL parameters
6465
// e.g., input[format]=iso&input[timezone]=UTC
6566
const params = new URLSearchParams();
6667
Object.entries( input ).forEach( ( [ key, value ] ) => {
6768
params.append( `input[${ key }]`, String( value ) );
6869
} );
6970
path = `${ path }?${ params.toString() }`;
70-
} else if ( method === 'POST' ) {
71+
} else if ( method === 'GET' && input !== null ) {
72+
// For GET requests with non-object inputs, pass as single parameter
73+
const params = new URLSearchParams();
74+
params.append( 'input', JSON.stringify( input ) );
75+
path = `${ path }?${ params.toString() }`;
76+
} else if ( method === 'POST' && input !== null ) {
7177
options.data = { input };
7278
}
7379

packages/client/src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ export interface AbilitiesState {
6464

6565
/**
6666
* Input parameters for ability execution.
67+
* Can be any JSON-serializable value: primitive, array, object, or null.
6768
*/
68-
export type AbilityInput = Record< string, any >;
69+
export type AbilityInput = any;
6970

7071
/**
7172
* Result from ability execution.

0 commit comments

Comments
 (0)