@wordpress/abilities 0.22.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.cjs.map +1 -1
- package/build-module/index.mjs.map +1 -1
- package/build-types/index.d.ts +1 -1
- package/package.json +21 -8
- package/src/index.ts +1 -1
- package/src/tests/api.test.ts +2 -12
- package/src/tests/validation.test.ts +11 -56
- package/CHANGELOG.md +0 -59
package/build/index.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress Abilities API Client\n *\n * This package provides a client for interacting with the\n * WordPress Abilities API, allowing you to list, retrieve, and execute\n * abilities from client-side code.\n *\n * @package\n */\n\n/**\n * Public API functions\n */\nexport {\n\tgetAbilities,\n\tgetAbility,\n\tgetAbilityCategories,\n\tgetAbilityCategory,\n\texecuteAbility,\n\tregisterAbility,\n\tunregisterAbility,\n\tregisterAbilityCategory,\n\tunregisterAbilityCategory,\n} from './api';\n\n/**\n * The store can be used directly with
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress Abilities API Client\n *\n * This package provides a client for interacting with the\n * WordPress Abilities API, allowing you to list, retrieve, and execute\n * abilities from client-side code.\n *\n * @package\n */\n\n/**\n * Public API functions\n */\nexport {\n\tgetAbilities,\n\tgetAbility,\n\tgetAbilityCategories,\n\tgetAbilityCategory,\n\texecuteAbility,\n\tregisterAbility,\n\tunregisterAbility,\n\tregisterAbilityCategory,\n\tunregisterAbilityCategory,\n} from './api';\n\n/**\n * The store can be used directly with `@wordpress/data` via selectors\n * in React components with useSelect.\n *\n * @example\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as abilitiesStore } from '@wordpress/abilities';\n *\n * function MyComponent() {\n * const abilities = useSelect(\n * (select) => select(abilitiesStore).getAbilities(),\n * []\n * );\n * // Use abilities...\n * }\n * ```\n */\nexport { store } from './store';\n\n/**\n * Type definitions\n */\nexport type {\n\tAbility,\n\tAbilityCategory,\n\tAbilityCategoryArgs,\n\tAbilitiesQueryArgs,\n\tAbilityCallback,\n\tPermissionCallback,\n\tAbilityInput,\n\tAbilityOutput,\n\tValidationError,\n} from './types';\n\n/**\n * Validation utilities\n */\nexport { validateValueFromSchema } from './validation';\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA,iBAUO;AAoBP,mBAAsB;AAoBtB,wBAAwC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress Abilities API Client\n *\n * This package provides a client for interacting with the\n * WordPress Abilities API, allowing you to list, retrieve, and execute\n * abilities from client-side code.\n *\n * @package\n */\n\n/**\n * Public API functions\n */\nexport {\n\tgetAbilities,\n\tgetAbility,\n\tgetAbilityCategories,\n\tgetAbilityCategory,\n\texecuteAbility,\n\tregisterAbility,\n\tunregisterAbility,\n\tregisterAbilityCategory,\n\tunregisterAbilityCategory,\n} from './api';\n\n/**\n * The store can be used directly with
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress Abilities API Client\n *\n * This package provides a client for interacting with the\n * WordPress Abilities API, allowing you to list, retrieve, and execute\n * abilities from client-side code.\n *\n * @package\n */\n\n/**\n * Public API functions\n */\nexport {\n\tgetAbilities,\n\tgetAbility,\n\tgetAbilityCategories,\n\tgetAbilityCategory,\n\texecuteAbility,\n\tregisterAbility,\n\tunregisterAbility,\n\tregisterAbilityCategory,\n\tunregisterAbilityCategory,\n} from './api';\n\n/**\n * The store can be used directly with `@wordpress/data` via selectors\n * in React components with useSelect.\n *\n * @example\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as abilitiesStore } from '@wordpress/abilities';\n *\n * function MyComponent() {\n * const abilities = useSelect(\n * (select) => select(abilitiesStore).getAbilities(),\n * []\n * );\n * // Use abilities...\n * }\n * ```\n */\nexport { store } from './store';\n\n/**\n * Type definitions\n */\nexport type {\n\tAbility,\n\tAbilityCategory,\n\tAbilityCategoryArgs,\n\tAbilitiesQueryArgs,\n\tAbilityCallback,\n\tPermissionCallback,\n\tAbilityInput,\n\tAbilityOutput,\n\tValidationError,\n} from './types';\n\n/**\n * Validation utilities\n */\nexport { validateValueFromSchema } from './validation';\n"],
|
|
5
5
|
"mappings": ";AAaA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAoBP,SAAS,aAAa;AAoBtB,SAAS,+BAA+B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build-types/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
export { getAbilities, getAbility, getAbilityCategories, getAbilityCategory, executeAbility, registerAbility, unregisterAbility, registerAbilityCategory, unregisterAbilityCategory, } from './api';
|
|
14
14
|
/**
|
|
15
|
-
* The store can be used directly with
|
|
15
|
+
* The store can be used directly with `@wordpress/data` via selectors
|
|
16
16
|
* in React components with useSelect.
|
|
17
17
|
*
|
|
18
18
|
* @example
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/abilities",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "JavaScript client for WordPress Abilities API.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -20,14 +20,13 @@
|
|
|
20
20
|
"url": "https://github.com/WordPress/gutenberg/issues"
|
|
21
21
|
},
|
|
22
22
|
"engines": {
|
|
23
|
-
"node": ">=
|
|
23
|
+
"node": ">=22.13.0"
|
|
24
24
|
},
|
|
25
25
|
"files": [
|
|
26
26
|
"src",
|
|
27
27
|
"build",
|
|
28
28
|
"build-module",
|
|
29
|
-
"build-types"
|
|
30
|
-
"*.md"
|
|
29
|
+
"build-types"
|
|
31
30
|
],
|
|
32
31
|
"main": "build/index.cjs",
|
|
33
32
|
"module": "build-module/index.mjs",
|
|
@@ -44,17 +43,31 @@
|
|
|
44
43
|
},
|
|
45
44
|
"types": "build-types",
|
|
46
45
|
"dependencies": {
|
|
47
|
-
"@wordpress/data": "^
|
|
48
|
-
"@wordpress/i18n": "^
|
|
46
|
+
"@wordpress/data": "^11.0.0",
|
|
47
|
+
"@wordpress/i18n": "^7.0.0",
|
|
49
48
|
"ajv": "^8.20.0",
|
|
50
49
|
"ajv-draft-04": "^1.0.0",
|
|
51
50
|
"ajv-formats": "^3.0.1"
|
|
52
51
|
},
|
|
53
52
|
"devDependencies": {
|
|
54
|
-
"vitest": "^5.0.
|
|
53
|
+
"vitest": "^5.0.3"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"@types/react": "^18 || ^19",
|
|
57
|
+
"@types/react-dom": "^18 || ^19",
|
|
58
|
+
"react": "^18 || ^19",
|
|
59
|
+
"react-dom": "^18 || ^19"
|
|
60
|
+
},
|
|
61
|
+
"peerDependenciesMeta": {
|
|
62
|
+
"@types/react": {
|
|
63
|
+
"optional": true
|
|
64
|
+
},
|
|
65
|
+
"@types/react-dom": {
|
|
66
|
+
"optional": true
|
|
67
|
+
}
|
|
55
68
|
},
|
|
56
69
|
"publishConfig": {
|
|
57
70
|
"access": "public"
|
|
58
71
|
},
|
|
59
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "8d30f92cbbde3ddf781c8799443c649befbbcb88"
|
|
60
73
|
}
|
package/src/index.ts
CHANGED
package/src/tests/api.test.ts
CHANGED
|
@@ -394,9 +394,6 @@ describe( 'API functions', () => {
|
|
|
394
394
|
} );
|
|
395
395
|
|
|
396
396
|
it( 'should handle errors in client ability execution', async () => {
|
|
397
|
-
const consoleErrorSpy = vi
|
|
398
|
-
.spyOn( console, 'error' )
|
|
399
|
-
.mockImplementation( () => {} );
|
|
400
397
|
const executionError = new Error( 'Execution failed' );
|
|
401
398
|
const mockCallback = vi.fn().mockRejectedValue( executionError );
|
|
402
399
|
|
|
@@ -420,18 +417,13 @@ describe( 'API functions', () => {
|
|
|
420
417
|
executeAbility( 'test/client-ability', {} )
|
|
421
418
|
).rejects.toThrow( 'Execution failed' );
|
|
422
419
|
|
|
423
|
-
expect(
|
|
420
|
+
expect( console ).toHaveErroredWith(
|
|
424
421
|
'Error executing ability test/client-ability:',
|
|
425
422
|
executionError
|
|
426
423
|
);
|
|
427
|
-
|
|
428
|
-
consoleErrorSpy.mockRestore();
|
|
429
424
|
} );
|
|
430
425
|
|
|
431
426
|
it( 'should handle errors in server ability execution', async () => {
|
|
432
|
-
const consoleErrorSpy = vi
|
|
433
|
-
.spyOn( console, 'error' )
|
|
434
|
-
.mockImplementation( () => {} );
|
|
435
427
|
const serverError = new Error( 'Server execution failed' );
|
|
436
428
|
const mockServerCallback = vi.fn().mockRejectedValue( serverError );
|
|
437
429
|
|
|
@@ -455,12 +447,10 @@ describe( 'API functions', () => {
|
|
|
455
447
|
executeAbility( 'test/server-ability', {} )
|
|
456
448
|
).rejects.toThrow( 'Server execution failed' );
|
|
457
449
|
|
|
458
|
-
expect(
|
|
450
|
+
expect( console ).toHaveErroredWith(
|
|
459
451
|
'Error executing ability test/server-ability:',
|
|
460
452
|
serverError
|
|
461
453
|
);
|
|
462
|
-
|
|
463
|
-
consoleErrorSpy.mockRestore();
|
|
464
454
|
} );
|
|
465
455
|
|
|
466
456
|
it( 'should execute ability without callback as server ability', async () => {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Tests for schema validation utilities.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { describe, expect, it
|
|
5
|
+
import { describe, expect, it } from 'vitest';
|
|
6
6
|
import { validateValueFromSchema } from '../validation';
|
|
7
7
|
|
|
8
8
|
describe( 'validateValueFromSchema', () => {
|
|
@@ -135,37 +135,23 @@ describe( 'validateValueFromSchema', () => {
|
|
|
135
135
|
|
|
136
136
|
describe( 'edge cases', () => {
|
|
137
137
|
it( 'should pass validation when empty schema provided', () => {
|
|
138
|
-
const consoleSpy = vi
|
|
139
|
-
.spyOn( console, 'warn' )
|
|
140
|
-
.mockImplementation( () => {} );
|
|
141
|
-
|
|
142
138
|
expect( validateValueFromSchema( 'anything', {} ) ).toBe( true );
|
|
143
|
-
expect(
|
|
139
|
+
expect( console ).toHaveWarnedWith(
|
|
144
140
|
'The "type" schema keyword for value is required.'
|
|
145
141
|
);
|
|
146
|
-
|
|
147
|
-
consoleSpy.mockRestore();
|
|
148
142
|
} );
|
|
149
143
|
|
|
150
144
|
it( 'should warn when type is missing but still pass validation', () => {
|
|
151
|
-
const consoleSpy = vi
|
|
152
|
-
.spyOn( console, 'warn' )
|
|
153
|
-
.mockImplementation( () => {} );
|
|
154
145
|
const schema = { properties: { name: { type: 'string' } } };
|
|
155
146
|
const result = validateValueFromSchema( { name: 'test' }, schema );
|
|
156
147
|
|
|
157
148
|
expect( result ).toBe( true );
|
|
158
|
-
expect(
|
|
149
|
+
expect( console ).toHaveWarnedWith(
|
|
159
150
|
'The "type" schema keyword for value is required.'
|
|
160
151
|
);
|
|
161
|
-
|
|
162
|
-
consoleSpy.mockRestore();
|
|
163
152
|
} );
|
|
164
153
|
|
|
165
154
|
it( 'should include param name in warning when provided', () => {
|
|
166
|
-
const consoleSpy = vi
|
|
167
|
-
.spyOn( console, 'warn' )
|
|
168
|
-
.mockImplementation( () => {} );
|
|
169
155
|
const schema = { format: 'email' }; // Schema without type
|
|
170
156
|
const result = validateValueFromSchema(
|
|
171
157
|
'test@example.com',
|
|
@@ -174,11 +160,9 @@ describe( 'validateValueFromSchema', () => {
|
|
|
174
160
|
);
|
|
175
161
|
|
|
176
162
|
expect( result ).toBe( true );
|
|
177
|
-
expect(
|
|
163
|
+
expect( console ).toHaveWarnedWith(
|
|
178
164
|
'The "type" schema keyword for email_field is required.'
|
|
179
165
|
);
|
|
180
|
-
|
|
181
|
-
consoleSpy.mockRestore();
|
|
182
166
|
} );
|
|
183
167
|
|
|
184
168
|
it( 'should handle null values correctly', () => {
|
|
@@ -451,24 +435,14 @@ describe( 'validateValueFromSchema', () => {
|
|
|
451
435
|
|
|
452
436
|
describe( 'schema edge cases and errors', () => {
|
|
453
437
|
it( 'should handle empty schema object as valid but warn about missing type', () => {
|
|
454
|
-
const consoleSpy = vi
|
|
455
|
-
.spyOn( console, 'warn' )
|
|
456
|
-
.mockImplementation( () => {} );
|
|
457
|
-
|
|
458
438
|
// Empty object schema triggers warning about missing type
|
|
459
439
|
expect( validateValueFromSchema( 'anything', {} ) ).toBe( true );
|
|
460
|
-
expect(
|
|
440
|
+
expect( console ).toHaveWarnedWith(
|
|
461
441
|
'The "type" schema keyword for value is required.'
|
|
462
442
|
);
|
|
463
|
-
|
|
464
|
-
consoleSpy.mockRestore();
|
|
465
443
|
} );
|
|
466
444
|
|
|
467
445
|
it( 'should warn for invalid schema types but still pass validation', () => {
|
|
468
|
-
const consoleSpy = vi
|
|
469
|
-
.spyOn( console, 'warn' )
|
|
470
|
-
.mockImplementation( () => {} );
|
|
471
|
-
|
|
472
446
|
// Testing edge cases where schema is not a valid object
|
|
473
447
|
expect(
|
|
474
448
|
validateValueFromSchema(
|
|
@@ -476,51 +450,42 @@ describe( 'validateValueFromSchema', () => {
|
|
|
476
450
|
undefined as unknown as Record< string, any >
|
|
477
451
|
)
|
|
478
452
|
).toBe( true );
|
|
479
|
-
expect(
|
|
453
|
+
expect( console ).toHaveWarnedWith(
|
|
480
454
|
'Schema must be an object. Received undefined.'
|
|
481
455
|
);
|
|
482
456
|
|
|
483
|
-
consoleSpy.mockClear();
|
|
484
457
|
expect(
|
|
485
458
|
validateValueFromSchema(
|
|
486
459
|
123,
|
|
487
460
|
null as unknown as Record< string, any >
|
|
488
461
|
)
|
|
489
462
|
).toBe( true );
|
|
490
|
-
expect(
|
|
463
|
+
expect( console ).toHaveWarnedWith(
|
|
491
464
|
'Schema must be an object. Received object.' // typeof null === 'object'
|
|
492
465
|
);
|
|
493
466
|
|
|
494
|
-
consoleSpy.mockClear();
|
|
495
467
|
expect(
|
|
496
468
|
validateValueFromSchema(
|
|
497
469
|
true,
|
|
498
470
|
false as unknown as Record< string, any >
|
|
499
471
|
)
|
|
500
472
|
).toBe( true );
|
|
501
|
-
expect(
|
|
473
|
+
expect( console ).toHaveWarnedWith(
|
|
502
474
|
'Schema must be an object. Received boolean.'
|
|
503
475
|
);
|
|
504
|
-
|
|
505
|
-
consoleSpy.mockRestore();
|
|
506
476
|
} );
|
|
507
477
|
|
|
508
478
|
it( 'should handle schema compilation errors', () => {
|
|
509
479
|
// Pass an invalid schema that will cause compilation error
|
|
510
480
|
const invalidSchema = { type: 'invalid-type' };
|
|
511
|
-
const consoleErrorSpy = vi
|
|
512
|
-
.spyOn( console, 'error' )
|
|
513
|
-
.mockImplementation( () => {} );
|
|
514
481
|
|
|
515
482
|
const result = validateValueFromSchema( 'test', invalidSchema );
|
|
516
483
|
|
|
517
484
|
expect( result ).toBe( 'Invalid schema provided for validation.' );
|
|
518
|
-
expect(
|
|
485
|
+
expect( console ).toHaveErroredWith(
|
|
519
486
|
'Schema compilation error:',
|
|
520
487
|
expect.any( Error )
|
|
521
488
|
);
|
|
522
|
-
|
|
523
|
-
consoleErrorSpy.mockRestore();
|
|
524
489
|
} );
|
|
525
490
|
|
|
526
491
|
it( 'should handle const validation keyword', () => {
|
|
@@ -568,19 +533,14 @@ describe( 'validateValueFromSchema', () => {
|
|
|
568
533
|
},
|
|
569
534
|
},
|
|
570
535
|
};
|
|
571
|
-
const consoleErrorSpy = vi
|
|
572
|
-
.spyOn( console, 'error' )
|
|
573
|
-
.mockImplementation( () => {} );
|
|
574
536
|
|
|
575
537
|
expect(
|
|
576
538
|
validateValueFromSchema( { name: 'hello' }, schema )
|
|
577
539
|
).toBe( 'Invalid schema provided for validation.' );
|
|
578
|
-
expect(
|
|
540
|
+
expect( console ).toHaveErroredWith(
|
|
579
541
|
'Schema compilation error:',
|
|
580
542
|
expect.any( Error )
|
|
581
543
|
);
|
|
582
|
-
|
|
583
|
-
consoleErrorSpy.mockRestore();
|
|
584
544
|
}
|
|
585
545
|
);
|
|
586
546
|
|
|
@@ -589,19 +549,14 @@ describe( 'validateValueFromSchema', () => {
|
|
|
589
549
|
type: 'string',
|
|
590
550
|
sanitize_callback: 'sanitize_text_field',
|
|
591
551
|
};
|
|
592
|
-
const consoleErrorSpy = vi
|
|
593
|
-
.spyOn( console, 'error' )
|
|
594
|
-
.mockImplementation( () => {} );
|
|
595
552
|
|
|
596
553
|
expect( validateValueFromSchema( 'hello', schema ) ).toBe(
|
|
597
554
|
'Invalid schema provided for validation.'
|
|
598
555
|
);
|
|
599
|
-
expect(
|
|
556
|
+
expect( console ).toHaveErroredWith(
|
|
600
557
|
'Schema compilation error:',
|
|
601
558
|
expect.any( Error )
|
|
602
559
|
);
|
|
603
|
-
|
|
604
|
-
consoleErrorSpy.mockRestore();
|
|
605
560
|
} );
|
|
606
561
|
} );
|
|
607
562
|
} );
|
package/CHANGELOG.md
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
<!-- Learn how to maintain this file at https://github.com/WordPress/gutenberg/tree/HEAD/packages#maintaining-changelogs. -->
|
|
2
|
-
|
|
3
|
-
## Unreleased
|
|
4
|
-
|
|
5
|
-
## 0.22.0 (2026-09-23)
|
|
6
|
-
|
|
7
|
-
## 0.21.0 (2026-09-10)
|
|
8
|
-
|
|
9
|
-
### Internal
|
|
10
|
-
|
|
11
|
-
- Remove tsconfig project references to packages that are not dependencies ([#82106](https://github.com/WordPress/gutenberg/pull/82106)).
|
|
12
|
-
|
|
13
|
-
## 0.20.0 (2026-08-26)
|
|
14
|
-
|
|
15
|
-
### Internal
|
|
16
|
-
|
|
17
|
-
- Split tsconfig into a build project and a default dev project so dev files are type checked without publishing their declarations. ([#81517](https://github.com/WordPress/gutenberg/pull/81517))
|
|
18
|
-
|
|
19
|
-
## 0.19.0 (2026-08-12)
|
|
20
|
-
|
|
21
|
-
## 0.18.0 (2026-07-29)
|
|
22
|
-
|
|
23
|
-
## 0.17.0 (2026-07-14)
|
|
24
|
-
|
|
25
|
-
## 0.16.0 (2026-07-01)
|
|
26
|
-
|
|
27
|
-
## 0.15.0 (2026-06-24)
|
|
28
|
-
|
|
29
|
-
## 0.14.1 (2026-06-16)
|
|
30
|
-
|
|
31
|
-
## 0.14.0 (2026-06-10)
|
|
32
|
-
|
|
33
|
-
## 0.13.0 (2026-05-27)
|
|
34
|
-
|
|
35
|
-
## 0.12.0 (2026-05-14)
|
|
36
|
-
|
|
37
|
-
## 0.11.0 (2026-04-29)
|
|
38
|
-
|
|
39
|
-
## 0.10.0 (2026-04-15)
|
|
40
|
-
|
|
41
|
-
## 0.9.0 (2026-04-01)
|
|
42
|
-
|
|
43
|
-
## 0.8.0 (2026-03-18)
|
|
44
|
-
|
|
45
|
-
## 0.7.0 (2026-03-04)
|
|
46
|
-
|
|
47
|
-
## 0.6.0 (2026-02-18)
|
|
48
|
-
|
|
49
|
-
## 0.5.0 (2026-01-29)
|
|
50
|
-
|
|
51
|
-
## 0.4.0 (2026-01-16)
|
|
52
|
-
|
|
53
|
-
## 0.2.0 (2025-11-26)
|
|
54
|
-
|
|
55
|
-
## 0.1.0 (Unreleased)
|
|
56
|
-
|
|
57
|
-
### New Features
|
|
58
|
-
|
|
59
|
-
- Initial release of the WordPress Abilities API client library.
|