convex-cms 0.0.1
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/dist/cli/commands/admin.d.ts +16 -0
- package/dist/cli/commands/admin.d.ts.map +1 -0
- package/dist/cli/commands/admin.js +88 -0
- package/dist/cli/commands/admin.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +18 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/utils/detectConvexUrl.d.ts +13 -0
- package/dist/cli/utils/detectConvexUrl.d.ts.map +1 -0
- package/dist/cli/utils/detectConvexUrl.js +48 -0
- package/dist/cli/utils/detectConvexUrl.js.map +1 -0
- package/dist/cli/utils/openBrowser.d.ts +7 -0
- package/dist/cli/utils/openBrowser.d.ts.map +1 -0
- package/dist/cli/utils/openBrowser.js +17 -0
- package/dist/cli/utils/openBrowser.js.map +1 -0
- package/dist/client/admin-config.d.ts +126 -0
- package/dist/client/admin-config.d.ts.map +1 -0
- package/dist/client/admin-config.js +117 -0
- package/dist/client/admin-config.js.map +1 -0
- package/dist/client/adminApi.d.ts +2273 -0
- package/dist/client/adminApi.d.ts.map +1 -0
- package/dist/client/adminApi.js +716 -0
- package/dist/client/adminApi.js.map +1 -0
- package/dist/client/agentTools.d.ts +933 -0
- package/dist/client/agentTools.d.ts.map +1 -0
- package/dist/client/agentTools.js +1004 -0
- package/dist/client/agentTools.js.map +1 -0
- package/dist/client/argTypes.d.ts +212 -0
- package/dist/client/argTypes.d.ts.map +1 -0
- package/dist/client/argTypes.js +5 -0
- package/dist/client/argTypes.js.map +1 -0
- package/dist/client/field-types.d.ts +55 -0
- package/dist/client/field-types.d.ts.map +1 -0
- package/dist/client/field-types.js +152 -0
- package/dist/client/field-types.js.map +1 -0
- package/dist/client/index.d.ts +189 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +668 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/queryBuilder.d.ts +765 -0
- package/dist/client/queryBuilder.d.ts.map +1 -0
- package/dist/client/queryBuilder.js +970 -0
- package/dist/client/queryBuilder.js.map +1 -0
- package/dist/client/schema/codegen.d.ts +128 -0
- package/dist/client/schema/codegen.d.ts.map +1 -0
- package/dist/client/schema/codegen.js +318 -0
- package/dist/client/schema/codegen.js.map +1 -0
- package/dist/client/schema/defineContentType.d.ts +221 -0
- package/dist/client/schema/defineContentType.d.ts.map +1 -0
- package/dist/client/schema/defineContentType.js +380 -0
- package/dist/client/schema/defineContentType.js.map +1 -0
- package/dist/client/schema/index.d.ts +85 -0
- package/dist/client/schema/index.d.ts.map +1 -0
- package/dist/client/schema/index.js +92 -0
- package/dist/client/schema/index.js.map +1 -0
- package/dist/client/schema/schemaDrift.d.ts +199 -0
- package/dist/client/schema/schemaDrift.d.ts.map +1 -0
- package/dist/client/schema/schemaDrift.js +340 -0
- package/dist/client/schema/schemaDrift.js.map +1 -0
- package/dist/client/schema/typedClient.d.ts +401 -0
- package/dist/client/schema/typedClient.d.ts.map +1 -0
- package/dist/client/schema/typedClient.js +269 -0
- package/dist/client/schema/typedClient.js.map +1 -0
- package/dist/client/schema/types.d.ts +477 -0
- package/dist/client/schema/types.d.ts.map +1 -0
- package/dist/client/schema/types.js +39 -0
- package/dist/client/schema/types.js.map +1 -0
- package/dist/client/types.d.ts +449 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +149 -0
- package/dist/client/types.js.map +1 -0
- package/dist/client/workflows.d.ts +51 -0
- package/dist/client/workflows.d.ts.map +1 -0
- package/dist/client/workflows.js +103 -0
- package/dist/client/workflows.js.map +1 -0
- package/dist/client/wrapper.d.ts +2198 -0
- package/dist/client/wrapper.d.ts.map +1 -0
- package/dist/client/wrapper.js +2651 -0
- package/dist/client/wrapper.js.map +1 -0
- package/dist/component/_generated/api.d.ts +124 -0
- package/dist/component/_generated/api.d.ts.map +1 -0
- package/dist/component/_generated/api.js +31 -0
- package/dist/component/_generated/api.js.map +1 -0
- package/dist/component/_generated/component.d.ts +4321 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +11 -0
- package/dist/component/_generated/component.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +46 -0
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +11 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +121 -0
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/dist/component/_generated/server.js +78 -0
- package/dist/component/_generated/server.js.map +1 -0
- package/dist/component/auditLog.d.ts +410 -0
- package/dist/component/auditLog.d.ts.map +1 -0
- package/dist/component/auditLog.js +607 -0
- package/dist/component/auditLog.js.map +1 -0
- package/dist/component/authorization.d.ts +323 -0
- package/dist/component/authorization.d.ts.map +1 -0
- package/dist/component/authorization.js +464 -0
- package/dist/component/authorization.js.map +1 -0
- package/dist/component/authorizationHooks.d.ts +184 -0
- package/dist/component/authorizationHooks.d.ts.map +1 -0
- package/dist/component/authorizationHooks.js +521 -0
- package/dist/component/authorizationHooks.js.map +1 -0
- package/dist/component/bulkOperations.d.ts +200 -0
- package/dist/component/bulkOperations.d.ts.map +1 -0
- package/dist/component/bulkOperations.js +568 -0
- package/dist/component/bulkOperations.js.map +1 -0
- package/dist/component/contentEntries.d.ts +719 -0
- package/dist/component/contentEntries.d.ts.map +1 -0
- package/dist/component/contentEntries.js +1617 -0
- package/dist/component/contentEntries.js.map +1 -0
- package/dist/component/contentEntryMutations.d.ts +505 -0
- package/dist/component/contentEntryMutations.d.ts.map +1 -0
- package/dist/component/contentEntryMutations.js +1009 -0
- package/dist/component/contentEntryMutations.js.map +1 -0
- package/dist/component/contentEntryValidation.d.ts +115 -0
- package/dist/component/contentEntryValidation.d.ts.map +1 -0
- package/dist/component/contentEntryValidation.js +546 -0
- package/dist/component/contentEntryValidation.js.map +1 -0
- package/dist/component/contentLock.d.ts +328 -0
- package/dist/component/contentLock.d.ts.map +1 -0
- package/dist/component/contentLock.js +471 -0
- package/dist/component/contentLock.js.map +1 -0
- package/dist/component/contentTypeMigration.d.ts +411 -0
- package/dist/component/contentTypeMigration.d.ts.map +1 -0
- package/dist/component/contentTypeMigration.js +805 -0
- package/dist/component/contentTypeMigration.js.map +1 -0
- package/dist/component/contentTypeMutations.d.ts +975 -0
- package/dist/component/contentTypeMutations.d.ts.map +1 -0
- package/dist/component/contentTypeMutations.js +768 -0
- package/dist/component/contentTypeMutations.js.map +1 -0
- package/dist/component/contentTypes.d.ts +538 -0
- package/dist/component/contentTypes.d.ts.map +1 -0
- package/dist/component/contentTypes.js +304 -0
- package/dist/component/contentTypes.js.map +1 -0
- package/dist/component/convex.config.d.ts +42 -0
- package/dist/component/convex.config.d.ts.map +1 -0
- package/dist/component/convex.config.js +43 -0
- package/dist/component/convex.config.js.map +1 -0
- package/dist/component/documentTypes.d.ts +186 -0
- package/dist/component/documentTypes.d.ts.map +1 -0
- package/dist/component/documentTypes.js +23 -0
- package/dist/component/documentTypes.js.map +1 -0
- package/dist/component/eventEmitter.d.ts +281 -0
- package/dist/component/eventEmitter.d.ts.map +1 -0
- package/dist/component/eventEmitter.js +300 -0
- package/dist/component/eventEmitter.js.map +1 -0
- package/dist/component/exportImport.d.ts +1120 -0
- package/dist/component/exportImport.d.ts.map +1 -0
- package/dist/component/exportImport.js +931 -0
- package/dist/component/exportImport.js.map +1 -0
- package/dist/component/index.d.ts +28 -0
- package/dist/component/index.d.ts.map +1 -0
- package/dist/component/index.js +142 -0
- package/dist/component/index.js.map +1 -0
- package/dist/component/lib/deepReferenceResolver.d.ts +252 -0
- package/dist/component/lib/deepReferenceResolver.d.ts.map +1 -0
- package/dist/component/lib/deepReferenceResolver.js +601 -0
- package/dist/component/lib/deepReferenceResolver.js.map +1 -0
- package/dist/component/lib/errors.d.ts +306 -0
- package/dist/component/lib/errors.d.ts.map +1 -0
- package/dist/component/lib/errors.js +407 -0
- package/dist/component/lib/errors.js.map +1 -0
- package/dist/component/lib/index.d.ts +10 -0
- package/dist/component/lib/index.d.ts.map +1 -0
- package/dist/component/lib/index.js +33 -0
- package/dist/component/lib/index.js.map +1 -0
- package/dist/component/lib/mediaReferenceResolver.d.ts +217 -0
- package/dist/component/lib/mediaReferenceResolver.d.ts.map +1 -0
- package/dist/component/lib/mediaReferenceResolver.js +326 -0
- package/dist/component/lib/mediaReferenceResolver.js.map +1 -0
- package/dist/component/lib/metadataExtractor.d.ts +245 -0
- package/dist/component/lib/metadataExtractor.d.ts.map +1 -0
- package/dist/component/lib/metadataExtractor.js +548 -0
- package/dist/component/lib/metadataExtractor.js.map +1 -0
- package/dist/component/lib/mutationAuth.d.ts +95 -0
- package/dist/component/lib/mutationAuth.d.ts.map +1 -0
- package/dist/component/lib/mutationAuth.js +146 -0
- package/dist/component/lib/mutationAuth.js.map +1 -0
- package/dist/component/lib/queries.d.ts +17 -0
- package/dist/component/lib/queries.d.ts.map +1 -0
- package/dist/component/lib/queries.js +49 -0
- package/dist/component/lib/queries.js.map +1 -0
- package/dist/component/lib/ragContentChunker.d.ts +423 -0
- package/dist/component/lib/ragContentChunker.d.ts.map +1 -0
- package/dist/component/lib/ragContentChunker.js +897 -0
- package/dist/component/lib/ragContentChunker.js.map +1 -0
- package/dist/component/lib/referenceResolver.d.ts +175 -0
- package/dist/component/lib/referenceResolver.d.ts.map +1 -0
- package/dist/component/lib/referenceResolver.js +293 -0
- package/dist/component/lib/referenceResolver.js.map +1 -0
- package/dist/component/lib/slugGenerator.d.ts +71 -0
- package/dist/component/lib/slugGenerator.d.ts.map +1 -0
- package/dist/component/lib/slugGenerator.js +207 -0
- package/dist/component/lib/slugGenerator.js.map +1 -0
- package/dist/component/lib/slugUniqueness.d.ts +131 -0
- package/dist/component/lib/slugUniqueness.d.ts.map +1 -0
- package/dist/component/lib/slugUniqueness.js +229 -0
- package/dist/component/lib/slugUniqueness.js.map +1 -0
- package/dist/component/lib/softDelete.d.ts +18 -0
- package/dist/component/lib/softDelete.d.ts.map +1 -0
- package/dist/component/lib/softDelete.js +29 -0
- package/dist/component/lib/softDelete.js.map +1 -0
- package/dist/component/localeFallbackChain.d.ts +410 -0
- package/dist/component/localeFallbackChain.d.ts.map +1 -0
- package/dist/component/localeFallbackChain.js +467 -0
- package/dist/component/localeFallbackChain.js.map +1 -0
- package/dist/component/localeFields.d.ts +508 -0
- package/dist/component/localeFields.d.ts.map +1 -0
- package/dist/component/localeFields.js +592 -0
- package/dist/component/localeFields.js.map +1 -0
- package/dist/component/mediaAssetMutations.d.ts +235 -0
- package/dist/component/mediaAssetMutations.d.ts.map +1 -0
- package/dist/component/mediaAssetMutations.js +558 -0
- package/dist/component/mediaAssetMutations.js.map +1 -0
- package/dist/component/mediaAssets.d.ts +168 -0
- package/dist/component/mediaAssets.d.ts.map +1 -0
- package/dist/component/mediaAssets.js +618 -0
- package/dist/component/mediaAssets.js.map +1 -0
- package/dist/component/mediaFolderMutations.d.ts +642 -0
- package/dist/component/mediaFolderMutations.d.ts.map +1 -0
- package/dist/component/mediaFolderMutations.js +849 -0
- package/dist/component/mediaFolderMutations.js.map +1 -0
- package/dist/component/mediaUploadMutations.d.ts +136 -0
- package/dist/component/mediaUploadMutations.d.ts.map +1 -0
- package/dist/component/mediaUploadMutations.js +205 -0
- package/dist/component/mediaUploadMutations.js.map +1 -0
- package/dist/component/mediaVariantMutations.d.ts +468 -0
- package/dist/component/mediaVariantMutations.d.ts.map +1 -0
- package/dist/component/mediaVariantMutations.js +737 -0
- package/dist/component/mediaVariantMutations.js.map +1 -0
- package/dist/component/mediaVariants.d.ts +525 -0
- package/dist/component/mediaVariants.d.ts.map +1 -0
- package/dist/component/mediaVariants.js +661 -0
- package/dist/component/mediaVariants.js.map +1 -0
- package/dist/component/ragContentIndexer.d.ts +595 -0
- package/dist/component/ragContentIndexer.d.ts.map +1 -0
- package/dist/component/ragContentIndexer.js +794 -0
- package/dist/component/ragContentIndexer.js.map +1 -0
- package/dist/component/rateLimitHooks.d.ts +266 -0
- package/dist/component/rateLimitHooks.d.ts.map +1 -0
- package/dist/component/rateLimitHooks.js +412 -0
- package/dist/component/rateLimitHooks.js.map +1 -0
- package/dist/component/roles.d.ts +649 -0
- package/dist/component/roles.d.ts.map +1 -0
- package/dist/component/roles.js +884 -0
- package/dist/component/roles.js.map +1 -0
- package/dist/component/scheduledPublish.d.ts +182 -0
- package/dist/component/scheduledPublish.d.ts.map +1 -0
- package/dist/component/scheduledPublish.js +304 -0
- package/dist/component/scheduledPublish.js.map +1 -0
- package/dist/component/schema.d.ts +4114 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +469 -0
- package/dist/component/schema.js.map +1 -0
- package/dist/component/taxonomies.d.ts +476 -0
- package/dist/component/taxonomies.d.ts.map +1 -0
- package/dist/component/taxonomies.js +785 -0
- package/dist/component/taxonomies.js.map +1 -0
- package/dist/component/taxonomyMutations.d.ts +206 -0
- package/dist/component/taxonomyMutations.d.ts.map +1 -0
- package/dist/component/taxonomyMutations.js +1001 -0
- package/dist/component/taxonomyMutations.js.map +1 -0
- package/dist/component/trash.d.ts +265 -0
- package/dist/component/trash.d.ts.map +1 -0
- package/dist/component/trash.js +621 -0
- package/dist/component/trash.js.map +1 -0
- package/dist/component/types.d.ts +4 -0
- package/dist/component/types.d.ts.map +1 -0
- package/dist/component/types.js +2 -0
- package/dist/component/types.js.map +1 -0
- package/dist/component/userContext.d.ts +508 -0
- package/dist/component/userContext.d.ts.map +1 -0
- package/dist/component/userContext.js +615 -0
- package/dist/component/userContext.js.map +1 -0
- package/dist/component/validation.d.ts +387 -0
- package/dist/component/validation.d.ts.map +1 -0
- package/dist/component/validation.js +1052 -0
- package/dist/component/validation.js.map +1 -0
- package/dist/component/validators.d.ts +4645 -0
- package/dist/component/validators.d.ts.map +1 -0
- package/dist/component/validators.js +641 -0
- package/dist/component/validators.js.map +1 -0
- package/dist/component/versionMutations.d.ts +216 -0
- package/dist/component/versionMutations.d.ts.map +1 -0
- package/dist/component/versionMutations.js +321 -0
- package/dist/component/versionMutations.js.map +1 -0
- package/dist/component/webhookTrigger.d.ts +770 -0
- package/dist/component/webhookTrigger.d.ts.map +1 -0
- package/dist/component/webhookTrigger.js +1413 -0
- package/dist/component/webhookTrigger.js.map +1 -0
- package/dist/react/index.d.ts +316 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +558 -0
- package/dist/react/index.js.map +1 -0
- package/dist/test.d.ts +2230 -0
- package/dist/test.d.ts.map +1 -0
- package/dist/test.js +1107 -0
- package/dist/test.js.map +1 -0
- package/package.json +95 -0
- package/src/cli/commands/admin.ts +104 -0
- package/src/cli/index.ts +21 -0
- package/src/cli/utils/detectConvexUrl.ts +54 -0
- package/src/cli/utils/openBrowser.ts +16 -0
- package/src/client/admin-config.ts +138 -0
- package/src/client/adminApi.ts +942 -0
- package/src/client/agentTools.ts +1311 -0
- package/src/client/argTypes.ts +316 -0
- package/src/client/field-types.ts +187 -0
- package/src/client/index.ts +1301 -0
- package/src/client/queryBuilder.ts +1100 -0
- package/src/client/schema/codegen.ts +500 -0
- package/src/client/schema/defineContentType.ts +501 -0
- package/src/client/schema/index.ts +169 -0
- package/src/client/schema/schemaDrift.ts +574 -0
- package/src/client/schema/typedClient.ts +688 -0
- package/src/client/schema/types.ts +666 -0
- package/src/client/types.ts +723 -0
- package/src/client/workflows.ts +141 -0
- package/src/client/wrapper.ts +4304 -0
- package/src/component/_generated/api.ts +140 -0
- package/src/component/_generated/component.ts +5029 -0
- package/src/component/_generated/dataModel.ts +60 -0
- package/src/component/_generated/server.ts +156 -0
- package/src/component/authorization.ts +647 -0
- package/src/component/authorizationHooks.ts +668 -0
- package/src/component/bulkOperations.ts +687 -0
- package/src/component/contentEntries.ts +1976 -0
- package/src/component/contentEntryMutations.ts +1223 -0
- package/src/component/contentEntryValidation.ts +707 -0
- package/src/component/contentLock.ts +550 -0
- package/src/component/contentTypeMigration.ts +1064 -0
- package/src/component/contentTypeMutations.ts +969 -0
- package/src/component/contentTypes.ts +346 -0
- package/src/component/convex.config.ts +44 -0
- package/src/component/documentTypes.ts +240 -0
- package/src/component/eventEmitter.ts +485 -0
- package/src/component/exportImport.ts +1169 -0
- package/src/component/index.ts +491 -0
- package/src/component/lib/deepReferenceResolver.ts +999 -0
- package/src/component/lib/errors.ts +816 -0
- package/src/component/lib/index.ts +145 -0
- package/src/component/lib/mediaReferenceResolver.ts +495 -0
- package/src/component/lib/metadataExtractor.ts +792 -0
- package/src/component/lib/mutationAuth.ts +199 -0
- package/src/component/lib/queries.ts +79 -0
- package/src/component/lib/ragContentChunker.ts +1371 -0
- package/src/component/lib/referenceResolver.ts +430 -0
- package/src/component/lib/slugGenerator.ts +262 -0
- package/src/component/lib/slugUniqueness.ts +333 -0
- package/src/component/lib/softDelete.ts +44 -0
- package/src/component/localeFallbackChain.ts +673 -0
- package/src/component/localeFields.ts +896 -0
- package/src/component/mediaAssetMutations.ts +725 -0
- package/src/component/mediaAssets.ts +932 -0
- package/src/component/mediaFolderMutations.ts +1046 -0
- package/src/component/mediaUploadMutations.ts +224 -0
- package/src/component/mediaVariantMutations.ts +900 -0
- package/src/component/mediaVariants.ts +793 -0
- package/src/component/ragContentIndexer.ts +1067 -0
- package/src/component/rateLimitHooks.ts +572 -0
- package/src/component/roles.ts +1360 -0
- package/src/component/scheduledPublish.ts +358 -0
- package/src/component/schema.ts +617 -0
- package/src/component/taxonomies.ts +949 -0
- package/src/component/taxonomyMutations.ts +1210 -0
- package/src/component/trash.ts +724 -0
- package/src/component/userContext.ts +898 -0
- package/src/component/validation.ts +1388 -0
- package/src/component/validators.ts +949 -0
- package/src/component/versionMutations.ts +392 -0
- package/src/component/webhookTrigger.ts +1922 -0
- package/src/react/index.ts +898 -0
- package/src/test.ts +1580 -0
|
@@ -0,0 +1,649 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RBAC Default Roles Configuration
|
|
3
|
+
*
|
|
4
|
+
* This module defines the default role configurations for the CMS:
|
|
5
|
+
* - admin: Full access to all CMS features
|
|
6
|
+
* - editor: Can manage all content and media, but not settings
|
|
7
|
+
* - author: Can create and manage own content
|
|
8
|
+
* - viewer: Read-only access to published content
|
|
9
|
+
*
|
|
10
|
+
* Roles are exported as constants for easy customization. Developers can
|
|
11
|
+
* extend or override these defaults using the custom roles feature.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { DEFAULT_ROLES, hasPermission, type RoleName } from '@convex-cms/core';
|
|
16
|
+
*
|
|
17
|
+
* // Check if a role has a specific permission
|
|
18
|
+
* if (hasPermission('editor', { resource: 'contentEntries', action: 'update' })) {
|
|
19
|
+
* // Allow the action
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* // Get all permissions for a role
|
|
23
|
+
* const adminPerms = getRolePermissions('admin');
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* All built-in role names in the CMS.
|
|
28
|
+
* Custom roles can be added by developers, but these are always available.
|
|
29
|
+
*/
|
|
30
|
+
export declare const roleNames: readonly ["admin", "editor", "author", "viewer"];
|
|
31
|
+
/**
|
|
32
|
+
* Type representing a built-in role name.
|
|
33
|
+
* Use `string` for custom roles, or extend this type.
|
|
34
|
+
*/
|
|
35
|
+
export type RoleName = typeof roleNames[number];
|
|
36
|
+
/**
|
|
37
|
+
* Convex validator for role names.
|
|
38
|
+
* Use this in function arguments to validate role input.
|
|
39
|
+
*/
|
|
40
|
+
export declare const roleNameValidator: import("convex/values").VUnion<"author" | "admin" | "editor" | "viewer", [import("convex/values").VLiteral<"admin", "required">, import("convex/values").VLiteral<"editor", "required">, import("convex/values").VLiteral<"author", "required">, import("convex/values").VLiteral<"viewer", "required">], "required", never>;
|
|
41
|
+
/**
|
|
42
|
+
* All resources that can be protected by RBAC.
|
|
43
|
+
*/
|
|
44
|
+
export declare const resources: readonly ["contentTypes", "contentEntries", "mediaItems", "settings"];
|
|
45
|
+
export type Resource = typeof resources[number];
|
|
46
|
+
/**
|
|
47
|
+
* Convex validator for resources.
|
|
48
|
+
*/
|
|
49
|
+
export declare const resourceValidator: import("convex/values").VUnion<"contentTypes" | "contentEntries" | "mediaItems" | "settings", [import("convex/values").VLiteral<"contentTypes", "required">, import("convex/values").VLiteral<"contentEntries", "required">, import("convex/values").VLiteral<"mediaItems", "required">, import("convex/values").VLiteral<"settings", "required">], "required", never>;
|
|
50
|
+
/**
|
|
51
|
+
* All actions that can be performed on resources.
|
|
52
|
+
*/
|
|
53
|
+
export declare const actions: readonly ["create", "read", "update", "delete", "publish", "unpublish", "restore", "manage", "move"];
|
|
54
|
+
export type Action = typeof actions[number];
|
|
55
|
+
/**
|
|
56
|
+
* Convex validator for actions.
|
|
57
|
+
*/
|
|
58
|
+
export declare const actionValidator: import("convex/values").VUnion<"update" | "read" | "publish" | "create" | "delete" | "unpublish" | "restore" | "manage" | "move", [import("convex/values").VLiteral<"create", "required">, import("convex/values").VLiteral<"read", "required">, import("convex/values").VLiteral<"update", "required">, import("convex/values").VLiteral<"delete", "required">, import("convex/values").VLiteral<"publish", "required">, import("convex/values").VLiteral<"unpublish", "required">, import("convex/values").VLiteral<"restore", "required">, import("convex/values").VLiteral<"manage", "required">, import("convex/values").VLiteral<"move", "required">], "required", never>;
|
|
59
|
+
/**
|
|
60
|
+
* Ownership scope for permissions.
|
|
61
|
+
* - "all": Can perform action on any item
|
|
62
|
+
* - "own": Can only perform action on items they created
|
|
63
|
+
*/
|
|
64
|
+
export type OwnershipScope = "all" | "own";
|
|
65
|
+
/**
|
|
66
|
+
* A single permission grant.
|
|
67
|
+
* Defines what action can be performed on which resource, with optional ownership scope.
|
|
68
|
+
*/
|
|
69
|
+
export interface Permission {
|
|
70
|
+
/** The resource this permission applies to */
|
|
71
|
+
resource: Resource;
|
|
72
|
+
/** The action being granted */
|
|
73
|
+
action: Action;
|
|
74
|
+
/**
|
|
75
|
+
* Ownership scope (defaults to "all" if not specified).
|
|
76
|
+
* Only relevant for resources that have ownership (contentEntries, mediaAssets).
|
|
77
|
+
*/
|
|
78
|
+
scope?: OwnershipScope;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Convex validator for a permission object.
|
|
82
|
+
*/
|
|
83
|
+
export declare const permissionValidator: import("convex/values").VObject<{
|
|
84
|
+
scope?: "all" | "own" | undefined;
|
|
85
|
+
action: "update" | "read" | "publish" | "create" | "delete" | "unpublish" | "restore" | "manage" | "move";
|
|
86
|
+
resource: "contentTypes" | "contentEntries" | "mediaItems" | "settings";
|
|
87
|
+
}, {
|
|
88
|
+
resource: import("convex/values").VUnion<"contentTypes" | "contentEntries" | "mediaItems" | "settings", [import("convex/values").VLiteral<"contentTypes", "required">, import("convex/values").VLiteral<"contentEntries", "required">, import("convex/values").VLiteral<"mediaItems", "required">, import("convex/values").VLiteral<"settings", "required">], "required", never>;
|
|
89
|
+
action: import("convex/values").VUnion<"update" | "read" | "publish" | "create" | "delete" | "unpublish" | "restore" | "manage" | "move", [import("convex/values").VLiteral<"create", "required">, import("convex/values").VLiteral<"read", "required">, import("convex/values").VLiteral<"update", "required">, import("convex/values").VLiteral<"delete", "required">, import("convex/values").VLiteral<"publish", "required">, import("convex/values").VLiteral<"unpublish", "required">, import("convex/values").VLiteral<"restore", "required">, import("convex/values").VLiteral<"manage", "required">, import("convex/values").VLiteral<"move", "required">], "required", never>;
|
|
90
|
+
scope: import("convex/values").VUnion<"all" | "own" | undefined, [import("convex/values").VLiteral<"all", "required">, import("convex/values").VLiteral<"own", "required">], "optional", never>;
|
|
91
|
+
}, "required", "action" | "resource" | "scope">;
|
|
92
|
+
/**
|
|
93
|
+
* Complete role definition including metadata and permissions.
|
|
94
|
+
*/
|
|
95
|
+
export interface RoleDefinition {
|
|
96
|
+
/** Unique role identifier */
|
|
97
|
+
name: RoleName | string;
|
|
98
|
+
/** Human-readable display name */
|
|
99
|
+
displayName: string;
|
|
100
|
+
/** Description of the role's purpose */
|
|
101
|
+
description: string;
|
|
102
|
+
/** List of permissions granted to this role */
|
|
103
|
+
permissions: Permission[];
|
|
104
|
+
/** Whether this is a system role that cannot be deleted */
|
|
105
|
+
isSystem: boolean;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Admin role - Full access to all CMS features.
|
|
109
|
+
*
|
|
110
|
+
* Admins can:
|
|
111
|
+
* - Create, read, update, and delete all content types
|
|
112
|
+
* - Manage all content entries regardless of author
|
|
113
|
+
* - Publish and unpublish any content
|
|
114
|
+
* - Manage all media assets and folders
|
|
115
|
+
* - Access and modify CMS settings
|
|
116
|
+
*/
|
|
117
|
+
export declare const ADMIN_ROLE: RoleDefinition;
|
|
118
|
+
/**
|
|
119
|
+
* Editor role - Can manage all content and media, but not settings or content types.
|
|
120
|
+
*
|
|
121
|
+
* Editors can:
|
|
122
|
+
* - Read content type definitions
|
|
123
|
+
* - Create, read, update, and delete all content entries
|
|
124
|
+
* - Publish and unpublish any content
|
|
125
|
+
* - Manage all media assets and folders
|
|
126
|
+
* - Cannot modify CMS settings or content type schemas
|
|
127
|
+
*/
|
|
128
|
+
export declare const EDITOR_ROLE: RoleDefinition;
|
|
129
|
+
/**
|
|
130
|
+
* Author role - Can create and manage own content.
|
|
131
|
+
*
|
|
132
|
+
* Authors can:
|
|
133
|
+
* - Read content type definitions
|
|
134
|
+
* - Create content entries
|
|
135
|
+
* - Read, update, and delete their own content entries
|
|
136
|
+
* - Publish and unpublish their own content (subject to workflow settings)
|
|
137
|
+
* - Upload and manage their own media assets
|
|
138
|
+
* - Read all media (for embedding in content)
|
|
139
|
+
* - Cannot manage other users' content or CMS settings
|
|
140
|
+
*/
|
|
141
|
+
export declare const AUTHOR_ROLE: RoleDefinition;
|
|
142
|
+
/**
|
|
143
|
+
* Viewer role - Read-only access to published content.
|
|
144
|
+
*
|
|
145
|
+
* Viewers can:
|
|
146
|
+
* - Read content type definitions
|
|
147
|
+
* - Read published content entries only
|
|
148
|
+
* - View media assets
|
|
149
|
+
* - Cannot create, update, delete, or publish any content
|
|
150
|
+
*/
|
|
151
|
+
export declare const VIEWER_ROLE: RoleDefinition;
|
|
152
|
+
/**
|
|
153
|
+
* All default roles indexed by role name.
|
|
154
|
+
* Use this to look up role definitions or iterate over all roles.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* // Get the admin role definition
|
|
159
|
+
* const adminDef = DEFAULT_ROLES.admin;
|
|
160
|
+
*
|
|
161
|
+
* // Iterate over all roles
|
|
162
|
+
* for (const [name, role] of Object.entries(DEFAULT_ROLES)) {
|
|
163
|
+
* console.log(`${name}: ${role.description}`);
|
|
164
|
+
* }
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
export declare const DEFAULT_ROLES: Record<RoleName, RoleDefinition>;
|
|
168
|
+
/**
|
|
169
|
+
* Array of all default role definitions.
|
|
170
|
+
* Useful for UI rendering or iterating over roles.
|
|
171
|
+
*/
|
|
172
|
+
export declare const DEFAULT_ROLES_LIST: RoleDefinition[];
|
|
173
|
+
/**
|
|
174
|
+
* Check if a permission matches a requested permission.
|
|
175
|
+
* Handles scope matching (own scope only matches if requested scope is also own).
|
|
176
|
+
*
|
|
177
|
+
* @param granted - The permission that was granted to the role
|
|
178
|
+
* @param requested - The permission being requested
|
|
179
|
+
* @returns True if the granted permission satisfies the requested permission
|
|
180
|
+
*/
|
|
181
|
+
export declare function permissionMatches(granted: Permission, requested: {
|
|
182
|
+
resource: Resource;
|
|
183
|
+
action: Action;
|
|
184
|
+
scope?: OwnershipScope;
|
|
185
|
+
}): boolean;
|
|
186
|
+
/**
|
|
187
|
+
* Check if a role has a specific permission.
|
|
188
|
+
*
|
|
189
|
+
* @param roleName - The name of the role to check
|
|
190
|
+
* @param permission - The permission to check for (resource + action + optional scope)
|
|
191
|
+
* @param customRoles - Optional custom roles to check in addition to defaults
|
|
192
|
+
* @returns True if the role has the permission
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```typescript
|
|
196
|
+
* // Check if editor can update content entries
|
|
197
|
+
* hasPermission('editor', { resource: 'contentEntries', action: 'update' }); // true
|
|
198
|
+
*
|
|
199
|
+
* // Check if author can publish their own content
|
|
200
|
+
* hasPermission('author', { resource: 'contentEntries', action: 'publish', scope: 'own' }); // true
|
|
201
|
+
*
|
|
202
|
+
* // Check if viewer can update content
|
|
203
|
+
* hasPermission('viewer', { resource: 'contentEntries', action: 'update' }); // false
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
export declare function hasPermission(roleName: RoleName | string, permission: {
|
|
207
|
+
resource: Resource;
|
|
208
|
+
action: Action;
|
|
209
|
+
scope?: OwnershipScope;
|
|
210
|
+
}, customRoles?: Record<string, RoleDefinition>): boolean;
|
|
211
|
+
/**
|
|
212
|
+
* Get all permissions for a role.
|
|
213
|
+
*
|
|
214
|
+
* @param roleName - The name of the role
|
|
215
|
+
* @param customRoles - Optional custom roles to check in addition to defaults
|
|
216
|
+
* @returns Array of permissions, or empty array if role not found
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```typescript
|
|
220
|
+
* const editorPerms = getRolePermissions('editor');
|
|
221
|
+
* console.log(editorPerms.length); // Number of permissions
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
export declare function getRolePermissions(roleName: RoleName | string, customRoles?: Record<string, RoleDefinition>): Permission[];
|
|
225
|
+
/**
|
|
226
|
+
* Get the role definition for a role name.
|
|
227
|
+
*
|
|
228
|
+
* @param roleName - The name of the role
|
|
229
|
+
* @param customRoles - Optional custom roles to check in addition to defaults
|
|
230
|
+
* @returns The role definition, or undefined if not found
|
|
231
|
+
*/
|
|
232
|
+
export declare function getRole(roleName: RoleName | string, customRoles?: Record<string, RoleDefinition>): RoleDefinition | undefined;
|
|
233
|
+
/**
|
|
234
|
+
* Check if a role name is a valid built-in role.
|
|
235
|
+
*
|
|
236
|
+
* @param name - The role name to check
|
|
237
|
+
* @returns True if it's a valid built-in role name
|
|
238
|
+
*/
|
|
239
|
+
export declare function isBuiltInRole(name: string): name is RoleName;
|
|
240
|
+
/**
|
|
241
|
+
* Get all permissions for a specific resource across a role.
|
|
242
|
+
*
|
|
243
|
+
* @param roleName - The name of the role
|
|
244
|
+
* @param resource - The resource to filter by
|
|
245
|
+
* @param customRoles - Optional custom roles to check in addition to defaults
|
|
246
|
+
* @returns Array of permissions for the specified resource
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```typescript
|
|
250
|
+
* // Get all content entry permissions for editor
|
|
251
|
+
* const contentPerms = getResourcePermissions('editor', 'contentEntries');
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
254
|
+
export declare function getResourcePermissions(roleName: RoleName | string, resource: Resource, customRoles?: Record<string, RoleDefinition>): Permission[];
|
|
255
|
+
/**
|
|
256
|
+
* Check if a role can perform any action on a resource.
|
|
257
|
+
*
|
|
258
|
+
* @param roleName - The name of the role
|
|
259
|
+
* @param resource - The resource to check
|
|
260
|
+
* @param customRoles - Optional custom roles to check in addition to defaults
|
|
261
|
+
* @returns True if the role h permission on the resource
|
|
262
|
+
*/
|
|
263
|
+
export declare function canAccessResource(roleName: RoleName | string, resource: Resource, customRoles?: Record<string, RoleDefinition>): boolean;
|
|
264
|
+
/**
|
|
265
|
+
* Extended permission with optional content-type-specific restrictions.
|
|
266
|
+
* Allows for fine-grained control over which content types a permission applies to.
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* ```typescript
|
|
270
|
+
* // Permission that only applies to blog_post and news content types
|
|
271
|
+
* const permission: ContentTypePermission = {
|
|
272
|
+
* resource: "contentEntries",
|
|
273
|
+
* action: "create",
|
|
274
|
+
* contentTypes: ["blog_post", "news"],
|
|
275
|
+
* };
|
|
276
|
+
*
|
|
277
|
+
* // Permission that applies to all content types except legal
|
|
278
|
+
* const restrictedPerm: ContentTypePermission = {
|
|
279
|
+
* resource: "contentEntries",
|
|
280
|
+
* action: "publish",
|
|
281
|
+
* excludeContentTypes: ["legal_document"],
|
|
282
|
+
* };
|
|
283
|
+
* ```
|
|
284
|
+
*/
|
|
285
|
+
export interface ContentTypePermission extends Permission {
|
|
286
|
+
/**
|
|
287
|
+
* Whitelist of content type names this permission applies to.
|
|
288
|
+
* If specified, permission only grants access to these content types.
|
|
289
|
+
* Cannot be used with excludeContentTypes.
|
|
290
|
+
*/
|
|
291
|
+
contentTypes?: string[];
|
|
292
|
+
/**
|
|
293
|
+
* Blacklist of content type names this permission does NOT apply to.
|
|
294
|
+
* If specified, permission grants access to all content types except these.
|
|
295
|
+
* Cannot be used with contentTypes.
|
|
296
|
+
*/
|
|
297
|
+
excludeContentTypes?: string[];
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Configuration for creating a custom role.
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* ```typescript
|
|
304
|
+
* // Create a new role from scratch
|
|
305
|
+
* const blogAuthor: CustomRoleConfig = {
|
|
306
|
+
* name: "blog-author",
|
|
307
|
+
* displayName: "Blog Author",
|
|
308
|
+
* description: "Can create and manage blog posts only",
|
|
309
|
+
* permissions: [
|
|
310
|
+
* { resource: "contentTypes", action: "read" },
|
|
311
|
+
* { resource: "contentEntries", action: "create", contentTypes: ["blog_post"] },
|
|
312
|
+
* { resource: "contentEntries", action: "read", scope: "own", contentTypes: ["blog_post"] },
|
|
313
|
+
* { resource: "contentEntries", action: "update", scope: "own", contentTypes: ["blog_post"] },
|
|
314
|
+
* ],
|
|
315
|
+
* };
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
export interface CustomRoleConfig {
|
|
319
|
+
/** Unique identifier for the custom role */
|
|
320
|
+
name: string;
|
|
321
|
+
/** Human-readable display name */
|
|
322
|
+
displayName: string;
|
|
323
|
+
/** Description of the role's purpose */
|
|
324
|
+
description: string;
|
|
325
|
+
/** Permissions granted to this role */
|
|
326
|
+
permissions: ContentTypePermission[];
|
|
327
|
+
/** Whether this role should be treated as a system role (cannot be deleted) */
|
|
328
|
+
isSystem?: boolean;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Configuration for extending an existing role.
|
|
332
|
+
*
|
|
333
|
+
* @example
|
|
334
|
+
* ```typescript
|
|
335
|
+
* // Extend the author role with additional permissions
|
|
336
|
+
* const seniorAuthor: ExtendRoleConfig = {
|
|
337
|
+
* name: "senior-author",
|
|
338
|
+
* displayName: "Senior Author",
|
|
339
|
+
* description: "Author with additional publishing rights",
|
|
340
|
+
* extends: "author",
|
|
341
|
+
* addPermissions: [
|
|
342
|
+
* { resource: "contentEntries", action: "publish" },
|
|
343
|
+
* ],
|
|
344
|
+
* };
|
|
345
|
+
*
|
|
346
|
+
* // Extend editor but restrict to certain content types
|
|
347
|
+
* const blogEditor: ExtendRoleConfig = {
|
|
348
|
+
* name: "blog-editor",
|
|
349
|
+
* displayName: "Blog Editor",
|
|
350
|
+
* description: "Editor for blog content only",
|
|
351
|
+
* extends: "editor",
|
|
352
|
+
* addPermissions: [],
|
|
353
|
+
* removePermissions: [
|
|
354
|
+
* { resource: "contentEntries", action: "create" },
|
|
355
|
+
* ],
|
|
356
|
+
* restrictToContentTypes: ["blog_post", "blog_category"],
|
|
357
|
+
* };
|
|
358
|
+
* ```
|
|
359
|
+
*/
|
|
360
|
+
export interface ExtendRoleConfig {
|
|
361
|
+
/** Unique identifier for the extended role */
|
|
362
|
+
name: string;
|
|
363
|
+
/** Human-readable display name */
|
|
364
|
+
displayName: string;
|
|
365
|
+
/** Description of the role's purpose */
|
|
366
|
+
description: string;
|
|
367
|
+
/** Name of the role to extend (can be built-in or custom) */
|
|
368
|
+
extends: RoleName | string;
|
|
369
|
+
/** Additional permissions to add to the extended role */
|
|
370
|
+
addPermissions?: ContentTypePermission[];
|
|
371
|
+
/**
|
|
372
|
+
* Permissions to remove from the extended role.
|
|
373
|
+
* Matching is done by resource + action (scope is ignored for removal).
|
|
374
|
+
*/
|
|
375
|
+
removePermissions?: Array<{
|
|
376
|
+
resource: Resource;
|
|
377
|
+
action: Action;
|
|
378
|
+
}>;
|
|
379
|
+
/**
|
|
380
|
+
* Restrict all contentEntries permissions to these content types.
|
|
381
|
+
* If specified, all contentEntries permissions are limited to only these types.
|
|
382
|
+
*/
|
|
383
|
+
restrictToContentTypes?: string[];
|
|
384
|
+
/** Whether this role should be treated as a system role */
|
|
385
|
+
isSystem?: boolean;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Extended role definition that supports content-type-specific permissions.
|
|
389
|
+
* This is the runtime representation of a role that may have per-content-type restrictions.
|
|
390
|
+
*/
|
|
391
|
+
export interface ExtendedRoleDefinition {
|
|
392
|
+
/** Unique role identifier */
|
|
393
|
+
name: string;
|
|
394
|
+
/** Human-readable display name */
|
|
395
|
+
displayName: string;
|
|
396
|
+
/** Description of the role's purpose */
|
|
397
|
+
description: string;
|
|
398
|
+
/** List of permissions granted to this role (may include content-type restrictions) */
|
|
399
|
+
permissions: ContentTypePermission[];
|
|
400
|
+
/** Whether this is a system role that cannot be deleted */
|
|
401
|
+
isSystem: boolean;
|
|
402
|
+
/** If this role was extended from another, the source role name */
|
|
403
|
+
extendsRole?: string;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Creates a new custom role from configuration.
|
|
407
|
+
*
|
|
408
|
+
* @param config - The custom role configuration
|
|
409
|
+
* @returns A role definition ready to use with the RBAC system
|
|
410
|
+
*
|
|
411
|
+
* @example
|
|
412
|
+
* ```typescript
|
|
413
|
+
* const blogAuthor = createCustomRole({
|
|
414
|
+
* name: "blog-author",
|
|
415
|
+
* displayName: "Blog Author",
|
|
416
|
+
* description: "Can create and manage blog posts",
|
|
417
|
+
* permissions: [
|
|
418
|
+
* { resource: "contentTypes", action: "read" },
|
|
419
|
+
* { resource: "contentEntries", action: "create", contentTypes: ["blog_post"] },
|
|
420
|
+
* { resource: "contentEntries", action: "read", scope: "own", contentTypes: ["blog_post"] },
|
|
421
|
+
* { resource: "contentEntries", action: "update", scope: "own", contentTypes: ["blog_post"] },
|
|
422
|
+
* { resource: "contentEntries", action: "delete", scope: "own", contentTypes: ["blog_post"] },
|
|
423
|
+
* { resource: "mediaItems", action: "create" },
|
|
424
|
+
* { resource: "mediaItems", action: "read" },
|
|
425
|
+
* ],
|
|
426
|
+
* });
|
|
427
|
+
* ```
|
|
428
|
+
*/
|
|
429
|
+
export declare function createCustomRole(config: CustomRoleConfig): ExtendedRoleDefinition;
|
|
430
|
+
/**
|
|
431
|
+
* Extends an existing role with additional or removed permissions.
|
|
432
|
+
*
|
|
433
|
+
* This function creates a new role based on an existing one, allowing you to:
|
|
434
|
+
* - Add new permissions
|
|
435
|
+
* - Remove existing permissions
|
|
436
|
+
* - Restrict all contentEntries permissions to specific content types
|
|
437
|
+
*
|
|
438
|
+
* @param config - The extend role configuration
|
|
439
|
+
* @param customRoles - Optional existing custom roles to look up the base role from
|
|
440
|
+
* @returns A new role definition with the modified permissions
|
|
441
|
+
*
|
|
442
|
+
* @example
|
|
443
|
+
* ```typescript
|
|
444
|
+
* // Create a senior author who can publish their own content
|
|
445
|
+
* const seniorAuthor = extendRole({
|
|
446
|
+
* name: "senior-author",
|
|
447
|
+
* displayName: "Senior Author",
|
|
448
|
+
* description: "Author with publishing rights",
|
|
449
|
+
* extends: "author",
|
|
450
|
+
* addPermissions: [
|
|
451
|
+
* { resource: "contentEntries", action: "publish", scope: "own" },
|
|
452
|
+
* { resource: "contentEntries", action: "unpublish", scope: "own" },
|
|
453
|
+
* ],
|
|
454
|
+
* });
|
|
455
|
+
*
|
|
456
|
+
* // Create a blog-only editor
|
|
457
|
+
* const blogEditor = extendRole({
|
|
458
|
+
* name: "blog-editor",
|
|
459
|
+
* displayName: "Blog Editor",
|
|
460
|
+
* description: "Can only edit blog content",
|
|
461
|
+
* extends: "editor",
|
|
462
|
+
* restrictToContentTypes: ["blog_post", "blog_category"],
|
|
463
|
+
* });
|
|
464
|
+
* ```
|
|
465
|
+
*/
|
|
466
|
+
export declare function extendRole(config: ExtendRoleConfig, customRoles?: Record<string, RoleDefinition | ExtendedRoleDefinition>): ExtendedRoleDefinition;
|
|
467
|
+
/**
|
|
468
|
+
* Merges custom roles with the default roles.
|
|
469
|
+
*
|
|
470
|
+
* Creates a combined role registry that includes both default and custom roles.
|
|
471
|
+
* Custom roles do NOT override default roles - they exist alongside them.
|
|
472
|
+
*
|
|
473
|
+
* @param customRoles - Array of custom role definitions
|
|
474
|
+
* @returns A record of all roles (default + custom)
|
|
475
|
+
*
|
|
476
|
+
* @example
|
|
477
|
+
* ```typescript
|
|
478
|
+
* const blogAuthor = createCustomRole({...});
|
|
479
|
+
* const seniorAuthor = extendRole({...});
|
|
480
|
+
*
|
|
481
|
+
* const allRoles = mergeRolesWithDefaults([blogAuthor, seniorAuthor]);
|
|
482
|
+
* // allRoles contains: admin, editor, author, viewer, blog-author, senior-author
|
|
483
|
+
* ```
|
|
484
|
+
*/
|
|
485
|
+
export declare function mergeRolesWithDefaults(customRoles: Array<RoleDefinition | ExtendedRoleDefinition>): Record<string, RoleDefinition | ExtendedRoleDefinition>;
|
|
486
|
+
/**
|
|
487
|
+
* Creates a custom roles record from an array of role definitions.
|
|
488
|
+
* Use this to pass custom roles to permission checking functions.
|
|
489
|
+
*
|
|
490
|
+
* @param roles - Array of custom role definitions
|
|
491
|
+
* @returns A record indexed by role name
|
|
492
|
+
*
|
|
493
|
+
* @example
|
|
494
|
+
* ```typescript
|
|
495
|
+
* const customRoles = buildCustomRolesRecord([blogAuthor, seniorAuthor]);
|
|
496
|
+
* hasPermission("blog-author", { resource: "contentEntries", action: "create" }, customRoles);
|
|
497
|
+
* ```
|
|
498
|
+
*/
|
|
499
|
+
export declare function buildCustomRolesRecord(roles: Array<RoleDefinition | ExtendedRoleDefinition>): Record<string, RoleDefinition | ExtendedRoleDefinition>;
|
|
500
|
+
/**
|
|
501
|
+
* Options for checking permissions with content-type awareness.
|
|
502
|
+
*/
|
|
503
|
+
export interface ContentTypePermissionCheckOptions {
|
|
504
|
+
/**
|
|
505
|
+
* Custom roles to include when checking permissions.
|
|
506
|
+
*/
|
|
507
|
+
customRoles?: Record<string, RoleDefinition | ExtendedRoleDefinition>;
|
|
508
|
+
/**
|
|
509
|
+
* The content type name to check permissions for.
|
|
510
|
+
* Required when the permission may have content-type restrictions.
|
|
511
|
+
*/
|
|
512
|
+
contentTypeName?: string;
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Extended permission check that includes content-type-specific restrictions.
|
|
516
|
+
*
|
|
517
|
+
* Use this function when you need to check if a role can perform an action
|
|
518
|
+
* on a specific content type.
|
|
519
|
+
*
|
|
520
|
+
* @param roleName - The name of the role to check
|
|
521
|
+
* @param permission - The permission to check (resource + action + optional scope)
|
|
522
|
+
* @param options - Additional options including custom roles and content type
|
|
523
|
+
* @returns True if the role has the permission for the specified content type
|
|
524
|
+
*
|
|
525
|
+
* @example
|
|
526
|
+
* ```typescript
|
|
527
|
+
* // Check if blog-author can create blog posts
|
|
528
|
+
* hasContentTypePermission("blog-author", {
|
|
529
|
+
* resource: "contentEntries",
|
|
530
|
+
* action: "create",
|
|
531
|
+
* }, {
|
|
532
|
+
* customRoles: allRoles,
|
|
533
|
+
* contentTypeName: "blog_post",
|
|
534
|
+
* }); // true
|
|
535
|
+
*
|
|
536
|
+
* // Check if blog-author can create legal documents
|
|
537
|
+
* hasContentTypePermission("blog-author", {
|
|
538
|
+
* resource: "contentEntries",
|
|
539
|
+
* action: "create",
|
|
540
|
+
* }, {
|
|
541
|
+
* customRoles: allRoles,
|
|
542
|
+
* contentTypeName: "legal_document",
|
|
543
|
+
* }); // false (restricted to blog_post only)
|
|
544
|
+
* ```
|
|
545
|
+
*/
|
|
546
|
+
export declare function hasContentTypePermission(roleName: RoleName | string, permission: {
|
|
547
|
+
resource: Resource;
|
|
548
|
+
action: Action;
|
|
549
|
+
scope?: OwnershipScope;
|
|
550
|
+
}, options?: ContentTypePermissionCheckOptions): boolean;
|
|
551
|
+
/**
|
|
552
|
+
* Gets all content types that a role can perform an action on.
|
|
553
|
+
*
|
|
554
|
+
* @param roleName - The name of the role
|
|
555
|
+
* @param action - The action to check
|
|
556
|
+
* @param options - Additional options
|
|
557
|
+
* @returns Array of content type names, or ["*"] if unrestricted, or [] if no permission
|
|
558
|
+
*
|
|
559
|
+
* @example
|
|
560
|
+
* ```typescript
|
|
561
|
+
* // Get content types the blog-author can create
|
|
562
|
+
* getPermittedContentTypes("blog-author", "create", { customRoles });
|
|
563
|
+
* // Returns: ["blog_post"]
|
|
564
|
+
*
|
|
565
|
+
* // Get content types the editor can update
|
|
566
|
+
* getPermittedContentTypes("editor", "update", { customRoles });
|
|
567
|
+
* // Returns: ["*"] (unrestricted)
|
|
568
|
+
* ```
|
|
569
|
+
*/
|
|
570
|
+
export declare function getPermittedContentTypes(roleName: RoleName | string, action: Action, options?: {
|
|
571
|
+
customRoles?: Record<string, RoleDefinition | ExtendedRoleDefinition>;
|
|
572
|
+
}): string[];
|
|
573
|
+
/**
|
|
574
|
+
* Gets all content types that a role is excluded from for an action.
|
|
575
|
+
*
|
|
576
|
+
* @param roleName - The name of the role
|
|
577
|
+
* @param action - The action to check
|
|
578
|
+
* @param options - Additional options
|
|
579
|
+
* @returns Array of excluded content type names, or [] if none
|
|
580
|
+
*/
|
|
581
|
+
export declare function getExcludedContentTypes(roleName: RoleName | string, action: Action, options?: {
|
|
582
|
+
customRoles?: Record<string, RoleDefinition | ExtendedRoleDefinition>;
|
|
583
|
+
}): string[];
|
|
584
|
+
/**
|
|
585
|
+
* Helper to create a full CRUD permission set for a resource with optional content type restriction.
|
|
586
|
+
*
|
|
587
|
+
* @param resource - The resource to grant permissions on
|
|
588
|
+
* @param options - Optional scope and content type restrictions
|
|
589
|
+
* @returns Array of permissions
|
|
590
|
+
*
|
|
591
|
+
* @example
|
|
592
|
+
* ```typescript
|
|
593
|
+
* // Full CRUD on contentEntries for blog_post only
|
|
594
|
+
* fullCrudForContentType("contentEntries", {
|
|
595
|
+
* contentTypes: ["blog_post"],
|
|
596
|
+
* scope: "own",
|
|
597
|
+
* });
|
|
598
|
+
* ```
|
|
599
|
+
*/
|
|
600
|
+
export declare function fullCrudForContentType(resource: Resource, options?: {
|
|
601
|
+
scope?: OwnershipScope;
|
|
602
|
+
contentTypes?: string[];
|
|
603
|
+
excludeContentTypes?: string[];
|
|
604
|
+
}): ContentTypePermission[];
|
|
605
|
+
/**
|
|
606
|
+
* Helper to create publish permissions with optional content type restriction.
|
|
607
|
+
*
|
|
608
|
+
* @param options - Optional scope and content type restrictions
|
|
609
|
+
* @returns Array of publish/unpublish permissions
|
|
610
|
+
*/
|
|
611
|
+
export declare function publishPermissionsForContentType(options?: {
|
|
612
|
+
scope?: OwnershipScope;
|
|
613
|
+
contentTypes?: string[];
|
|
614
|
+
excludeContentTypes?: string[];
|
|
615
|
+
}): ContentTypePermission[];
|
|
616
|
+
/**
|
|
617
|
+
* Helper to create read-only permission with optional content type restriction.
|
|
618
|
+
*
|
|
619
|
+
* @param resource - The resource to grant read permission on
|
|
620
|
+
* @param options - Optional scope and content type restrictions
|
|
621
|
+
* @returns Array with single read permission
|
|
622
|
+
*/
|
|
623
|
+
export declare function readOnlyForContentType(resource: Resource, options?: {
|
|
624
|
+
scope?: OwnershipScope;
|
|
625
|
+
contentTypes?: string[];
|
|
626
|
+
excludeContentTypes?: string[];
|
|
627
|
+
}): ContentTypePermission[];
|
|
628
|
+
/**
|
|
629
|
+
* Validates a custom role configuration.
|
|
630
|
+
*
|
|
631
|
+
* @param config - The custom role configuration to validate
|
|
632
|
+
* @returns An object with isValid boolean and optional error messages
|
|
633
|
+
*/
|
|
634
|
+
export declare function validateCustomRoleConfig(config: CustomRoleConfig): {
|
|
635
|
+
isValid: boolean;
|
|
636
|
+
errors: string[];
|
|
637
|
+
};
|
|
638
|
+
/**
|
|
639
|
+
* Validates an extend role configuration.
|
|
640
|
+
*
|
|
641
|
+
* @param config - The extend role configuration to validate
|
|
642
|
+
* @param customRoles - Optional custom roles to check the base role in
|
|
643
|
+
* @returns An object with isValid boolean and optional error messages
|
|
644
|
+
*/
|
|
645
|
+
export declare function validateExtendRoleConfig(config: ExtendRoleConfig, customRoles?: Record<string, RoleDefinition | ExtendedRoleDefinition>): {
|
|
646
|
+
isValid: boolean;
|
|
647
|
+
errors: string[];
|
|
648
|
+
};
|
|
649
|
+
//# sourceMappingURL=roles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roles.d.ts","sourceRoot":"","sources":["../../src/component/roles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAQH;;;GAGG;AACH,eAAO,MAAM,SAAS,kDAAmD,CAAC;AAE1E;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC;AAEhD;;;GAGG;AACH,eAAO,MAAM,iBAAiB,8TAK7B,CAAC;AAMF;;GAEG;AACH,eAAO,MAAM,SAAS,uEAKZ,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC;AAEhD;;GAEG;AACH,eAAO,MAAM,iBAAiB,wWAK7B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,OAAO,sGAUV,CAAC;AAEX,MAAM,MAAM,MAAM,GAAG,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;AAE5C;;GAEG;AACH,eAAO,MAAM,eAAe,ipBAU3B,CAAC;AAMF;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,KAAK,CAAC;AAE3C;;;GAGG;AACH,MAAM,WAAW,UAAU;IAC1B,8CAA8C;IAC9C,QAAQ,EAAE,QAAQ,CAAC;IACnB,+BAA+B;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,KAAK,CAAC,EAAE,cAAc,CAAC;CACvB;AAED;;GAEG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;+CAI9B,CAAC;AAEH;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,6BA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