File tree Expand file tree Collapse file tree 3 files changed +28
-6
lines changed Expand file tree Collapse file tree 3 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -147,7 +147,9 @@ describe('API functions', () => {
147147 } ;
148148
149149 // Use type assertion to bypass TypeScript check for testing runtime validation
150- expect ( ( ) => registerAbility ( ability as unknown as ClientAbility ) ) . toThrow (
150+ expect ( ( ) =>
151+ registerAbility ( ability as unknown as ClientAbility )
152+ ) . toThrow (
151153 'Server abilities cannot be registered via registerAbility'
152154 ) ;
153155 } ) ;
@@ -170,9 +172,9 @@ describe('API functions', () => {
170172 } ;
171173
172174 // Use type assertion to bypass TypeScript check
173- expect ( ( ) => registerAbility ( ability as unknown as ClientAbility ) ) . toThrow (
174- 'Client abilities must include a callback function'
175- ) ;
175+ expect ( ( ) =>
176+ registerAbility ( ability as unknown as ClientAbility )
177+ ) . toThrow ( 'Client abilities must include a callback function' ) ;
176178 } ) ;
177179
178180 it ( 'should throw error for ability without name' , ( ) => {
Original file line number Diff line number Diff line change @@ -382,8 +382,18 @@ describe('validateValueFromSchema', () => {
382382 it ( 'should handle empty schema as valid' , ( ) => {
383383 expect ( validateValueFromSchema ( 'anything' , undefined ) ) . toBe ( true ) ;
384384 // Testing edge cases where schema is null or falsy
385- expect ( validateValueFromSchema ( 123 , null as unknown as Record < string , any > ) ) . toBe ( true ) ;
386- expect ( validateValueFromSchema ( true , false as unknown as Record < string , any > ) ) . toBe ( true ) ;
385+ expect (
386+ validateValueFromSchema (
387+ 123 ,
388+ null as unknown as Record < string , any >
389+ )
390+ ) . toBe ( true ) ;
391+ expect (
392+ validateValueFromSchema (
393+ true ,
394+ false as unknown as Record < string , any >
395+ )
396+ ) . toBe ( true ) ;
387397 } ) ;
388398
389399 it ( 'should handle schema compilation errors' , ( ) => {
Original file line number Diff line number Diff line change @@ -71,6 +71,16 @@ export function registerAbility(ability: Ability): void {
7171 if ( ! ability . description ) {
7272 throw new Error ( __ ( 'Ability description is required' ) ) ;
7373 }
74+
75+ // Runtime check for JavaScript consumers who might pass server abilities
76+ // TypeScript users are protected by the ClientAbility type
77+ const anyAbility = ability as any ;
78+ if ( anyAbility . location === 'server' ) {
79+ throw new Error (
80+ 'Server abilities cannot be registered via registerAbility'
81+ ) ;
82+ }
83+
7484 if ( ! ability . callback || typeof ability . callback !== 'function' ) {
7585 throw new Error ( __ ( 'Abilities registered on the client require a callback function' ) ) ;
7686 }
You can’t perform that action at this time.
0 commit comments