Skip to content

Commit

Permalink
refactor: Remove all scope definition duplication (no-changelog) (#11401
Browse files Browse the repository at this point in the history
)
  • Loading branch information
valya authored Oct 24, 2024
1 parent 8201d32 commit 95c5df0
Showing 1 changed file with 8 additions and 47 deletions.
55 changes: 8 additions & 47 deletions packages/@n8n/permissions/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { DEFAULT_OPERATIONS, RESOURCES } from './constants';
import type { RESOURCES } from './constants';

export type DefaultOperations = (typeof DEFAULT_OPERATIONS)[number];
export type Resource = keyof typeof RESOURCES;

export type ResourceScope<
Expand All @@ -10,52 +9,14 @@ export type ResourceScope<

export type WildcardScope = `${Resource}:*` | '*';

export type AnnotationTagScope = ResourceScope<'annotationTag'>;
export type AuditLogsScope = ResourceScope<'auditLogs'>;
export type BannerScope = ResourceScope<'banner'>;
export type CommunityScope = ResourceScope<'community'>;
export type CommunityPackageScope = ResourceScope<'communityPackage'>;
export type CredentialScope = ResourceScope<'credential'>;
export type ExternalSecretScope = ResourceScope<'externalSecret'>;
export type ExternalSecretProviderScope = ResourceScope<'externalSecretsProvider'>;
export type EventBusDestinationScope = ResourceScope<'eventBusDestination'>;
export type LdapScope = ResourceScope<'ldap'>;
export type LicenseScope = ResourceScope<'license'>;
export type LogStreamingScope = ResourceScope<'logStreaming'>;
export type OrchestrationScope = ResourceScope<'orchestration'>;
export type ProjectScope = ResourceScope<'project'>;
export type SamlScope = ResourceScope<'saml'>;
export type SecurityAuditScope = ResourceScope<'securityAudit'>;
export type SourceControlScope = ResourceScope<'sourceControl'>;
export type TagScope = ResourceScope<'tag'>;
export type UserScope = ResourceScope<'user'>;
export type VariableScope = ResourceScope<'variable'>;
export type WorkersViewScope = ResourceScope<'workersView'>;
export type WorkflowScope = ResourceScope<'workflow'>;
// This is purely an intermediary type.
// If we tried to do use `ResourceScope<Resource>` directly we'd end
// up with all resources having all scopes (e.g. `ldap:uninstall`).
type AllScopesObject = {
[R in Resource]: ResourceScope<R>;
};

export type Scope =
| AnnotationTagScope
| AuditLogsScope
| BannerScope
| CommunityScope
| CommunityPackageScope
| CredentialScope
| ExternalSecretProviderScope
| ExternalSecretScope
| EventBusDestinationScope
| LdapScope
| LicenseScope
| LogStreamingScope
| OrchestrationScope
| ProjectScope
| SamlScope
| SecurityAuditScope
| SourceControlScope
| TagScope
| UserScope
| VariableScope
| WorkersViewScope
| WorkflowScope;
export type Scope<K extends Resource = Resource> = AllScopesObject[K];

export type ScopeLevel = 'global' | 'project' | 'resource';
export type GetScopeLevel<T extends ScopeLevel> = Record<T, Scope[]>;
Expand Down

0 comments on commit 95c5df0

Please sign in to comment.