@astram/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +47 -0
- package/dist/admin/admin-service.d.ts +221 -0
- package/dist/admin/admin-service.d.ts.map +1 -0
- package/dist/admin/admin-service.js +155 -0
- package/dist/admin/admin-service.js.map +1 -0
- package/dist/admin/command/grants.d.ts +40 -0
- package/dist/admin/command/grants.d.ts.map +1 -0
- package/dist/admin/command/grants.js +196 -0
- package/dist/admin/command/grants.js.map +1 -0
- package/dist/admin/command/index.d.ts +23 -0
- package/dist/admin/command/index.d.ts.map +1 -0
- package/dist/admin/command/index.js +23 -0
- package/dist/admin/command/index.js.map +1 -0
- package/dist/admin/command/invitations.d.ts +72 -0
- package/dist/admin/command/invitations.d.ts.map +1 -0
- package/dist/admin/command/invitations.js +241 -0
- package/dist/admin/command/invitations.js.map +1 -0
- package/dist/admin/command/permissions.d.ts +33 -0
- package/dist/admin/command/permissions.d.ts.map +1 -0
- package/dist/admin/command/permissions.js +67 -0
- package/dist/admin/command/permissions.js.map +1 -0
- package/dist/admin/command/pipeline.d.ts +79 -0
- package/dist/admin/command/pipeline.d.ts.map +1 -0
- package/dist/admin/command/pipeline.js +106 -0
- package/dist/admin/command/pipeline.js.map +1 -0
- package/dist/admin/command/policies.d.ts +50 -0
- package/dist/admin/command/policies.d.ts.map +1 -0
- package/dist/admin/command/policies.js +219 -0
- package/dist/admin/command/policies.js.map +1 -0
- package/dist/admin/command/service-accounts.d.ts +58 -0
- package/dist/admin/command/service-accounts.d.ts.map +1 -0
- package/dist/admin/command/service-accounts.js +272 -0
- package/dist/admin/command/service-accounts.js.map +1 -0
- package/dist/admin/command/service.d.ts +65 -0
- package/dist/admin/command/service.d.ts.map +1 -0
- package/dist/admin/command/service.js +128 -0
- package/dist/admin/command/service.js.map +1 -0
- package/dist/admin/command/tiers.d.ts +40 -0
- package/dist/admin/command/tiers.d.ts.map +1 -0
- package/dist/admin/command/tiers.js +79 -0
- package/dist/admin/command/tiers.js.map +1 -0
- package/dist/admin/index.d.ts +36 -0
- package/dist/admin/index.d.ts.map +1 -0
- package/dist/admin/index.js +63 -0
- package/dist/admin/index.js.map +1 -0
- package/dist/admin/ports.d.ts +288 -0
- package/dist/admin/ports.d.ts.map +1 -0
- package/dist/admin/ports.js +39 -0
- package/dist/admin/ports.js.map +1 -0
- package/dist/admin/query/audit-view.d.ts +52 -0
- package/dist/admin/query/audit-view.d.ts.map +1 -0
- package/dist/admin/query/audit-view.js +84 -0
- package/dist/admin/query/audit-view.js.map +1 -0
- package/dist/admin/query/catalog.d.ts +70 -0
- package/dist/admin/query/catalog.d.ts.map +1 -0
- package/dist/admin/query/catalog.js +169 -0
- package/dist/admin/query/catalog.js.map +1 -0
- package/dist/admin/query/explain.d.ts +52 -0
- package/dist/admin/query/explain.d.ts.map +1 -0
- package/dist/admin/query/explain.js +145 -0
- package/dist/admin/query/explain.js.map +1 -0
- package/dist/admin/query/index.d.ts +45 -0
- package/dist/admin/query/index.d.ts.map +1 -0
- package/dist/admin/query/index.js +58 -0
- package/dist/admin/query/index.js.map +1 -0
- package/dist/admin/query/simulate.d.ts +42 -0
- package/dist/admin/query/simulate.d.ts.map +1 -0
- package/dist/admin/query/simulate.js +91 -0
- package/dist/admin/query/simulate.js.map +1 -0
- package/dist/admin/safeguards-impl.d.ts +67 -0
- package/dist/admin/safeguards-impl.d.ts.map +1 -0
- package/dist/admin/safeguards-impl.js +318 -0
- package/dist/admin/safeguards-impl.js.map +1 -0
- package/dist/admin/safeguards.d.ts +89 -0
- package/dist/admin/safeguards.d.ts.map +1 -0
- package/dist/admin/safeguards.js +91 -0
- package/dist/admin/safeguards.js.map +1 -0
- package/dist/admin/types.d.ts +485 -0
- package/dist/admin/types.d.ts.map +1 -0
- package/dist/admin/types.js +38 -0
- package/dist/admin/types.js.map +1 -0
- package/dist/audit/audit-recorder.d.ts +129 -0
- package/dist/audit/audit-recorder.d.ts.map +1 -0
- package/dist/audit/audit-recorder.js +265 -0
- package/dist/audit/audit-recorder.js.map +1 -0
- package/dist/audit/canonicalize.d.ts +38 -0
- package/dist/audit/canonicalize.d.ts.map +1 -0
- package/dist/audit/canonicalize.js +174 -0
- package/dist/audit/canonicalize.js.map +1 -0
- package/dist/audit/errors.d.ts +56 -0
- package/dist/audit/errors.d.ts.map +1 -0
- package/dist/audit/errors.js +41 -0
- package/dist/audit/errors.js.map +1 -0
- package/dist/audit/index.d.ts +45 -0
- package/dist/audit/index.d.ts.map +1 -0
- package/dist/audit/index.js +24 -0
- package/dist/audit/index.js.map +1 -0
- package/dist/audit/ports.d.ts +131 -0
- package/dist/audit/ports.d.ts.map +1 -0
- package/dist/audit/ports.js +27 -0
- package/dist/audit/ports.js.map +1 -0
- package/dist/audit/sensitive.d.ts +68 -0
- package/dist/audit/sensitive.d.ts.map +1 -0
- package/dist/audit/sensitive.js +159 -0
- package/dist/audit/sensitive.js.map +1 -0
- package/dist/audit/walk.d.ts +109 -0
- package/dist/audit/walk.d.ts.map +1 -0
- package/dist/audit/walk.js +117 -0
- package/dist/audit/walk.js.map +1 -0
- package/dist/authentication/authenticator.d.ts +74 -0
- package/dist/authentication/authenticator.d.ts.map +1 -0
- package/dist/authentication/authenticator.js +208 -0
- package/dist/authentication/authenticator.js.map +1 -0
- package/dist/authentication/credential-resolver.d.ts +76 -0
- package/dist/authentication/credential-resolver.d.ts.map +1 -0
- package/dist/authentication/credential-resolver.js +21 -0
- package/dist/authentication/credential-resolver.js.map +1 -0
- package/dist/authentication/index.d.ts +52 -0
- package/dist/authentication/index.d.ts.map +1 -0
- package/dist/authentication/index.js +27 -0
- package/dist/authentication/index.js.map +1 -0
- package/dist/authentication/password-hasher.d.ts +41 -0
- package/dist/authentication/password-hasher.d.ts.map +1 -0
- package/dist/authentication/password-hasher.js +21 -0
- package/dist/authentication/password-hasher.js.map +1 -0
- package/dist/authentication/totp.d.ts +101 -0
- package/dist/authentication/totp.d.ts.map +1 -0
- package/dist/authentication/totp.js +151 -0
- package/dist/authentication/totp.js.map +1 -0
- package/dist/authorization/cross-tenant/grant-evaluator.d.ts +90 -0
- package/dist/authorization/cross-tenant/grant-evaluator.d.ts.map +1 -0
- package/dist/authorization/cross-tenant/grant-evaluator.js +165 -0
- package/dist/authorization/cross-tenant/grant-evaluator.js.map +1 -0
- package/dist/authorization/decision-authority.d.ts +212 -0
- package/dist/authorization/decision-authority.d.ts.map +1 -0
- package/dist/authorization/decision-authority.js +200 -0
- package/dist/authorization/decision-authority.js.map +1 -0
- package/dist/authorization/default-gates.d.ts +41 -0
- package/dist/authorization/default-gates.d.ts.map +1 -0
- package/dist/authorization/default-gates.js +47 -0
- package/dist/authorization/default-gates.js.map +1 -0
- package/dist/authorization/delegation/operation-identity.d.ts +132 -0
- package/dist/authorization/delegation/operation-identity.d.ts.map +1 -0
- package/dist/authorization/delegation/operation-identity.js +220 -0
- package/dist/authorization/delegation/operation-identity.js.map +1 -0
- package/dist/authorization/errors.d.ts +54 -0
- package/dist/authorization/errors.d.ts.map +1 -0
- package/dist/authorization/errors.js +63 -0
- package/dist/authorization/errors.js.map +1 -0
- package/dist/authorization/gates/object-type.d.ts +63 -0
- package/dist/authorization/gates/object-type.d.ts.map +1 -0
- package/dist/authorization/gates/object-type.js +177 -0
- package/dist/authorization/gates/object-type.js.map +1 -0
- package/dist/authorization/gates/tenant.d.ts +50 -0
- package/dist/authorization/gates/tenant.d.ts.map +1 -0
- package/dist/authorization/gates/tenant.js +87 -0
- package/dist/authorization/gates/tenant.js.map +1 -0
- package/dist/authorization/gates/wiring.d.ts +57 -0
- package/dist/authorization/gates/wiring.d.ts.map +1 -0
- package/dist/authorization/gates/wiring.js +56 -0
- package/dist/authorization/gates/wiring.js.map +1 -0
- package/dist/authorization/index.d.ts +136 -0
- package/dist/authorization/index.d.ts.map +1 -0
- package/dist/authorization/index.js +82 -0
- package/dist/authorization/index.js.map +1 -0
- package/dist/authorization/ports.d.ts +271 -0
- package/dist/authorization/ports.d.ts.map +1 -0
- package/dist/authorization/ports.js +36 -0
- package/dist/authorization/ports.js.map +1 -0
- package/dist/authorization/reason-codes.d.ts +75 -0
- package/dist/authorization/reason-codes.d.ts.map +1 -0
- package/dist/authorization/reason-codes.js +98 -0
- package/dist/authorization/reason-codes.js.map +1 -0
- package/dist/authorization/record/permit-tier.d.ts +57 -0
- package/dist/authorization/record/permit-tier.d.ts.map +1 -0
- package/dist/authorization/record/permit-tier.js +79 -0
- package/dist/authorization/record/permit-tier.js.map +1 -0
- package/dist/authorization/record/rule-evaluator.d.ts +116 -0
- package/dist/authorization/record/rule-evaluator.d.ts.map +1 -0
- package/dist/authorization/record/rule-evaluator.js +125 -0
- package/dist/authorization/record/rule-evaluator.js.map +1 -0
- package/dist/authorization/record/shares.d.ts +70 -0
- package/dist/authorization/record/shares.d.ts.map +1 -0
- package/dist/authorization/record/shares.js +107 -0
- package/dist/authorization/record/shares.js.map +1 -0
- package/dist/identity/broker.d.ts +59 -0
- package/dist/identity/broker.d.ts.map +1 -0
- package/dist/identity/broker.js +135 -0
- package/dist/identity/broker.js.map +1 -0
- package/dist/identity/claim-mapper.d.ts +84 -0
- package/dist/identity/claim-mapper.d.ts.map +1 -0
- package/dist/identity/claim-mapper.js +48 -0
- package/dist/identity/claim-mapper.js.map +1 -0
- package/dist/identity/index.d.ts +60 -0
- package/dist/identity/index.d.ts.map +1 -0
- package/dist/identity/index.js +24 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/identity/internal-adapter.d.ts +54 -0
- package/dist/identity/internal-adapter.d.ts.map +1 -0
- package/dist/identity/internal-adapter.js +88 -0
- package/dist/identity/internal-adapter.js.map +1 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/dist/metadata/completeness.d.ts +136 -0
- package/dist/metadata/completeness.d.ts.map +1 -0
- package/dist/metadata/completeness.js +106 -0
- package/dist/metadata/completeness.js.map +1 -0
- package/dist/metadata/dependencies.d.ts +114 -0
- package/dist/metadata/dependencies.d.ts.map +1 -0
- package/dist/metadata/dependencies.js +105 -0
- package/dist/metadata/dependencies.js.map +1 -0
- package/dist/metadata/index.d.ts +153 -0
- package/dist/metadata/index.d.ts.map +1 -0
- package/dist/metadata/index.js +51 -0
- package/dist/metadata/index.js.map +1 -0
- package/dist/metadata/registry.d.ts +23 -0
- package/dist/metadata/registry.d.ts.map +1 -0
- package/dist/metadata/registry.js +204 -0
- package/dist/metadata/registry.js.map +1 -0
- package/dist/risk/evaluator.d.ts +76 -0
- package/dist/risk/evaluator.d.ts.map +1 -0
- package/dist/risk/evaluator.js +59 -0
- package/dist/risk/evaluator.js.map +1 -0
- package/dist/risk/index.d.ts +40 -0
- package/dist/risk/index.d.ts.map +1 -0
- package/dist/risk/index.js +20 -0
- package/dist/risk/index.js.map +1 -0
- package/dist/risk/risk-engine.d.ts +76 -0
- package/dist/risk/risk-engine.d.ts.map +1 -0
- package/dist/risk/risk-engine.js +287 -0
- package/dist/risk/risk-engine.js.map +1 -0
- package/dist/risk/signals.d.ts +60 -0
- package/dist/risk/signals.d.ts.map +1 -0
- package/dist/risk/signals.js +104 -0
- package/dist/risk/signals.js.map +1 -0
- package/dist/risk/thresholds.d.ts +54 -0
- package/dist/risk/thresholds.d.ts.map +1 -0
- package/dist/risk/thresholds.js +60 -0
- package/dist/risk/thresholds.js.map +1 -0
- package/dist/session/index.d.ts +47 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +20 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/lifetimes.d.ts +50 -0
- package/dist/session/lifetimes.d.ts.map +1 -0
- package/dist/session/lifetimes.js +67 -0
- package/dist/session/lifetimes.js.map +1 -0
- package/dist/session/ports.d.ts +266 -0
- package/dist/session/ports.d.ts.map +1 -0
- package/dist/session/ports.js +23 -0
- package/dist/session/ports.js.map +1 -0
- package/dist/session/session-authority.d.ts +97 -0
- package/dist/session/session-authority.d.ts.map +1 -0
- package/dist/session/session-authority.js +393 -0
- package/dist/session/session-authority.js.map +1 -0
- package/package.json +32 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Astram
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# @astram/core
|
|
2
|
+
|
|
3
|
+
The **framework-agnostic security Core** for Astram. Owned by the Core team
|
|
4
|
+
(STATUS layer 3, `010_Architecture`). Framework-agnostic per
|
|
5
|
+
[ADR-0003](../../docs/Shield/ADR/0003-framework-agnostic-core.md) — **ZERO
|
|
6
|
+
NestJS / React / Express / Vite imports** (enforced by the root ESLint boundary rule).
|
|
7
|
+
|
|
8
|
+
## What this package is
|
|
9
|
+
|
|
10
|
+
The portable contract other layers build against. At this Scaffold step it defines
|
|
11
|
+
**types/interfaces only** — the engine seams and the module-registers-metadata
|
|
12
|
+
contract. **No security logic** lives here yet; each layer's implementation is built
|
|
13
|
+
later, against these seams.
|
|
14
|
+
|
|
15
|
+
### Engine seams (one per layer — the request's journey)
|
|
16
|
+
|
|
17
|
+
| Layer | Module | Key exports |
|
|
18
|
+
| -------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
19
|
+
| Identity | `src/identity` | `Principal`, `Tenant`, `PrincipalKind`, `ExternalIdentityAssertion`, `IdentityBroker` |
|
|
20
|
+
| Authentication | `src/authentication` | `Credential`, `AuthFactor`, `AuthenticationResult`, `Authenticator` |
|
|
21
|
+
| Session | `src/session` | `Session`, `SessionTokens`, `SessionEstablishment`, `SessionAuthority` |
|
|
22
|
+
| Risk | `src/risk` | `RiskSignal`, `RiskScore`, `RiskLevel`, `RiskEngine` |
|
|
23
|
+
| Authorization | `src/authorization` | `Principal`-based `Action`, `Resource`, `DecisionContext`, `Decision`, `DecisionReasonCode`, `AccessTier`, `ResourceLevel`, **`DecisionAuthority.decide(principal, action, resource, context)`** (§7) |
|
|
24
|
+
| Audit | `src/audit` | `AuditEvent`, `AuditEventType`, `AuditSink` |
|
|
25
|
+
|
|
26
|
+
### Module-registers-metadata contract
|
|
27
|
+
|
|
28
|
+
`src/metadata` — how a business module **declares** its object types, actions,
|
|
29
|
+
access tiers, and supporting read-only dependencies to the Core (it never
|
|
30
|
+
implements access checks). Exports `ObjectTypeDescriptor`, `FieldDescriptor`,
|
|
31
|
+
`ActionDescriptor`, `SupportingDependency`, `ModuleMetadata`, and the
|
|
32
|
+
`ModuleRegistry` interface (static + dynamic/runtime registration, per ADR-0014 §5.5).
|
|
33
|
+
|
|
34
|
+
## Scripts
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pnpm --filter @astram/core build # tsc → dist/ (declarations + maps)
|
|
38
|
+
pnpm --filter @astram/core lint # eslint — proves no framework import leaked
|
|
39
|
+
pnpm --filter @astram/core test # vitest — trivial import smoke test
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Rules
|
|
43
|
+
|
|
44
|
+
- **No framework imports** anywhere (ADR-0003). Inject platform deps across the
|
|
45
|
+
integration boundary instead.
|
|
46
|
+
- **Types only at this step** — no decision/auth/session logic bodies. Real
|
|
47
|
+
invariant proofs are authored per-layer as those layers are built.
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Admin Console engine SEAM — the query/command service factories the three
|
|
3
|
+
* parallel teams fill (Layer 10).
|
|
4
|
+
*
|
|
5
|
+
* The PRELUDE freezes: the dependency bags ({@link AdminQueryDeps} /
|
|
6
|
+
* {@link AdminCommandDeps}), the two service interfaces ({@link AdminQueryService}
|
|
7
|
+
* / {@link AdminCommandService}), the two factories, and — critically — the
|
|
8
|
+
* MUTATING-COMMAND PIPELINE ORDER (encoded in {@link runCommandPipeline} + the
|
|
9
|
+
* comments below) that every command method routes through. Each method has a
|
|
10
|
+
* TRIVIAL FAIL-CLOSED default body (throw for a query it cannot answer / a `deny`
|
|
11
|
+
* CommandResult for a mutation) so the skeleton compiles and the teams replace
|
|
12
|
+
* method-by-method.
|
|
13
|
+
*
|
|
14
|
+
* OWNERSHIP:
|
|
15
|
+
* - QUERY methods (getCatalog / explain / simulate / auditView / listUnclassified)
|
|
16
|
+
* → **Team A**.
|
|
17
|
+
* - COMMAND methods (curatePermission / grant / revoke / authorPolicy / setTier /
|
|
18
|
+
* serviceAccount* / invitation*) → **Team B**, gated by the §11.3 safeguards in
|
|
19
|
+
* `./safeguards.ts` (also Team B).
|
|
20
|
+
*
|
|
21
|
+
* ⛔ NON-NEGOTIABLES the seam encodes:
|
|
22
|
+
* - ONE DECISION PATH: `simulate` + the delegated-admin check REUSE the injected
|
|
23
|
+
* {@link DecisionAuthority.decide} — never a second verdict (ADR-0001).
|
|
24
|
+
* - FAIL-CLOSED: unimplemented commands return a `deny` CommandResult; the
|
|
25
|
+
* safeguards default to deny/high-blast/confirm-required.
|
|
26
|
+
* - AUDIT: every applied mutation emits via the injected {@link AuditSink}.
|
|
27
|
+
* - NO RAW IDS out: the query engine resolves ids via {@link LabelResolver}.
|
|
28
|
+
*
|
|
29
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
|
|
30
|
+
*/
|
|
31
|
+
import type { AuditSink } from '../audit/index.js';
|
|
32
|
+
import type { AccessTier, DecisionAuthority, PermissionKey } from '../authorization/index.js';
|
|
33
|
+
import type { ModuleRegistry } from '../metadata/index.js';
|
|
34
|
+
import type { AuditReader, CatalogStore, CrossTenantInvitationStore, GrantStore, LabelResolver, PolicyStore, ServiceAccountStore } from './ports.js';
|
|
35
|
+
import { type BlastRadiusDeps } from './safeguards.js';
|
|
36
|
+
import type { AdminMutation, AuditReadResult, CatalogEntry, CommandResult, CreateInvitationCommand, CreateServiceAccountInput, CrossTenantInvitation, EffectiveAccess, GrantCommand, GuidedPolicy, InvitationTransitionCommand, Policy, RotateServiceAccountCredentialInput, ScopeServiceAccountInput, ServiceAccount, SetServiceAccountExpiryInput, SimulateRequest, SimulateResult } from './types.js';
|
|
37
|
+
/**
|
|
38
|
+
* Dependencies for the admin QUERY engine (Team A). Read-side ports + the
|
|
39
|
+
* registry (the catalog base) + the ONE decision authority (for `simulate`) +
|
|
40
|
+
* the label resolver (the no-raw-id chokepoint).
|
|
41
|
+
*/
|
|
42
|
+
export interface AdminQueryDeps {
|
|
43
|
+
/** The catalog base — auto-seeds from `listActions()`/`resolveObjectType`. */
|
|
44
|
+
readonly registry: ModuleRegistry;
|
|
45
|
+
/** The curation overlay (custom labels/groups) layered on the registry. */
|
|
46
|
+
readonly catalogStore: CatalogStore;
|
|
47
|
+
/** Grants — enumerated for effective-access explain. */
|
|
48
|
+
readonly grantStore: GrantStore;
|
|
49
|
+
/** Guided record-access policies. */
|
|
50
|
+
readonly policyStore: PolicyStore;
|
|
51
|
+
/** The audit READ side (the viewer). */
|
|
52
|
+
readonly auditReader: AuditReader;
|
|
53
|
+
/** id→label chokepoint — every user-facing id resolves here (ADR-0012). */
|
|
54
|
+
readonly labels: LabelResolver;
|
|
55
|
+
/**
|
|
56
|
+
* ⛔ The ONE decision authority — `simulate` forwards to `decide()` (ADR-0001).
|
|
57
|
+
* NEVER re-implement a verdict; this is the single decision path.
|
|
58
|
+
*/
|
|
59
|
+
readonly decide: DecisionAuthority;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Dependencies for the admin COMMAND engine (Team B). Write-side ports + the
|
|
63
|
+
* registry + the ONE decision authority (for the delegated-admin self-check) +
|
|
64
|
+
* the audit SINK (every applied mutation emits an event, §11.3).
|
|
65
|
+
*/
|
|
66
|
+
export interface AdminCommandDeps {
|
|
67
|
+
/** The catalog base (for validation / tier lookups). */
|
|
68
|
+
readonly registry: ModuleRegistry;
|
|
69
|
+
/** The curation overlay store (rename/group writes). */
|
|
70
|
+
readonly catalogStore: CatalogStore;
|
|
71
|
+
/** Grant writes (grant/revoke). */
|
|
72
|
+
readonly grantStore: GrantStore;
|
|
73
|
+
/** Guided policy writes (validated before persist). */
|
|
74
|
+
readonly policyStore: PolicyStore;
|
|
75
|
+
/** Cross-tenant invitation state machine persistence (§10bis). */
|
|
76
|
+
readonly invitationStore: CrossTenantInvitationStore;
|
|
77
|
+
/** Service-account lifecycle persistence (AC 10). */
|
|
78
|
+
readonly serviceAccountStore: ServiceAccountStore;
|
|
79
|
+
/** id→label chokepoint (for audit descriptions + blast-radius prose). */
|
|
80
|
+
readonly labels: LabelResolver;
|
|
81
|
+
/**
|
|
82
|
+
* ⛔ The ONE decision authority — the delegated-admin self-check REUSES
|
|
83
|
+
* `decide()` (ADR-0001 / §3.2). NEVER a second verdict path.
|
|
84
|
+
*/
|
|
85
|
+
readonly decide: DecisionAuthority;
|
|
86
|
+
/** ⛔ The audit SINK — every applied mutation emits an event here (§11.3). */
|
|
87
|
+
readonly audit: AuditSink;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The admin QUERY service (Team A). Read-only, human-readable, no raw ids.
|
|
91
|
+
* Every method's result is label-resolved via {@link LabelResolver} before it
|
|
92
|
+
* leaves the Core (ADR-0012).
|
|
93
|
+
*/
|
|
94
|
+
export interface AdminQueryService {
|
|
95
|
+
/**
|
|
96
|
+
* The human-readable catalog (AC 1): registry-seeded + curation overlay, each
|
|
97
|
+
* permission label-resolved with its classification (classified / unclassified /
|
|
98
|
+
* orphaned). — **Team A**.
|
|
99
|
+
*/
|
|
100
|
+
getCatalog(tenantId: string): Promise<readonly CatalogEntry[]>;
|
|
101
|
+
/**
|
|
102
|
+
* The catalog's "needs attention" subset — unclassified/orphaned permissions
|
|
103
|
+
* (§5.4). A new permission surfaces here, never silently open. — **Team A**.
|
|
104
|
+
*/
|
|
105
|
+
listUnclassified(tenantId: string): Promise<readonly CatalogEntry[]>;
|
|
106
|
+
/**
|
|
107
|
+
* Effective-access explain (AC 3): a principal's effective grants in human
|
|
108
|
+
* terms + the "why". MUST match what `decide()` would allow. — **Team A**.
|
|
109
|
+
*/
|
|
110
|
+
explain(principalId: string, tenantId: string): Promise<EffectiveAccess>;
|
|
111
|
+
/**
|
|
112
|
+
* Simulate (AC 2): "would P be allowed A on R?" — forwards to the ONE
|
|
113
|
+
* {@link DecisionAuthority.decide} and wraps its {@link Decision} with the
|
|
114
|
+
* deciding gate/reason. NEVER a second decision path (ADR-0001). — **Team A**.
|
|
115
|
+
*/
|
|
116
|
+
simulate(request: SimulateRequest): Promise<SimulateResult>;
|
|
117
|
+
/**
|
|
118
|
+
* The audit viewer read-model (§13): ordered events over {@link AuditReader},
|
|
119
|
+
* actor ids resolved to labels via {@link LabelResolver}. — **Team A**.
|
|
120
|
+
*/
|
|
121
|
+
auditView(query: AuditReadResult['query']): Promise<AuditReadResult>;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The admin COMMAND service (Team B). Every mutating method routes through the
|
|
125
|
+
* §11.3 pipeline ({@link runCommandPipeline}): delegated-admin self-check →
|
|
126
|
+
* validate → (if destructive) confirm + blast-radius → mutate → audit. Returns a
|
|
127
|
+
* fail-closed {@link CommandResult}.
|
|
128
|
+
*/
|
|
129
|
+
export interface AdminCommandService {
|
|
130
|
+
/** Rename/group a permission (curation overlay, AC 1). — **Team B**. */
|
|
131
|
+
curatePermission(mutation: AdminMutation, label: string | undefined, group: string | undefined): Promise<CommandResult<void>>;
|
|
132
|
+
/** Grant a permission (action subset + conditions) to a principal (AC 4). — **Team B**. */
|
|
133
|
+
grant(mutation: AdminMutation, command: GrantCommand): Promise<CommandResult<void>>;
|
|
134
|
+
/** Revoke a grant (destructive — confirm + blast-radius + audit, AC 7). — **Team B**. */
|
|
135
|
+
revoke(mutation: AdminMutation, grantId: string): Promise<CommandResult<void>>;
|
|
136
|
+
/** Author a guided record-access policy (structured, validated, AC 5). — **Team B**. */
|
|
137
|
+
authorPolicy(mutation: AdminMutation, policy: GuidedPolicy): Promise<CommandResult<Policy>>;
|
|
138
|
+
/**
|
|
139
|
+
* Set an access tier — MUST refuse `public` (code-only, §3.6 / AC 8). — **Team B**.
|
|
140
|
+
*/
|
|
141
|
+
setTier(mutation: AdminMutation, permissionKey: PermissionKey, tier: AccessTier): Promise<CommandResult<void>>;
|
|
142
|
+
/** Create a service account (least-privilege, tenant-bound, AC 10). — **Team B**. */
|
|
143
|
+
createServiceAccount(mutation: AdminMutation, input: CreateServiceAccountInput): Promise<CommandResult<ServiceAccount>>;
|
|
144
|
+
/** Re-scope a service account (within admin authority, AC 10). — **Team B**. */
|
|
145
|
+
scopeServiceAccount(mutation: AdminMutation, input: ScopeServiceAccountInput): Promise<CommandResult<void>>;
|
|
146
|
+
/** Issue/rotate a service-account credential via the Auth hasher port (AC 10). — **Team B**. */
|
|
147
|
+
rotateServiceAccountCredential(mutation: AdminMutation, input: RotateServiceAccountCredentialInput): Promise<CommandResult<void>>;
|
|
148
|
+
/** Revoke a service account (immediate, destructive, AC 10). — **Team B**. */
|
|
149
|
+
revokeServiceAccount(mutation: AdminMutation, id: string): Promise<CommandResult<void>>;
|
|
150
|
+
/** Set/clear a service-account expiry (AC 10). — **Team B**. */
|
|
151
|
+
setServiceAccountExpiry(mutation: AdminMutation, input: SetServiceAccountExpiryInput): Promise<CommandResult<void>>;
|
|
152
|
+
/** Create a cross-tenant invitation → `pending` (§10bis / AC 9). — **Team B**. */
|
|
153
|
+
createInvitation(mutation: AdminMutation, command: CreateInvitationCommand): Promise<CommandResult<CrossTenantInvitation>>;
|
|
154
|
+
/**
|
|
155
|
+
* Transition a cross-tenant invitation (accept/deny/revoke/expire) — validated
|
|
156
|
+
* against {@link import('./types.js').INVITATION_TRANSITIONS} (§10bis / AC 9). — **Team B**.
|
|
157
|
+
*/
|
|
158
|
+
transitionInvitation(mutation: AdminMutation, command: InvitationTransitionCommand): Promise<CommandResult<void>>;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* The ORDERED steps a mutating command MUST run through (§11.3 / §3). The PRELUDE
|
|
162
|
+
* freezes this order; Team B's command methods call {@link runCommandPipeline}
|
|
163
|
+
* with their per-command `validate` + `mutate` closures.
|
|
164
|
+
*
|
|
165
|
+
* (1) DELEGATED-ADMIN CHECK — {@link checkDelegatedAdmin} (REUSES `decide()`);
|
|
166
|
+
* fail-closed. A non-superuser cannot grant beyond own authority / cross
|
|
167
|
+
* tenants unilaterally (§3.2).
|
|
168
|
+
* (2) VALIDATE — the command's own structural check (guided policy well-formed;
|
|
169
|
+
* tier ≠ `public`; invitation transition legal). Returns a deny reason on
|
|
170
|
+
* failure (§3.4 / §3.6 / §3.7).
|
|
171
|
+
* (3) CONFIRM + BLAST-RADIUS — if {@link requiresConfirm} says the command is
|
|
172
|
+
* destructive/high-blast, REQUIRE the confirm token (else
|
|
173
|
+
* `confirm_required`) and compute {@link computeBlastRadius} for the audit
|
|
174
|
+
* record (§3.5).
|
|
175
|
+
* (4) MUTATE — apply the change via the store.
|
|
176
|
+
* (5) AUDIT — emit the `admin_action` event via {@link AuditSink} (invariant #6).
|
|
177
|
+
*
|
|
178
|
+
* Any step that denies short-circuits (fail-closed) BEFORE the mutation — the
|
|
179
|
+
* mutate step runs only after 1–3 pass.
|
|
180
|
+
*/
|
|
181
|
+
export interface CommandPipelineStep<T> {
|
|
182
|
+
/** The tagged mutation (drives the safeguards). */
|
|
183
|
+
readonly mutation: AdminMutation;
|
|
184
|
+
/**
|
|
185
|
+
* Step 2 — structural validation. Return `null` to pass, or an
|
|
186
|
+
* {@link CommandResult} deny (`ok: false`) to reject. Team B supplies this.
|
|
187
|
+
*/
|
|
188
|
+
readonly validate: () => Promise<CommandResult<never> | null> | (CommandResult<never> | null);
|
|
189
|
+
/** Whether the caller supplied a valid confirm token (checked at step 3 when required). */
|
|
190
|
+
readonly hasConfirmToken: boolean;
|
|
191
|
+
/** Step 4 — apply the mutation via the store; returns the command's value. */
|
|
192
|
+
readonly mutate: () => Promise<T>;
|
|
193
|
+
/**
|
|
194
|
+
* Step 5 — emit the audit event for the applied mutation. Team B builds the
|
|
195
|
+
* event (with the computed blast-radius) and calls the injected `AuditSink`.
|
|
196
|
+
*/
|
|
197
|
+
readonly emitAudit: (value: T) => Promise<void>;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Run a mutating command through the frozen §11.3 pipeline (order above). The
|
|
201
|
+
* PRELUDE provides the ORCHESTRATION; Team B provides the per-command closures via
|
|
202
|
+
* {@link CommandPipelineStep}. Every deny short-circuits fail-closed BEFORE the
|
|
203
|
+
* mutation. Used by Team B's command-service method bodies.
|
|
204
|
+
*
|
|
205
|
+
* ⛔ `decide` is threaded into {@link checkDelegatedAdmin} — the ONE decision path.
|
|
206
|
+
*/
|
|
207
|
+
export declare function runCommandPipeline<T>(step: CommandPipelineStep<T>, decide: DecisionAuthority, blastDeps: BlastRadiusDeps): Promise<CommandResult<T>>;
|
|
208
|
+
/**
|
|
209
|
+
* Create the admin QUERY service (Team A). The PRELUDE returns a skeleton whose
|
|
210
|
+
* methods FAIL CLOSED (throw `not_implemented`); Team A replaces each body.
|
|
211
|
+
* `deps` is captured for the real implementations.
|
|
212
|
+
*/
|
|
213
|
+
export declare function createAdminQueryService(deps: AdminQueryDeps): AdminQueryService;
|
|
214
|
+
/**
|
|
215
|
+
* Create the admin COMMAND service (Team B). The PRELUDE returns a skeleton whose
|
|
216
|
+
* methods FAIL CLOSED (return a `not_implemented` DENY); Team B replaces each body,
|
|
217
|
+
* routing through {@link runCommandPipeline} with `deps.decide` + the stores +
|
|
218
|
+
* `deps.audit`. `deps` is captured for the real implementations.
|
|
219
|
+
*/
|
|
220
|
+
export declare function createAdminCommandService(deps: AdminCommandDeps): AdminCommandService;
|
|
221
|
+
//# sourceMappingURL=admin-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admin-service.d.ts","sourceRoot":"","sources":["../../src/admin/admin-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EACV,UAAU,EACV,iBAAiB,EACjB,aAAa,EACd,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,0BAA0B,EAC1B,UAAU,EACV,aAAa,EACb,WAAW,EACX,mBAAmB,EACpB,MAAM,YAAY,CAAC;AACpB,OAAO,EAIL,KAAK,eAAe,EACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,YAAY,EACZ,aAAa,EACb,uBAAuB,EACvB,yBAAyB,EACzB,qBAAqB,EACrB,eAAe,EACf,YAAY,EACZ,YA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,aAAa,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;IAC9F,2FAA2F;IAC3F,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;IAClC,8EAA8E;IAC9E,QAAQ,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC;IAClC;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACjD;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CAAC,CAAC,EACxC,IAAI,EAAE,mBAAmB,CAAC,CAAC,CAAC,EAC5B,MAAM,EAAE,iBAAiB,EACzB,SAAS,EAAE,eAAe,GACzB,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CA6B3B;AAsBD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,cAAc,GAAG,iBAAiB,CAqB/E;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,gBAAgB,GACrB,mBAAmB,CAyCrB"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Admin Console engine SEAM — the query/command service factories the three
|
|
3
|
+
* parallel teams fill (Layer 10).
|
|
4
|
+
*
|
|
5
|
+
* The PRELUDE freezes: the dependency bags ({@link AdminQueryDeps} /
|
|
6
|
+
* {@link AdminCommandDeps}), the two service interfaces ({@link AdminQueryService}
|
|
7
|
+
* / {@link AdminCommandService}), the two factories, and — critically — the
|
|
8
|
+
* MUTATING-COMMAND PIPELINE ORDER (encoded in {@link runCommandPipeline} + the
|
|
9
|
+
* comments below) that every command method routes through. Each method has a
|
|
10
|
+
* TRIVIAL FAIL-CLOSED default body (throw for a query it cannot answer / a `deny`
|
|
11
|
+
* CommandResult for a mutation) so the skeleton compiles and the teams replace
|
|
12
|
+
* method-by-method.
|
|
13
|
+
*
|
|
14
|
+
* OWNERSHIP:
|
|
15
|
+
* - QUERY methods (getCatalog / explain / simulate / auditView / listUnclassified)
|
|
16
|
+
* → **Team A**.
|
|
17
|
+
* - COMMAND methods (curatePermission / grant / revoke / authorPolicy / setTier /
|
|
18
|
+
* serviceAccount* / invitation*) → **Team B**, gated by the §11.3 safeguards in
|
|
19
|
+
* `./safeguards.ts` (also Team B).
|
|
20
|
+
*
|
|
21
|
+
* ⛔ NON-NEGOTIABLES the seam encodes:
|
|
22
|
+
* - ONE DECISION PATH: `simulate` + the delegated-admin check REUSE the injected
|
|
23
|
+
* {@link DecisionAuthority.decide} — never a second verdict (ADR-0001).
|
|
24
|
+
* - FAIL-CLOSED: unimplemented commands return a `deny` CommandResult; the
|
|
25
|
+
* safeguards default to deny/high-blast/confirm-required.
|
|
26
|
+
* - AUDIT: every applied mutation emits via the injected {@link AuditSink}.
|
|
27
|
+
* - NO RAW IDS out: the query engine resolves ids via {@link LabelResolver}.
|
|
28
|
+
*
|
|
29
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
|
|
30
|
+
*/
|
|
31
|
+
import { checkDelegatedAdmin, computeBlastRadius, requiresConfirm, } from './safeguards.js';
|
|
32
|
+
/**
|
|
33
|
+
* Run a mutating command through the frozen §11.3 pipeline (order above). The
|
|
34
|
+
* PRELUDE provides the ORCHESTRATION; Team B provides the per-command closures via
|
|
35
|
+
* {@link CommandPipelineStep}. Every deny short-circuits fail-closed BEFORE the
|
|
36
|
+
* mutation. Used by Team B's command-service method bodies.
|
|
37
|
+
*
|
|
38
|
+
* ⛔ `decide` is threaded into {@link checkDelegatedAdmin} — the ONE decision path.
|
|
39
|
+
*/
|
|
40
|
+
export async function runCommandPipeline(step, decide, blastDeps) {
|
|
41
|
+
// (1) DELEGATED-ADMIN CHECK — fail-closed, reuses decide() (ADR-0001 / §3.2).
|
|
42
|
+
const delegated = await checkDelegatedAdmin(step.mutation.admin, step.mutation, decide);
|
|
43
|
+
if (delegated.ok !== true) {
|
|
44
|
+
return { ok: false, reason: delegated.reason ?? 'delegated_admin_exceeds_authority' };
|
|
45
|
+
}
|
|
46
|
+
// (2) VALIDATE — structural (guided policy / tier≠public / legal transition).
|
|
47
|
+
const invalid = await step.validate();
|
|
48
|
+
if (invalid !== null) {
|
|
49
|
+
return invalid;
|
|
50
|
+
}
|
|
51
|
+
// (3) CONFIRM + BLAST-RADIUS — destructive/high-blast requires a confirm token.
|
|
52
|
+
if (requiresConfirm(step.mutation) === true) {
|
|
53
|
+
if (step.hasConfirmToken !== true) {
|
|
54
|
+
return { ok: false, reason: 'confirm_required' };
|
|
55
|
+
}
|
|
56
|
+
// Computed for the audit record; Team B attaches it to the emitted event.
|
|
57
|
+
await computeBlastRadius(step.mutation, blastDeps);
|
|
58
|
+
}
|
|
59
|
+
// (4) MUTATE — only reached after 1–3 pass (fail-closed order).
|
|
60
|
+
const value = await step.mutate();
|
|
61
|
+
// (5) AUDIT — every applied mutation is recorded (invariant #6).
|
|
62
|
+
await step.emitAudit(value);
|
|
63
|
+
return { ok: true, value };
|
|
64
|
+
}
|
|
65
|
+
// ---------------------------------------------------------------------------
|
|
66
|
+
// Factories — return fail-closed skeletons the teams replace method-by-method.
|
|
67
|
+
// ---------------------------------------------------------------------------
|
|
68
|
+
/**
|
|
69
|
+
* The fail-closed default a query method throws when it has no implementation yet.
|
|
70
|
+
* A THROW (not an empty result) so a not-yet-built query surfaces loudly in dev/CI
|
|
71
|
+
* rather than silently returning "no data" (which could read as "no access").
|
|
72
|
+
*/
|
|
73
|
+
function notImplementedQuery(method) {
|
|
74
|
+
throw new Error(`[admin-query] ${method} is not implemented yet — Team A fills this method (prelude skeleton).`);
|
|
75
|
+
}
|
|
76
|
+
/** The fail-closed default a command method returns when unimplemented — a DENY. */
|
|
77
|
+
function notImplementedCommand() {
|
|
78
|
+
return { ok: false, reason: 'not_implemented' };
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Create the admin QUERY service (Team A). The PRELUDE returns a skeleton whose
|
|
82
|
+
* methods FAIL CLOSED (throw `not_implemented`); Team A replaces each body.
|
|
83
|
+
* `deps` is captured for the real implementations.
|
|
84
|
+
*/
|
|
85
|
+
export function createAdminQueryService(deps) {
|
|
86
|
+
// Captured for the team implementations; unused in the fail-closed skeleton.
|
|
87
|
+
void deps;
|
|
88
|
+
return {
|
|
89
|
+
async getCatalog() {
|
|
90
|
+
return notImplementedQuery('getCatalog');
|
|
91
|
+
},
|
|
92
|
+
async listUnclassified() {
|
|
93
|
+
return notImplementedQuery('listUnclassified');
|
|
94
|
+
},
|
|
95
|
+
async explain() {
|
|
96
|
+
return notImplementedQuery('explain');
|
|
97
|
+
},
|
|
98
|
+
async simulate() {
|
|
99
|
+
// ⛔ Team A: forward to deps.decide.decide(...) — the ONE path (ADR-0001).
|
|
100
|
+
return notImplementedQuery('simulate');
|
|
101
|
+
},
|
|
102
|
+
async auditView() {
|
|
103
|
+
return notImplementedQuery('auditView');
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Create the admin COMMAND service (Team B). The PRELUDE returns a skeleton whose
|
|
109
|
+
* methods FAIL CLOSED (return a `not_implemented` DENY); Team B replaces each body,
|
|
110
|
+
* routing through {@link runCommandPipeline} with `deps.decide` + the stores +
|
|
111
|
+
* `deps.audit`. `deps` is captured for the real implementations.
|
|
112
|
+
*/
|
|
113
|
+
export function createAdminCommandService(deps) {
|
|
114
|
+
// Captured for the team implementations; unused in the fail-closed skeleton.
|
|
115
|
+
void deps;
|
|
116
|
+
return {
|
|
117
|
+
async curatePermission() {
|
|
118
|
+
return notImplementedCommand();
|
|
119
|
+
},
|
|
120
|
+
async grant() {
|
|
121
|
+
return notImplementedCommand();
|
|
122
|
+
},
|
|
123
|
+
async revoke() {
|
|
124
|
+
return notImplementedCommand();
|
|
125
|
+
},
|
|
126
|
+
async authorPolicy() {
|
|
127
|
+
return notImplementedCommand();
|
|
128
|
+
},
|
|
129
|
+
async setTier() {
|
|
130
|
+
return notImplementedCommand();
|
|
131
|
+
},
|
|
132
|
+
async createServiceAccount() {
|
|
133
|
+
return notImplementedCommand();
|
|
134
|
+
},
|
|
135
|
+
async scopeServiceAccount() {
|
|
136
|
+
return notImplementedCommand();
|
|
137
|
+
},
|
|
138
|
+
async rotateServiceAccountCredential() {
|
|
139
|
+
return notImplementedCommand();
|
|
140
|
+
},
|
|
141
|
+
async revokeServiceAccount() {
|
|
142
|
+
return notImplementedCommand();
|
|
143
|
+
},
|
|
144
|
+
async setServiceAccountExpiry() {
|
|
145
|
+
return notImplementedCommand();
|
|
146
|
+
},
|
|
147
|
+
async createInvitation() {
|
|
148
|
+
return notImplementedCommand();
|
|
149
|
+
},
|
|
150
|
+
async transitionInvitation() {
|
|
151
|
+
return notImplementedCommand();
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=admin-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admin-service.js","sourceRoot":"","sources":["../../src/admin/admin-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAkBH,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,GAEhB,MAAM,iBAAiB,CAAC;AAwPzB;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,IAA4B,EAC5B,MAAyB,EACzB,SAA0B;IAE1B,8EAA8E;IAC9E,MAAM,SAAS,GAAG,MAAM,mBAAmB,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACxF,IAAI,SAAS,CAAC,EAAE,KAAK,IAAI,EAAE,CAAC;QAC1B,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,IAAI,mCAAmC,EAAE,CAAC;IACxF,CAAC;IAED,8EAA8E;IAC9E,MAAM,OAAO,GAAG,M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
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Team B commands — **grant / revoke** (AC 4, AC 7).
|
|
3
|
+
*
|
|
4
|
+
* grant: bind a principal to a permission with an action subset (+ optional guided
|
|
5
|
+
* conditions), scoped to a tenant. Routes the full §11.3 pipeline — the
|
|
6
|
+
* delegated-admin gate (the admin can only grant what THEY hold, reused via
|
|
7
|
+
* decide()) → validate the action subset + conditions → mutate via {@link GrantStore}
|
|
8
|
+
* → audit. Additive → no confirm token required.
|
|
9
|
+
*
|
|
10
|
+
* revoke: remove a grant by id. DESTRUCTIVE — the pipeline requires a confirm token
|
|
11
|
+
* + computes the blast-radius (threaded into the audit event) before the store
|
|
12
|
+
* removes it. Idempotent at the store (a second revoke is a no-op).
|
|
13
|
+
*
|
|
14
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
|
|
15
|
+
*/
|
|
16
|
+
import type { AuditSink } from '../../audit/index.js';
|
|
17
|
+
import type { DecisionAuthority } from '../../authorization/index.js';
|
|
18
|
+
import type { GrantStore, LabelResolver } from '../ports.js';
|
|
19
|
+
import type { AdminMutation, CommandResult, GrantCommand } from '../types.js';
|
|
20
|
+
/** Deps the grant/revoke commands close over. */
|
|
21
|
+
export interface GrantCommandDeps {
|
|
22
|
+
readonly grantStore: GrantStore;
|
|
23
|
+
readonly labels: LabelResolver;
|
|
24
|
+
readonly decide: DecisionAuthority;
|
|
25
|
+
readonly audit: AuditSink;
|
|
26
|
+
/** UTC clock (epoch ms). */
|
|
27
|
+
readonly now?: () => number;
|
|
28
|
+
/** Injected id minter for the new grant id (deterministic in tests). */
|
|
29
|
+
readonly newId?: () => string;
|
|
30
|
+
}
|
|
31
|
+
export declare function makeGrant(deps: GrantCommandDeps): (inMutation: AdminMutation, command: GrantCommand) => Promise<CommandResult<void>>;
|
|
32
|
+
export declare function makeRevoke(deps: GrantCommandDeps): (mutation: AdminMutation, grantId: string) => Promise<CommandResult<void>>;
|
|
33
|
+
/**
|
|
34
|
+
* Read the confirm flag from a destructive command's mutation payload. The service
|
|
35
|
+
* assembler places `{ confirm: ConfirmToken }` on the payload for destructive
|
|
36
|
+
* commands; a valid confirm token has `confirmed === true` (strict). Any other
|
|
37
|
+
* shape → no confirm token presented.
|
|
38
|
+
*/
|
|
39
|
+
export declare function extractHasConfirm(mutation: AdminMutation): boolean;
|
|
40
|
+
//# sourceMappingURL=grants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grants.d.ts","sourceRoot":"","sources":["../../../src/admin/command/grants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEtE,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EAEb,YAAY,EAEb,MAAM,aAAa,CAAC;AAIrB,iDAAiD;AACjD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC;IACnC,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,4BAA4B;IAC5B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IAC5B,wEAAwE;IACxE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,MAAM,CAAC;CAC/B;AA2BD,wBAAgB,SAAS,CAAC,IAAI,EAAE,gBAAgB,IAI5C,YAAY,aAAa,EACzB,SAAS,YAAY,KACpB,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAyGhC;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,gBAAgB,IAG7C,UAAU,aAAa,EACvB,SAAS,MAAM,KACd,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAyDhC;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,aAAa,GAAG,OAAO,CAKlE"}
|