mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 16:53:34 +00:00
[PM-11418] generator policy constraints (#11014)
* add constraint support to UserStateSubject * add dynamic constraints * implement password policy constraints * replace policy evaluator with constraints in credential generation service * add cascade between minNumber and minSpecial Co-authored-by: Daniel James Smith <2670567+djsmith85@users.noreply.github.com>
This commit is contained in:
29
libs/common/src/tools/state/state-constraints-dependency.ts
Normal file
29
libs/common/src/tools/state/state-constraints-dependency.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { Observable } from "rxjs";
|
||||
|
||||
import { DynamicStateConstraints, StateConstraints } from "../types";
|
||||
|
||||
/** A pattern for types that depend upon a dynamic set of constraints.
|
||||
*
|
||||
* Consumers of this dependency should track the last-received state and
|
||||
* apply it when application state is received or emitted. If `constraints$`
|
||||
* emits an unrecoverable error, the consumer should continue using the
|
||||
* last-emitted constraints. If `constraints$` completes, the consumer should
|
||||
* continue using the last-emitted constraints.
|
||||
*/
|
||||
export type StateConstraintsDependency<State> = {
|
||||
/** A stream that emits constraints when subscribed and when the
|
||||
* constraints change. The stream should not emit `null` or
|
||||
* `undefined`.
|
||||
*/
|
||||
constraints$: Observable<StateConstraints<State> | DynamicStateConstraints<State>>;
|
||||
};
|
||||
|
||||
/** Returns `true` if the input constraint is a `DynamicStateConstraints<T>`.
|
||||
* Otherwise, returns false.
|
||||
* @param constraints the constraint to evaluate.
|
||||
* */
|
||||
export function isDynamic<State>(
|
||||
constraints: StateConstraints<State> | DynamicStateConstraints<State>,
|
||||
): constraints is DynamicStateConstraints<State> {
|
||||
return constraints && "calibrate" in constraints;
|
||||
}
|
||||
Reference in New Issue
Block a user