@pipeline-builder/api-core 4.1.6 → 4.1.7

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.
@@ -1,5 +1,7 @@
1
1
  import type { Request, Response, NextFunction } from 'express';
2
+ import { type OrgAdminAssuranceMachines } from './route-table.js';
2
3
  import { type AssuranceLevel, type JwtPayload } from '../types/common.js';
4
+ import { ErrorCode } from '../types/error-codes.js';
3
5
  import { type Permission } from '../types/permissions.js';
4
6
  /**
5
7
  * Verify a token that speaks for a PERSON — access, step-up, and the token an
@@ -157,6 +159,61 @@ export interface AssuranceOptions {
157
159
  * of "is this session MFA-grade" in the codebase.
158
160
  */
159
161
  export declare function requireAssurance(options: AssuranceOptions): (req: Request, res: Response, next: NextFunction) => void;
162
+ /**
163
+ * Handler-level twin of {@link requireAssurance}, for a route where only SOME
164
+ * requests must be MFA-grade — e.g. a policy route on which TIGHTENING a setting
165
+ * stays open to a single-factor session (so an admin without MFA can adopt it)
166
+ * but LOOSENING it does not. Same rules and the same three refusals. Returns
167
+ * true when the request was REFUSED (a response has been sent).
168
+ */
169
+ export declare function refuseWeakSession(req: Request, res: Response, options: AssuranceOptions): boolean;
170
+ /** What {@link requireOrgAdminAssurance} demands of a route. */
171
+ export interface OrgAdminAssuranceOptions {
172
+ /** What a machine credential (PAT, service account, machine session) meets on
173
+ * this route while the policy is on — see {@link OrgAdminAssuranceMachines}.
174
+ * Required, so every route states its decision rather than inheriting one. */
175
+ machines: OrgAdminAssuranceMachines;
176
+ }
177
+ /** `details.reason` on a refusal by {@link requireOrgAdminAssurance}, so the UI
178
+ * can say it is the ORG's policy asking, not the route's own requirement. */
179
+ export declare const ORG_ADMIN_MFA_REASON = "org_admin_policy";
180
+ /**
181
+ * The refusal {@link requireOrgAdminAssurance} would send for these claims, or
182
+ * `undefined` when the request may proceed. Exported so a handler whose policy
183
+ * applies to only PART of a route (e.g. `generate-token`, where opening a new
184
+ * machine credential is gated but renewing an existing one is not) applies the
185
+ * exact same rule rather than a copy of it.
186
+ */
187
+ export declare function orgAdminAssuranceRefusal(claims: JwtPayload | undefined, options: OrgAdminAssuranceOptions): {
188
+ status: number;
189
+ code: ErrorCode;
190
+ message: string;
191
+ reason: 'machine_principal' | 'weak_session';
192
+ } | undefined;
193
+ /**
194
+ * Apply {@link orgAdminAssuranceRefusal} and send its refusal. Returns true when
195
+ * the request was REFUSED (a response has been sent). For handler-level use;
196
+ * routes use {@link requireOrgAdminAssurance}.
197
+ */
198
+ export declare function refuseForOrgAdminAssurance(req: Request, res: Response, options: OrgAdminAssuranceOptions): boolean;
199
+ /**
200
+ * The org policy "administrative actions require MFA" (`adminActionsRequireMfa`).
201
+ *
202
+ * Unlike {@link requireAssurance}, the requirement is the ORG's choice, not the
203
+ * route's: the gate reads the `org_admin_aal` claim, set at token issue from the
204
+ * active org's policy (strictest across its ancestors), so a service that cannot
205
+ * read the org document still enforces it. With the policy off the gate is a
206
+ * no-op; with it on, a single-factor session is refused 401 `MFA_REQUIRED`
207
+ * (with `details.reason: 'org_admin_policy'`) — the same code the client already
208
+ * turns into "enrol a factor / sign in with it", never a sign-out.
209
+ *
210
+ * `machines` is decided per route (see {@link OrgAdminAssuranceMachines}): the
211
+ * policy is about how strongly a PERSON's session was opened, so automation that
212
+ * legitimately drives a route keeps working (`allow`), while a route that mints
213
+ * a further credential refuses machines outright (`refuse`, 403
214
+ * `HUMAN_SESSION_REQUIRED` — the same refusal `requireAssurance` gives them).
215
+ */
216
+ export declare function requireOrgAdminAssurance(options: OrgAdminAssuranceOptions): (req: Request, res: Response, next: NextFunction) => void;
160
217
  /**
161
218
  * Whether a verified token carries a well-formed identity: a known
162
219
  * `principalType` and `token_use`, and the claims that kind of principal must