@rokt/dcui-orchestrator 1.2.1-rc.51 → 1.2.1-rc.52

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.
@@ -6,3 +6,4 @@ export declare const FAILED_TO_MAP_STATIC_DATA = "FAILED_TO_MAP_STATIC_DATA";
6
6
  export declare const FAILED_SANITISING_HTML = "FAILED_SANITISING_HTML";
7
7
  export declare const UNRESOLVED_FORM_VALIDATION_TARGET = "UNRESOLVED_FORM_VALIDATION_TARGET";
8
8
  export declare const MISSING_LEAD_IDENTITY = "MISSING_LEAD_IDENTITY";
9
+ export declare const UNSAFE_FORM_VALIDATION_PATTERN = "UNSAFE_FORM_VALIDATION_PATTERN";
@@ -83,3 +83,88 @@ export interface FormFieldRef {
83
83
  * ActionButton (to gate dispatch) so both resolve entries identically.
84
84
  */
85
85
  export declare function resolveFormFieldRefs(formStates: FormStatesState, entries: string[]): FormFieldRef[];
86
+ /**
87
+ * The longest `Pattern` a layout may register. A longer one is refused by
88
+ * {@link scanPattern}: the form-state reducer drops it at registration and
89
+ * {@link matchesPattern} treats it as non-blocking.
90
+ */
91
+ export declare const MAX_PATTERN_LENGTH = 256;
92
+ /**
93
+ * The longest value a `Pattern` validation tests, whatever the pattern. A
94
+ * longer value fails the validation with its message, untested. The rules of
95
+ * {@link scanPattern} bound the engine's work on a value of this length and
96
+ * on no other.
97
+ */
98
+ export declare const MAX_PATTERN_VALUE_LENGTH = 512;
99
+ /** Why {@link scanPattern} refused a pattern: the first rule it broke. */
100
+ export type PatternRefusal = 'too-long' | 'backreference' | 'nested-quantifier' | 'repeated-alternation' | 'quantified-lookaround' | 'too-many-repetitions' | 'count-too-wide' | 'too-many-ways' | 'too-many-steps' | 'invalid';
101
+ /** What {@link scanPattern} read: the verdict, with a refusal's reason. */
102
+ export type PatternScan = {
103
+ safe: true;
104
+ } | {
105
+ safe: false;
106
+ reason: PatternRefusal;
107
+ };
108
+ /**
109
+ * The walk behind {@link isSafePattern}: one pass over the pattern's syntax,
110
+ * with no reading of what the atoms match. Escapes and `[...]` classes are
111
+ * one token each, so a `(`, `|` or `*` inside them is literal. The rules are
112
+ * blunt by design: each refuses a shape that can backtrack past the value
113
+ * cap, and with it the safe patterns of the same shape. The check that reads
114
+ * a pattern's real cost belongs at publish time, in the service that stores
115
+ * the layout. Refused, in the order the rules are read:
116
+ *
117
+ * 1. a pattern longer than {@link MAX_PATTERN_LENGTH};
118
+ * 2. a backreference, `\1` or `\k<name>`;
119
+ * 3. a repeated group that holds a quantifier of its own, at any depth:
120
+ * `(a+)+`, `(\d{3}-?)+`, `(a+){3}`. A `?` or a `{1}` on the group takes
121
+ * it whole or not at all, so `(a+)?` is accepted. A fixed count is copies
122
+ * of the group in sequence, so `(\d{4}[- ]?){3}` is accepted;
123
+ * 4. a repeated group that holds a `|`, at any depth: `(a|ab)+`. A fixed
124
+ * count is copies here too, so `(?:a|ab){3}` is accepted;
125
+ * 5. a quantifier on a lookaround, inside one, or on a group that holds
126
+ * one: `(?=a)+`, `(?=.*\d)`, `(?:(?=a)b){3}`;
127
+ * 6. more than {@link MAX_REPETITIONS} repetitions that can run on in the
128
+ * whole pattern, or more than {@link MAX_ANCHORED_REPETITIONS} in one
129
+ * anchored at `^`: `\w*\w*\w*-`, `^\w*\w*\w*\w*$`, where `^\w*\w*\w*$`
130
+ * and `^[^\s@]+@[^\s@]+\.[^\s@]+$` are accepted;
131
+ * 7. a count past {@link MAX_PATTERN_VALUE_LENGTH}, on its own or multiplied
132
+ * through the counts of the groups that hold it: `\w{513}`, `.{0,1000}`,
133
+ * `(?:\b){999}`, `(?:(?:\b){512}){512}`;
134
+ * 8. {@link MAX_WAYS_STEPS} steps or more from the ways alone: each atom's
135
+ * count, once per way of the atoms before it. Thirty `a?`, eight
136
+ * `\d{1,9}`, `^(?:\d{1,9}){5}\w{467}$` and sixteen `a?` before `\w{495}$`
137
+ * are refused, where a phone, card, IPv4 or optional-scheme URL pattern
138
+ * is accepted;
139
+ * 9. {@link MAX_PATTERN_STEPS} steps or more from the ways and the runs
140
+ * together: the same sum, each run multiplying the paths to the atoms
141
+ * after it by the cap over the run's rank on its own path (its branch
142
+ * and the branches of the groups that hold it, never a sibling `|`
143
+ * alternative, so the branches of a `|` add up), and a pattern with no
144
+ * `^` running from every position. Twelve `a?` before `\w*\w*$`,
145
+ * `\w*\w*-`, `^\w*\w*\w{511}$` and `^\w*!|^` with nine `a?` before
146
+ * `\w*\w*!` are refused, where `^\w*\w*\w*!`, `\S+@\S+` and `^\S+@\S+$`
147
+ * are accepted;
148
+ * 10. a pattern RegExp rejects, as `(`.
149
+ *
150
+ * An accepted pattern is tested on a value of {@link MAX_PATTERN_VALUE_LENGTH}
151
+ * characters at most; {@link matchesPattern} fails a longer value untested.
152
+ */
153
+ export declare function scanPattern(pattern: string): PatternScan;
154
+ /**
155
+ * Whether a layout author's `Pattern` can be tested without hanging the
156
+ * plugin. The regular expression runs synchronously on the UI thread, inside
157
+ * a reducer, on every keystroke, and cannot be interrupted, so the only
158
+ * control is on the pattern's shape before it runs: the rules of
159
+ * {@link scanPattern}. A `pattern` that is no string is not refused, so a
160
+ * layout no schema checked still registers, but {@link matchesPattern}
161
+ * never compiles it.
162
+ */
163
+ export declare function isSafePattern(pattern: string): boolean;
164
+ /**
165
+ * Whether a validation may be registered on a field: every validation but a
166
+ * `Pattern` that {@link isSafePattern} refuses. Shared by the form-state
167
+ * reducer, which drops the refused ones, and the TextInput, which reports
168
+ * them, so the two never disagree on what was dropped.
169
+ */
170
+ export declare function isSafeInputValidation(validation: InputValidation): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokt/dcui-orchestrator",
3
- "version": "1.2.1-rc.51",
3
+ "version": "1.2.1-rc.52",
4
4
  "description": "Rokt's DCUI rendering process",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",