@apipass/permissions 1.0.192 → 1.0.193
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/README.md +36 -14
- package/esm2022/public-api.mjs +2 -1
- package/esm2022/service/permissions.providers.mjs +37 -0
- package/fesm2022/apipass-permissions.mjs +36 -2
- package/fesm2022/apipass-permissions.mjs.map +1 -1
- package/package.json +1 -1
- package/public-api.d.ts +1 -0
- package/service/permissions.providers.d.ts +30 -0
package/README.md
CHANGED
|
@@ -24,30 +24,51 @@ These mirror the React `PermissionGate`:
|
|
|
24
24
|
|
|
25
25
|
## Setup
|
|
26
26
|
|
|
27
|
+
Each app supplies one `PermissionsConfig` (how to read the Cerbos toggle, how to
|
|
28
|
+
build the principal, how to resolve legacy decisions) and wires everything with a
|
|
29
|
+
single `providePermissions` call:
|
|
30
|
+
|
|
27
31
|
```ts
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
// permissions-config.factory.ts — the only app-specific piece
|
|
33
|
+
export function permissionsConfigFactory(featureToggle: FeatureToggleService, iam: IamService): PermissionsConfig {
|
|
34
|
+
return {
|
|
35
|
+
cerbosEnabled: async () => (await featureToggle.getFeatures()).isCerbosEnabled(),
|
|
36
|
+
userInfo: async () => (await iam.getLoggedUserInfo()).cerbosUserInfo,
|
|
37
|
+
legacyResolver: async ({ kind, action }, ctx) => {
|
|
38
|
+
const { role } = await iam.getLoggedUserInfo()
|
|
39
|
+
// map { kind, action } → role.canX()
|
|
40
|
+
if (kind === 'flow' && action === 'read') return role.canAccessFlow((ctx as LegacyContext)?.projectId)
|
|
41
|
+
return false
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { PermissionsModule, providePermissions } from '@apipass/permissions'
|
|
30
49
|
|
|
31
50
|
@NgModule({
|
|
32
51
|
imports: [PermissionsModule, /* ... */],
|
|
33
52
|
providers: [
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
legacyResolver: async ({ kind, action }, ctx) => {
|
|
39
|
-
const { role } = await iamService.getLoggedUserInfo()
|
|
40
|
-
// map { kind, action } → role.canX()
|
|
41
|
-
if (kind === 'flow' && action === 'read') return role.canAccessFlow((ctx as any)?.projectId)
|
|
42
|
-
return false
|
|
43
|
-
}
|
|
53
|
+
providePermissions({
|
|
54
|
+
cerbosUrl: 'https://cerbos.example.com', // optional: registers CERBOS_SERVICE
|
|
55
|
+
configFactory: permissionsConfigFactory,
|
|
56
|
+
deps: [FEATURE_TOGGLE_SERVICE, IAM_SERVICE]
|
|
44
57
|
})
|
|
45
58
|
]
|
|
46
59
|
})
|
|
47
60
|
export class AppModule {}
|
|
48
61
|
```
|
|
49
62
|
|
|
50
|
-
|
|
63
|
+
For a static config without DI, pass `config` instead of `configFactory`/`deps`
|
|
64
|
+
(or use the lower-level `providePermissionsConfig`).
|
|
65
|
+
|
|
66
|
+
`HttpClient` must be available (e.g. via `provideHttpClient()`), as required by
|
|
67
|
+
`provideCerbos` when `cerbosUrl` is set.
|
|
68
|
+
|
|
69
|
+
> Adoption note: the config callbacks are inherently app-specific. Apps whose
|
|
70
|
+
> `UserInfo` does not expose `cerbosUserInfo` need a small adapter building
|
|
71
|
+
> `{ accountId, domain, roles }` from their own user model.
|
|
51
72
|
|
|
52
73
|
## Reading permissions
|
|
53
74
|
|
|
@@ -105,7 +126,8 @@ For Material controls prefer the component: Material reads its own `disabled`
|
|
|
105
126
|
| Symbol | Kind | Description |
|
|
106
127
|
|---|---|---|
|
|
107
128
|
| `PermissionsService` | service | `checkResource` / `checkResources`, hybrid Cerbos + legacy |
|
|
108
|
-
| `
|
|
129
|
+
| `providePermissions` / `ProvidePermissionsOptions` | fn / interface | One-call setup (config + service + optional Cerbos) |
|
|
130
|
+
| `PERMISSIONS_CONFIG` / `providePermissionsConfig` | token / fn | Lower-level per-app wiring |
|
|
109
131
|
| `PermissionsConfig` / `LegacyCheck` | interface | Config contract |
|
|
110
132
|
| `PermissionGateComponent` | component | `<apipass-permission-gate>` |
|
|
111
133
|
| `PermissionGateDirective` | directive | `[apipassPermissionGate]` |
|
package/esm2022/public-api.mjs
CHANGED
|
@@ -3,6 +3,7 @@ export * from './permission-gate/permission-gate.component';
|
|
|
3
3
|
export * from './permission-gate/permission-gate.directive';
|
|
4
4
|
export * from './service/permissions.service';
|
|
5
5
|
export * from './service/permissions.config';
|
|
6
|
+
export * from './service/permissions.providers';
|
|
6
7
|
export * from './model/permission-check.interface';
|
|
7
8
|
export * from './model/permission-result.interface';
|
|
8
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
9
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHVibGljLWFwaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3Byb2plY3RzL3Blcm1pc3Npb25zL3NyYy9wdWJsaWMtYXBpLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLGNBQWMsc0JBQXNCLENBQUE7QUFDcEMsY0FBYyw2Q0FBNkMsQ0FBQTtBQUMzRCxjQUFjLDZDQUE2QyxDQUFBO0FBQzNELGNBQWMsK0JBQStCLENBQUE7QUFDN0MsY0FBYyw4QkFBOEIsQ0FBQTtBQUM1QyxjQUFjLGlDQUFpQyxDQUFBO0FBQy9DLGNBQWMsb0NBQW9DLENBQUE7QUFDbEQsY0FBYyxxQ0FBcUMsQ0FBQSIsInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCAqIGZyb20gJy4vcGVybWlzc2lvbnMubW9kdWxlJ1xuZXhwb3J0ICogZnJvbSAnLi9wZXJtaXNzaW9uLWdhdGUvcGVybWlzc2lvbi1nYXRlLmNvbXBvbmVudCdcbmV4cG9ydCAqIGZyb20gJy4vcGVybWlzc2lvbi1nYXRlL3Blcm1pc3Npb24tZ2F0ZS5kaXJlY3RpdmUnXG5leHBvcnQgKiBmcm9tICcuL3NlcnZpY2UvcGVybWlzc2lvbnMuc2VydmljZSdcbmV4cG9ydCAqIGZyb20gJy4vc2VydmljZS9wZXJtaXNzaW9ucy5jb25maWcnXG5leHBvcnQgKiBmcm9tICcuL3NlcnZpY2UvcGVybWlzc2lvbnMucHJvdmlkZXJzJ1xuZXhwb3J0ICogZnJvbSAnLi9tb2RlbC9wZXJtaXNzaW9uLWNoZWNrLmludGVyZmFjZSdcbmV4cG9ydCAqIGZyb20gJy4vbW9kZWwvcGVybWlzc2lvbi1yZXN1bHQuaW50ZXJmYWNlJ1xuIl19
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { provideCerbos } from '@apipass/frontend-utils';
|
|
2
|
+
import { PERMISSIONS_CONFIG } from './permissions.config';
|
|
3
|
+
import { PermissionsService } from './permissions.service';
|
|
4
|
+
/**
|
|
5
|
+
* One-call setup for `@apipass/permissions`: registers the {@link PERMISSIONS_CONFIG},
|
|
6
|
+
* the {@link PermissionsService} and (optionally) the Cerbos service.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* @NgModule({
|
|
11
|
+
* providers: [
|
|
12
|
+
* providePermissions({
|
|
13
|
+
* cerbosUrl: $ENV.CERBOS_PDP_URL,
|
|
14
|
+
* configFactory: permissionsConfigFactory,
|
|
15
|
+
* deps: [FEATURE_TOGGLE_SERVICE, IAM_SERVICE]
|
|
16
|
+
* })
|
|
17
|
+
* ]
|
|
18
|
+
* })
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export function providePermissions(options) {
|
|
22
|
+
const { config, configFactory, deps, cerbosUrl } = options;
|
|
23
|
+
if ((config && configFactory) || (!config && !configFactory)) {
|
|
24
|
+
throw new Error('providePermissions: provide exactly one of `config` or `configFactory`');
|
|
25
|
+
}
|
|
26
|
+
const providers = [
|
|
27
|
+
config
|
|
28
|
+
? { provide: PERMISSIONS_CONFIG, useValue: config }
|
|
29
|
+
: { provide: PERMISSIONS_CONFIG, useFactory: configFactory, deps: deps ?? [] },
|
|
30
|
+
PermissionsService
|
|
31
|
+
];
|
|
32
|
+
if (cerbosUrl) {
|
|
33
|
+
providers.push(provideCerbos(cerbosUrl));
|
|
34
|
+
}
|
|
35
|
+
return providers;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGVybWlzc2lvbnMucHJvdmlkZXJzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vcHJvamVjdHMvcGVybWlzc2lvbnMvc3JjL3NlcnZpY2UvcGVybWlzc2lvbnMucHJvdmlkZXJzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sRUFBRSxhQUFhLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQTtBQUN2RCxPQUFPLEVBQUUsa0JBQWtCLEVBQXFCLE1BQU0sc0JBQXNCLENBQUE7QUFDNUUsT0FBTyxFQUFFLGtCQUFrQixFQUFFLE1BQU0sdUJBQXVCLENBQUE7QUFhMUQ7Ozs7Ozs7Ozs7Ozs7Ozs7R0FnQkc7QUFDSCxNQUFNLFVBQVUsa0JBQWtCLENBQUMsT0FBa0M7SUFDbkUsTUFBTSxFQUFFLE1BQU0sRUFBRSxhQUFhLEVBQUUsSUFBSSxFQUFFLFNBQVMsRUFBRSxHQUFHLE9BQU8sQ0FBQTtJQUUxRCxJQUFJLENBQUMsTUFBTSxJQUFJLGFBQWEsQ0FBQyxJQUFJLENBQUMsQ0FBQyxNQUFNLElBQUksQ0FBQyxhQUFhLENBQUMsRUFBRTtRQUM1RCxNQUFNLElBQUksS0FBSyxDQUFDLHdFQUF3RSxDQUFDLENBQUE7S0FDMUY7SUFFRCxNQUFNLFNBQVMsR0FBZTtRQUM1QixNQUFNO1lBQ0osQ0FBQyxDQUFDLEVBQUUsT0FBTyxFQUFFLGtCQU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ZmlnLCBjb25maWdGYWN0b3J5LCBkZXBzLCBjZXJib3NVcmwgfSA9IG9wdGlvbnNcblxuICBpZiAoKGNvbmZpZyAmJiBjb25maWdGYWN0b3J5KSB8fCAoIWNvbmZpZyAmJiAhY29uZmlnRmFjdG9yeSkpIHtcbiAgICB0aHJvdyBuZXcgRXJyb3IoJ3Byb3ZpZGVQZXJtaXNzaW9uczogcHJvdmlkZSBleGFjdGx5IG9uZSBvZiBgY29uZmlnYCBvciBgY29uZmlnRmFjdG9yeWAnKVxuICB9XG5cbiAgY29uc3QgcHJvdmlkZXJzOiBQcm92aWRlcltdID0gW1xuICAgIGNvbmZpZ1xuICAgICAgPyB7IHByb3ZpZGU6IFBFUk1JU1NJT05TX0NPTkZJRywgdXNlVmFsdWU6IGNvbmZpZyB9XG4gICAgICA6IHsgcHJvdmlkZTogUEVSTUlTU0lPTlNfQ09ORklHLCB1c2VGYWN0b3J5OiBjb25maWdGYWN0b3J5LCBkZXBzOiBkZXBzID8/IFtdIH0sXG4gICAgUGVybWlzc2lvbnNTZXJ2aWNlXG4gIF1cblxuICBpZiAoY2VyYm9zVXJsKSB7XG4gICAgcHJvdmlkZXJzLnB1c2gocHJvdmlkZUNlcmJvcyhjZXJib3NVcmwpKVxuICB9XG5cbiAgcmV0dXJuIHByb3ZpZGVyc1xufVxuIl19
|
|
@@ -4,7 +4,7 @@ import * as i1 from '@angular/common';
|
|
|
4
4
|
import { CommonModule } from '@angular/common';
|
|
5
5
|
import * as i2 from '@angular/material/tooltip';
|
|
6
6
|
import { MatTooltipModule } from '@angular/material/tooltip';
|
|
7
|
-
import { CERBOS_SERVICE } from '@apipass/frontend-utils';
|
|
7
|
+
import { CERBOS_SERVICE, provideCerbos } from '@apipass/frontend-utils';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Angular equivalent of the React `PermissionGate`.
|
|
@@ -223,9 +223,43 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.2", ngImpor
|
|
|
223
223
|
}]
|
|
224
224
|
}] });
|
|
225
225
|
|
|
226
|
+
/**
|
|
227
|
+
* One-call setup for `@apipass/permissions`: registers the {@link PERMISSIONS_CONFIG},
|
|
228
|
+
* the {@link PermissionsService} and (optionally) the Cerbos service.
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```ts
|
|
232
|
+
* @NgModule({
|
|
233
|
+
* providers: [
|
|
234
|
+
* providePermissions({
|
|
235
|
+
* cerbosUrl: $ENV.CERBOS_PDP_URL,
|
|
236
|
+
* configFactory: permissionsConfigFactory,
|
|
237
|
+
* deps: [FEATURE_TOGGLE_SERVICE, IAM_SERVICE]
|
|
238
|
+
* })
|
|
239
|
+
* ]
|
|
240
|
+
* })
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
function providePermissions(options) {
|
|
244
|
+
const { config, configFactory, deps, cerbosUrl } = options;
|
|
245
|
+
if ((config && configFactory) || (!config && !configFactory)) {
|
|
246
|
+
throw new Error('providePermissions: provide exactly one of `config` or `configFactory`');
|
|
247
|
+
}
|
|
248
|
+
const providers = [
|
|
249
|
+
config
|
|
250
|
+
? { provide: PERMISSIONS_CONFIG, useValue: config }
|
|
251
|
+
: { provide: PERMISSIONS_CONFIG, useFactory: configFactory, deps: deps ?? [] },
|
|
252
|
+
PermissionsService
|
|
253
|
+
];
|
|
254
|
+
if (cerbosUrl) {
|
|
255
|
+
providers.push(provideCerbos(cerbosUrl));
|
|
256
|
+
}
|
|
257
|
+
return providers;
|
|
258
|
+
}
|
|
259
|
+
|
|
226
260
|
/**
|
|
227
261
|
* Generated bundle index. Do not edit.
|
|
228
262
|
*/
|
|
229
263
|
|
|
230
|
-
export { PERMISSIONS_CONFIG, PermissionGateComponent, PermissionGateDirective, PermissionsModule, PermissionsService, providePermissionsConfig };
|
|
264
|
+
export { PERMISSIONS_CONFIG, PermissionGateComponent, PermissionGateDirective, PermissionsModule, PermissionsService, providePermissions, providePermissionsConfig };
|
|
231
265
|
//# sourceMappingURL=apipass-permissions.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apipass-permissions.mjs","sources":["../../../projects/permissions/src/permission-gate/permission-gate.component.ts","../../../projects/permissions/src/permission-gate/permission-gate.component.html","../../../projects/permissions/src/permission-gate/permission-gate.directive.ts","../../../projects/permissions/src/service/permissions.config.ts","../../../projects/permissions/src/service/permissions.service.ts","../../../projects/permissions/src/permissions.module.ts","../../../projects/permissions/src/apipass-permissions.ts"],"sourcesContent":["import { Component, ContentChild, Input, TemplateRef } from '@angular/core'\n\n/** Context object passed to the projected template — `$implicit` is the `allowed` flag. */\nexport interface PermissionGateContext {\n $implicit: boolean\n}\n\n/**\n * Angular equivalent of the React `PermissionGate`.\n *\n * It **never hides** the protected action: when blocked it still renders the\n * content, disabled, wrapped in a tooltip that explains why. The decision\n * (`isAllowed`) is supplied by the caller — this component only presents it.\n *\n * @example\n * ```html\n * <apipass-permission-gate [isAllowed]=\"canCreate\" [noAccessLabel]=\"'PERMISSIONS.NO_CREATE' | translate\">\n * <ng-template let-allowed>\n * <button mat-raised-button [disabled]=\"!allowed\" (click)=\"allowed && create()\">New</button>\n * </ng-template>\n * </apipass-permission-gate>\n * ```\n */\n@Component({\n selector: 'apipass-permission-gate',\n templateUrl: './permission-gate.component.html',\n styleUrls: ['./permission-gate.component.scss']\n})\nexport class PermissionGateComponent {\n\n /** Whether the gated action is allowed. */\n @Input() isAllowed = false\n\n /** Tooltip text shown when the action is blocked. */\n @Input() noAccessLabel = ''\n\n @ContentChild(TemplateRef) template?: TemplateRef<PermissionGateContext>\n\n}\n","<ng-container *ngIf=\"isAllowed; else blocked\">\n <ng-container *ngTemplateOutlet=\"template ?? null; context: { $implicit: true }\"></ng-container>\n</ng-container>\n\n<ng-template #blocked>\n <span\n class=\"permission-gate-blocked\"\n [matTooltip]=\"noAccessLabel\"\n [matTooltipDisabled]=\"!noAccessLabel\">\n <ng-container *ngTemplateOutlet=\"template ?? null; context: { $implicit: false }\"></ng-container>\n </span>\n</ng-template>\n","import { Directive, ElementRef, Input, OnChanges, Renderer2 } from '@angular/core'\n\n/**\n * Lightweight, dependency-free variant of {@link PermissionGateComponent} for\n * **native** elements (e.g. `<button>`, `<a>`). When blocked it sets the\n * `disabled` attribute, a `.permission-blocked` class and a native `title`\n * tooltip — the element stays in the DOM, never hidden.\n *\n * For Angular Material controls (`mat-button`, etc.) prefer the component, since\n * Material reads its own `disabled` @Input rather than the DOM attribute.\n *\n * @example\n * ```html\n * <button [apipassPermissionGate]=\"canCreate\" noAccessLabel=\"No permission\" (click)=\"create()\">New</button>\n * ```\n */\n@Directive({\n selector: '[apipassPermissionGate]'\n})\nexport class PermissionGateDirective implements OnChanges {\n\n /** Whether the gated action is allowed. */\n @Input('apipassPermissionGate') isAllowed = false\n\n /** Native tooltip text shown when the action is blocked. */\n @Input() noAccessLabel = ''\n\n constructor(\n private readonly el: ElementRef<HTMLElement>,\n private readonly renderer: Renderer2\n ) {}\n\n ngOnChanges(): void {\n const node = this.el.nativeElement\n if (this.isAllowed) {\n this.renderer.removeAttribute(node, 'disabled')\n this.renderer.removeAttribute(node, 'title')\n this.renderer.removeClass(node, 'permission-blocked')\n return\n }\n this.renderer.setAttribute(node, 'disabled', 'true')\n this.renderer.addClass(node, 'permission-blocked')\n if (this.noAccessLabel) {\n this.renderer.setAttribute(node, 'title', this.noAccessLabel)\n } else {\n this.renderer.removeAttribute(node, 'title')\n }\n }\n\n}\n","import { InjectionToken, Provider } from '@angular/core'\nimport { UserInfo } from '@apipass/frontend-utils'\n\nexport type MaybeAsync<T> = T | Promise<T>\n\n/** A single `{ kind, action }` pair handed to the legacy resolver. */\nexport interface LegacyCheck {\n kind: string\n action: string\n}\n\n/**\n * Per-application configuration for {@link PermissionsService}.\n *\n * The library is decoupled from any concrete app: each consumer wires in how to\n * read the Cerbos toggle, how to build the Cerbos principal, and how to resolve\n * the legacy (pre-Cerbos) decision.\n */\nexport interface PermissionsConfig {\n /** Whether Cerbos authorization is active. When `false`, only `legacyResolver` runs. */\n cerbosEnabled(): MaybeAsync<boolean>\n /** Builds the Cerbos principal (`{ accountId, domain, roles }`). Only called when Cerbos is enabled. */\n userInfo(): MaybeAsync<UserInfo>\n /**\n * Resolves a single check using the legacy role model. Only called when Cerbos is disabled.\n * `context` is the `legacyContext` carried by the originating {@link PermissionCheck}.\n */\n legacyResolver(check: LegacyCheck, context?: unknown): MaybeAsync<boolean>\n}\n\nexport const PERMISSIONS_CONFIG = new InjectionToken<PermissionsConfig>('PERMISSIONS_CONFIG')\n\n/** Registers the {@link PermissionsConfig} used by {@link PermissionsService}. */\nexport function providePermissionsConfig(config: PermissionsConfig): Provider {\n return { provide: PERMISSIONS_CONFIG, useValue: config }\n}\n","import { Inject, Injectable, Optional } from '@angular/core'\nimport { CERBOS_SERVICE, ICerbosService } from '@apipass/frontend-utils'\nimport { PERMISSIONS_CONFIG, PermissionsConfig } from './permissions.config'\nimport { PermissionCheck } from '../model/permission-check.interface'\nimport { PermissionResult, PermissionResultMap } from '../model/permission-result.interface'\n\ntype DecisionMap = Record<string, Record<string, boolean>>\n\n/**\n * Hybrid authorization orchestrator: decides between Cerbos and the legacy role\n * model based on {@link PermissionsConfig.cerbosEnabled}.\n *\n * - **Cerbos disabled** → behavior is identical to the pre-Cerbos system (legacy resolver).\n * - **Cerbos enabled** → asks the PDP; on any failure it is **fail-closed** (every action denied),\n * so a PDP outage never silently grants access.\n */\n@Injectable()\nexport class PermissionsService {\n\n constructor(\n @Inject(PERMISSIONS_CONFIG) private readonly config: PermissionsConfig,\n @Optional() @Inject(CERBOS_SERVICE) private readonly cerbos: ICerbosService | null\n ) {}\n\n /** Evaluates several resource kinds at once. With Cerbos enabled this is a single round-trip. */\n async checkResources(checks: PermissionCheck[]): Promise<PermissionResultMap> {\n const cerbosEnabled = await this.config.cerbosEnabled()\n const decisions = cerbosEnabled\n ? await this.resolveWithCerbos(checks)\n : await this.resolveWithLegacy(checks)\n return this.buildResultMap(decisions)\n }\n\n /** Convenience for the common single-kind case. */\n async checkResource(check: PermissionCheck): Promise<PermissionResult> {\n const map = await this.checkResources([check])\n return map.for(check.kind)\n }\n\n private async resolveWithCerbos(checks: PermissionCheck[]): Promise<DecisionMap> {\n // Fail-closed: no PDP wired in means no grants.\n if (!this.cerbos) {\n console.error(`${PermissionsService.name} - CERBOS_SERVICE not provided; denying all (fail-closed)`)\n return this.denyAll(checks)\n }\n try {\n const userInfo = await this.config.userInfo()\n return await this.cerbos.checkResources(\n userInfo,\n checks.map(({ kind, actions, id }) => ({ kind, actions, id }))\n )\n } catch (e) {\n console.error(`${PermissionsService.name} - Cerbos check failed; denying all (fail-closed)`, e)\n return this.denyAll(checks)\n }\n }\n\n private async resolveWithLegacy(checks: PermissionCheck[]): Promise<DecisionMap> {\n const decisions: DecisionMap = {}\n for (const check of checks) {\n const actions: Record<string, boolean> = {}\n for (const action of check.actions) {\n actions[action] = await this.config.legacyResolver({ kind: check.kind, action }, check.legacyContext)\n }\n decisions[check.kind] = actions\n }\n return decisions\n }\n\n private denyAll(checks: PermissionCheck[]): DecisionMap {\n return checks.reduce<DecisionMap>((acc, check) => {\n acc[check.kind] = check.actions.reduce<Record<string, boolean>>((actions, action) => {\n actions[action] = false\n return actions\n }, {})\n return acc\n }, {})\n }\n\n private buildResultMap(decisions: DecisionMap): PermissionResultMap {\n const can = (kind: string, action: string): boolean => decisions[kind]?.[action] ?? false\n return {\n can,\n for: (kind: string): PermissionResult => ({ can: (action: string) => can(kind, action) })\n }\n }\n\n}\n","import { NgModule } from '@angular/core'\nimport { CommonModule } from '@angular/common'\nimport { MatTooltipModule } from '@angular/material/tooltip'\nimport { PermissionGateComponent } from './permission-gate/permission-gate.component'\nimport { PermissionGateDirective } from './permission-gate/permission-gate.directive'\nimport { PermissionsService } from './service/permissions.service'\n\n@NgModule({\n imports: [\n CommonModule,\n MatTooltipModule\n ],\n declarations: [\n PermissionGateComponent,\n PermissionGateDirective\n ],\n exports: [\n PermissionGateComponent,\n PermissionGateDirective\n ],\n providers: [\n PermissionsService\n ]\n})\nexport class PermissionsModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;;AAOA;;;;;;;;;;;;;;;AAeG;AACH,MAKa,uBAAuB,CAAA;;IAGzB,SAAS,GAAG,KAAK,CAAA;;IAGjB,aAAa,GAAG,EAAE,CAAA;AAEA,IAAA,QAAQ,CAAqC;uGAR7D,uBAAuB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA,CAAA;2FAAvB,uBAAuB,EAAA,QAAA,EAAA,yBAAA,EAAA,MAAA,EAAA,EAAA,SAAA,EAAA,WAAA,EAAA,aAAA,EAAA,eAAA,EAAA,EAAA,OAAA,EAAA,CAAA,EAAA,YAAA,EAAA,UAAA,EAAA,KAAA,EAAA,IAAA,EAAA,SAAA,EAQpB,WAAW,EAAA,WAAA,EAAA,IAAA,EAAA,CAAA,EAAA,QAAA,EAAA,EAAA,EAAA,QAAA,ECpC3B,2cAYA,EAAA,MAAA,EAAA,CAAA,oEAAA,CAAA,EAAA,YAAA,EAAA,CAAA,EAAA,IAAA,EAAA,WAAA,EAAA,IAAA,EAAA,EAAA,CAAA,IAAA,EAAA,QAAA,EAAA,QAAA,EAAA,MAAA,EAAA,CAAA,MAAA,EAAA,UAAA,EAAA,UAAA,CAAA,EAAA,EAAA,EAAA,IAAA,EAAA,WAAA,EAAA,IAAA,EAAA,EAAA,CAAA,gBAAA,EAAA,QAAA,EAAA,oBAAA,EAAA,MAAA,EAAA,CAAA,yBAAA,EAAA,kBAAA,EAAA,0BAAA,CAAA,EAAA,EAAA,EAAA,IAAA,EAAA,WAAA,EAAA,IAAA,EAAA,EAAA,CAAA,UAAA,EAAA,QAAA,EAAA,cAAA,EAAA,QAAA,EAAA,CAAA,YAAA,CAAA,EAAA,CAAA,EAAA,CAAA,CAAA;;2FDgBa,uBAAuB,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BACP,YAAY;wBACZ,gBAAgB;AACjB,qBAAA;AACD,oBAAA,YAAY,EAAE;wBACZ,uBAAuB;wBACvB,uBAAuB;AACxB,qBAAA;AACD,oBAAA,OAAO,EAAE;wBACP,uBAAuB;wBACvB,uBAAuB;AACxB,qBAAA;AACD,oBAAA,SAAS,EAAE;wBACT,kBAAkB;AACnB,qBAAA;AACF,iBAAA,CAAA;;;ACvBD;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"apipass-permissions.mjs","sources":["../../../projects/permissions/src/permission-gate/permission-gate.component.ts","../../../projects/permissions/src/permission-gate/permission-gate.component.html","../../../projects/permissions/src/permission-gate/permission-gate.directive.ts","../../../projects/permissions/src/service/permissions.config.ts","../../../projects/permissions/src/service/permissions.service.ts","../../../projects/permissions/src/permissions.module.ts","../../../projects/permissions/src/service/permissions.providers.ts","../../../projects/permissions/src/apipass-permissions.ts"],"sourcesContent":["import { Component, ContentChild, Input, TemplateRef } from '@angular/core'\n\n/** Context object passed to the projected template — `$implicit` is the `allowed` flag. */\nexport interface PermissionGateContext {\n $implicit: boolean\n}\n\n/**\n * Angular equivalent of the React `PermissionGate`.\n *\n * It **never hides** the protected action: when blocked it still renders the\n * content, disabled, wrapped in a tooltip that explains why. The decision\n * (`isAllowed`) is supplied by the caller — this component only presents it.\n *\n * @example\n * ```html\n * <apipass-permission-gate [isAllowed]=\"canCreate\" [noAccessLabel]=\"'PERMISSIONS.NO_CREATE' | translate\">\n * <ng-template let-allowed>\n * <button mat-raised-button [disabled]=\"!allowed\" (click)=\"allowed && create()\">New</button>\n * </ng-template>\n * </apipass-permission-gate>\n * ```\n */\n@Component({\n selector: 'apipass-permission-gate',\n templateUrl: './permission-gate.component.html',\n styleUrls: ['./permission-gate.component.scss']\n})\nexport class PermissionGateComponent {\n\n /** Whether the gated action is allowed. */\n @Input() isAllowed = false\n\n /** Tooltip text shown when the action is blocked. */\n @Input() noAccessLabel = ''\n\n @ContentChild(TemplateRef) template?: TemplateRef<PermissionGateContext>\n\n}\n","<ng-container *ngIf=\"isAllowed; else blocked\">\n <ng-container *ngTemplateOutlet=\"template ?? null; context: { $implicit: true }\"></ng-container>\n</ng-container>\n\n<ng-template #blocked>\n <span\n class=\"permission-gate-blocked\"\n [matTooltip]=\"noAccessLabel\"\n [matTooltipDisabled]=\"!noAccessLabel\">\n <ng-container *ngTemplateOutlet=\"template ?? null; context: { $implicit: false }\"></ng-container>\n </span>\n</ng-template>\n","import { Directive, ElementRef, Input, OnChanges, Renderer2 } from '@angular/core'\n\n/**\n * Lightweight, dependency-free variant of {@link PermissionGateComponent} for\n * **native** elements (e.g. `<button>`, `<a>`). When blocked it sets the\n * `disabled` attribute, a `.permission-blocked` class and a native `title`\n * tooltip — the element stays in the DOM, never hidden.\n *\n * For Angular Material controls (`mat-button`, etc.) prefer the component, since\n * Material reads its own `disabled` @Input rather than the DOM attribute.\n *\n * @example\n * ```html\n * <button [apipassPermissionGate]=\"canCreate\" noAccessLabel=\"No permission\" (click)=\"create()\">New</button>\n * ```\n */\n@Directive({\n selector: '[apipassPermissionGate]'\n})\nexport class PermissionGateDirective implements OnChanges {\n\n /** Whether the gated action is allowed. */\n @Input('apipassPermissionGate') isAllowed = false\n\n /** Native tooltip text shown when the action is blocked. */\n @Input() noAccessLabel = ''\n\n constructor(\n private readonly el: ElementRef<HTMLElement>,\n private readonly renderer: Renderer2\n ) {}\n\n ngOnChanges(): void {\n const node = this.el.nativeElement\n if (this.isAllowed) {\n this.renderer.removeAttribute(node, 'disabled')\n this.renderer.removeAttribute(node, 'title')\n this.renderer.removeClass(node, 'permission-blocked')\n return\n }\n this.renderer.setAttribute(node, 'disabled', 'true')\n this.renderer.addClass(node, 'permission-blocked')\n if (this.noAccessLabel) {\n this.renderer.setAttribute(node, 'title', this.noAccessLabel)\n } else {\n this.renderer.removeAttribute(node, 'title')\n }\n }\n\n}\n","import { InjectionToken, Provider } from '@angular/core'\nimport { UserInfo } from '@apipass/frontend-utils'\n\nexport type MaybeAsync<T> = T | Promise<T>\n\n/** A single `{ kind, action }` pair handed to the legacy resolver. */\nexport interface LegacyCheck {\n kind: string\n action: string\n}\n\n/**\n * Per-application configuration for {@link PermissionsService}.\n *\n * The library is decoupled from any concrete app: each consumer wires in how to\n * read the Cerbos toggle, how to build the Cerbos principal, and how to resolve\n * the legacy (pre-Cerbos) decision.\n */\nexport interface PermissionsConfig {\n /** Whether Cerbos authorization is active. When `false`, only `legacyResolver` runs. */\n cerbosEnabled(): MaybeAsync<boolean>\n /** Builds the Cerbos principal (`{ accountId, domain, roles }`). Only called when Cerbos is enabled. */\n userInfo(): MaybeAsync<UserInfo>\n /**\n * Resolves a single check using the legacy role model. Only called when Cerbos is disabled.\n * `context` is the `legacyContext` carried by the originating {@link PermissionCheck}.\n */\n legacyResolver(check: LegacyCheck, context?: unknown): MaybeAsync<boolean>\n}\n\nexport const PERMISSIONS_CONFIG = new InjectionToken<PermissionsConfig>('PERMISSIONS_CONFIG')\n\n/** Registers the {@link PermissionsConfig} used by {@link PermissionsService}. */\nexport function providePermissionsConfig(config: PermissionsConfig): Provider {\n return { provide: PERMISSIONS_CONFIG, useValue: config }\n}\n","import { Inject, Injectable, Optional } from '@angular/core'\nimport { CERBOS_SERVICE, ICerbosService } from '@apipass/frontend-utils'\nimport { PERMISSIONS_CONFIG, PermissionsConfig } from './permissions.config'\nimport { PermissionCheck } from '../model/permission-check.interface'\nimport { PermissionResult, PermissionResultMap } from '../model/permission-result.interface'\n\ntype DecisionMap = Record<string, Record<string, boolean>>\n\n/**\n * Hybrid authorization orchestrator: decides between Cerbos and the legacy role\n * model based on {@link PermissionsConfig.cerbosEnabled}.\n *\n * - **Cerbos disabled** → behavior is identical to the pre-Cerbos system (legacy resolver).\n * - **Cerbos enabled** → asks the PDP; on any failure it is **fail-closed** (every action denied),\n * so a PDP outage never silently grants access.\n */\n@Injectable()\nexport class PermissionsService {\n\n constructor(\n @Inject(PERMISSIONS_CONFIG) private readonly config: PermissionsConfig,\n @Optional() @Inject(CERBOS_SERVICE) private readonly cerbos: ICerbosService | null\n ) {}\n\n /** Evaluates several resource kinds at once. With Cerbos enabled this is a single round-trip. */\n async checkResources(checks: PermissionCheck[]): Promise<PermissionResultMap> {\n const cerbosEnabled = await this.config.cerbosEnabled()\n const decisions = cerbosEnabled\n ? await this.resolveWithCerbos(checks)\n : await this.resolveWithLegacy(checks)\n return this.buildResultMap(decisions)\n }\n\n /** Convenience for the common single-kind case. */\n async checkResource(check: PermissionCheck): Promise<PermissionResult> {\n const map = await this.checkResources([check])\n return map.for(check.kind)\n }\n\n private async resolveWithCerbos(checks: PermissionCheck[]): Promise<DecisionMap> {\n // Fail-closed: no PDP wired in means no grants.\n if (!this.cerbos) {\n console.error(`${PermissionsService.name} - CERBOS_SERVICE not provided; denying all (fail-closed)`)\n return this.denyAll(checks)\n }\n try {\n const userInfo = await this.config.userInfo()\n return await this.cerbos.checkResources(\n userInfo,\n checks.map(({ kind, actions, id }) => ({ kind, actions, id }))\n )\n } catch (e) {\n console.error(`${PermissionsService.name} - Cerbos check failed; denying all (fail-closed)`, e)\n return this.denyAll(checks)\n }\n }\n\n private async resolveWithLegacy(checks: PermissionCheck[]): Promise<DecisionMap> {\n const decisions: DecisionMap = {}\n for (const check of checks) {\n const actions: Record<string, boolean> = {}\n for (const action of check.actions) {\n actions[action] = await this.config.legacyResolver({ kind: check.kind, action }, check.legacyContext)\n }\n decisions[check.kind] = actions\n }\n return decisions\n }\n\n private denyAll(checks: PermissionCheck[]): DecisionMap {\n return checks.reduce<DecisionMap>((acc, check) => {\n acc[check.kind] = check.actions.reduce<Record<string, boolean>>((actions, action) => {\n actions[action] = false\n return actions\n }, {})\n return acc\n }, {})\n }\n\n private buildResultMap(decisions: DecisionMap): PermissionResultMap {\n const can = (kind: string, action: string): boolean => decisions[kind]?.[action] ?? false\n return {\n can,\n for: (kind: string): PermissionResult => ({ can: (action: string) => can(kind, action) })\n }\n }\n\n}\n","import { NgModule } from '@angular/core'\nimport { CommonModule } from '@angular/common'\nimport { MatTooltipModule } from '@angular/material/tooltip'\nimport { PermissionGateComponent } from './permission-gate/permission-gate.component'\nimport { PermissionGateDirective } from './permission-gate/permission-gate.directive'\nimport { PermissionsService } from './service/permissions.service'\n\n@NgModule({\n imports: [\n CommonModule,\n MatTooltipModule\n ],\n declarations: [\n PermissionGateComponent,\n PermissionGateDirective\n ],\n exports: [\n PermissionGateComponent,\n PermissionGateDirective\n ],\n providers: [\n PermissionsService\n ]\n})\nexport class PermissionsModule {}\n","import { Provider } from '@angular/core'\nimport { provideCerbos } from '@apipass/frontend-utils'\nimport { PERMISSIONS_CONFIG, PermissionsConfig } from './permissions.config'\nimport { PermissionsService } from './permissions.service'\n\nexport interface ProvidePermissionsOptions {\n /** Static config (registered with `useValue`). Mutually exclusive with `configFactory`. */\n config?: PermissionsConfig\n /** Config factory with DI (registered with `useFactory`). Mutually exclusive with `config`. */\n configFactory?: (...deps: never[]) => PermissionsConfig\n /** Injection tokens passed to `configFactory`, in parameter order. */\n deps?: unknown[]\n /** Optional Cerbos PDP url; when set, also registers `CERBOS_SERVICE` via `provideCerbos`. */\n cerbosUrl?: string\n}\n\n/**\n * One-call setup for `@apipass/permissions`: registers the {@link PERMISSIONS_CONFIG},\n * the {@link PermissionsService} and (optionally) the Cerbos service.\n *\n * @example\n * ```ts\n * @NgModule({\n * providers: [\n * providePermissions({\n * cerbosUrl: $ENV.CERBOS_PDP_URL,\n * configFactory: permissionsConfigFactory,\n * deps: [FEATURE_TOGGLE_SERVICE, IAM_SERVICE]\n * })\n * ]\n * })\n * ```\n */\nexport function providePermissions(options: ProvidePermissionsOptions): Provider[] {\n const { config, configFactory, deps, cerbosUrl } = options\n\n if ((config && configFactory) || (!config && !configFactory)) {\n throw new Error('providePermissions: provide exactly one of `config` or `configFactory`')\n }\n\n const providers: Provider[] = [\n config\n ? { provide: PERMISSIONS_CONFIG, useValue: config }\n : { provide: PERMISSIONS_CONFIG, useFactory: configFactory, deps: deps ?? [] },\n PermissionsService\n ]\n\n if (cerbosUrl) {\n providers.push(provideCerbos(cerbosUrl))\n }\n\n return providers\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;;AAOA;;;;;;;;;;;;;;;AAeG;AACH,MAKa,uBAAuB,CAAA;;IAGzB,SAAS,GAAG,KAAK,CAAA;;IAGjB,aAAa,GAAG,EAAE,CAAA;AAEA,IAAA,QAAQ,CAAqC;uGAR7D,uBAAuB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA,CAAA;2FAAvB,uBAAuB,EAAA,QAAA,EAAA,yBAAA,EAAA,MAAA,EAAA,EAAA,SAAA,EAAA,WAAA,EAAA,aAAA,EAAA,eAAA,EAAA,EAAA,OAAA,EAAA,CAAA,EAAA,YAAA,EAAA,UAAA,EAAA,KAAA,EAAA,IAAA,EAAA,SAAA,EAQpB,WAAW,EAAA,WAAA,EAAA,IAAA,EAAA,CAAA,EAAA,QAAA,EAAA,EAAA,EAAA,QAAA,ECpC3B,2cAYA,EAAA,MAAA,EAAA,CAAA,oEAAA,CAAA,EAAA,YAAA,EAAA,CAAA,EAAA,IAAA,EAAA,WAAA,EAAA,IAAA,EAAA,EAAA,CAAA,IAAA,EAAA,QAAA,EAAA,QAAA,EAAA,MAAA,EAAA,CAAA,MAAA,EAAA,UAAA,EAAA,UAAA,CAAA,EAAA,EAAA,EAAA,IAAA,EAAA,WAAA,EAAA,IAAA,EAAA,EAAA,CAAA,gBAAA,EAAA,QAAA,EAAA,oBAAA,EAAA,MAAA,EAAA,CAAA,yBAAA,EAAA,kBAAA,EAAA,0BAAA,CAAA,EAAA,EAAA,EAAA,IAAA,EAAA,WAAA,EAAA,IAAA,EAAA,EAAA,CAAA,UAAA,EAAA,QAAA,EAAA,cAAA,EAAA,QAAA,EAAA,CAAA,YAAA,CAAA,EAAA,CAAA,EAAA,CAAA,CAAA;;2FDgBa,uBAAuB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wBACP,YAAY;wBACZ,gBAAgB;AACjB,qBAAA;AACD,oBAAA,YAAY,EAAE;wBACZ,uBAAuB;wBACvB,uBAAuB;AACxB,qBAAA;AACD,oBAAA,OAAO,EAAE;wBACP,uBAAuB;wBACvB,uBAAuB;AACxB,qBAAA;AACD,oBAAA,SAAS,EAAE;wBACT,kBAAkB;AACnB,qBAAA;AACF,iBAAA,CAAA;;;ACPD;;;;;;;;;;;;;;;;AAgBG;AACG,SAAU,kBAAkB,CAAC,OAAkC,EAAA;IACnE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,OAAO,CAAA;AAE1D,IAAA,IAAI,CAAC,MAAM,IAAI,aAAa,MAAM,CAAC,MAAM,IAAI,CAAC,aAAa,CAAC,EAAE;AAC5D,QAAA,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAA;AAC1F,KAAA;AAED,IAAA,MAAM,SAAS,GAAe;QAC5B,MAAM;cACF,EAAE,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,EAAE;AACnD,cAAE,EAAE,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,aAAa,EAAE,IAAI,EAAE,IAAI,IAAI,EAAE,EAAE;QAChF,kBAAkB;KACnB,CAAA;AAED,IAAA,IAAI,SAAS,EAAE;QACb,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAA;AACzC,KAAA;AAED,IAAA,OAAO,SAAS,CAAA;AAClB;;ACpDA;;AAEG;;;;"}
|
package/package.json
CHANGED
package/public-api.d.ts
CHANGED
|
@@ -3,5 +3,6 @@ export * from './permission-gate/permission-gate.component';
|
|
|
3
3
|
export * from './permission-gate/permission-gate.directive';
|
|
4
4
|
export * from './service/permissions.service';
|
|
5
5
|
export * from './service/permissions.config';
|
|
6
|
+
export * from './service/permissions.providers';
|
|
6
7
|
export * from './model/permission-check.interface';
|
|
7
8
|
export * from './model/permission-result.interface';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Provider } from '@angular/core';
|
|
2
|
+
import { PermissionsConfig } from './permissions.config';
|
|
3
|
+
export interface ProvidePermissionsOptions {
|
|
4
|
+
/** Static config (registered with `useValue`). Mutually exclusive with `configFactory`. */
|
|
5
|
+
config?: PermissionsConfig;
|
|
6
|
+
/** Config factory with DI (registered with `useFactory`). Mutually exclusive with `config`. */
|
|
7
|
+
configFactory?: (...deps: never[]) => PermissionsConfig;
|
|
8
|
+
/** Injection tokens passed to `configFactory`, in parameter order. */
|
|
9
|
+
deps?: unknown[];
|
|
10
|
+
/** Optional Cerbos PDP url; when set, also registers `CERBOS_SERVICE` via `provideCerbos`. */
|
|
11
|
+
cerbosUrl?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* One-call setup for `@apipass/permissions`: registers the {@link PERMISSIONS_CONFIG},
|
|
15
|
+
* the {@link PermissionsService} and (optionally) the Cerbos service.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* @NgModule({
|
|
20
|
+
* providers: [
|
|
21
|
+
* providePermissions({
|
|
22
|
+
* cerbosUrl: $ENV.CERBOS_PDP_URL,
|
|
23
|
+
* configFactory: permissionsConfigFactory,
|
|
24
|
+
* deps: [FEATURE_TOGGLE_SERVICE, IAM_SERVICE]
|
|
25
|
+
* })
|
|
26
|
+
* ]
|
|
27
|
+
* })
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function providePermissions(options: ProvidePermissionsOptions): Provider[];
|