@secmia/openui-flow 4.1.0 → 4.2.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/AGENTS.md +19 -0
- package/README.md +89 -0
- package/dist/index.d.mts +86 -4
- package/dist/index.d.ts +86 -4
- package/dist/index.js +344 -111
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +344 -111
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Built-in requirement keys that cover the default flow states supported by the package.
|
|
6
|
+
*/
|
|
4
7
|
declare const DefaultAppRequirements: {
|
|
5
8
|
readonly HAS_EMAIL: "has_email";
|
|
6
9
|
readonly EMAIL_VERIFIED: "email_verified";
|
|
@@ -10,6 +13,9 @@ declare const DefaultAppRequirements: {
|
|
|
10
13
|
readonly ACCEPTED_TOS: "accepted_tos";
|
|
11
14
|
readonly HAS_JOB_TITLE: "has_job_title";
|
|
12
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* Built-in step keys used by the default flow UI and default requirement resolvers.
|
|
18
|
+
*/
|
|
13
19
|
declare const DefaultAdaptiveSteps: {
|
|
14
20
|
readonly COLLECT_EMAIL: "COLLECT_EMAIL";
|
|
15
21
|
readonly VERIFY_OTP: "VERIFY_OTP";
|
|
@@ -18,10 +24,15 @@ declare const DefaultAdaptiveSteps: {
|
|
|
18
24
|
readonly COLLECT_TOS: "COLLECT_TOS";
|
|
19
25
|
readonly COMPLETE: "COMPLETE";
|
|
20
26
|
};
|
|
27
|
+
/** Requirement key from the built-in default requirement set. */
|
|
21
28
|
type DefaultAppRequirement = (typeof DefaultAppRequirements)[keyof typeof DefaultAppRequirements];
|
|
29
|
+
/** Step key from the built-in default step set. */
|
|
22
30
|
type DefaultAdaptiveStep = (typeof DefaultAdaptiveSteps)[keyof typeof DefaultAdaptiveSteps];
|
|
31
|
+
/** Requirement key used by the engine, including custom app-specific requirements. */
|
|
23
32
|
type AppRequirement = DefaultAppRequirement | (string & {});
|
|
33
|
+
/** Step key used by the engine, including custom app-specific steps. */
|
|
24
34
|
type AdaptiveStep = DefaultAdaptiveStep | (string & {});
|
|
35
|
+
/** Base context shape managed by the default flow helpers and UI. */
|
|
25
36
|
type AdaptiveContextBase = {
|
|
26
37
|
email: string | null;
|
|
27
38
|
isVerified: boolean;
|
|
@@ -33,14 +44,23 @@ type AdaptiveContextBase = {
|
|
|
33
44
|
};
|
|
34
45
|
agreedToTos: boolean;
|
|
35
46
|
};
|
|
47
|
+
/** Alias for the default context shape used by the built-in component and hook. */
|
|
36
48
|
type AdaptiveContext = AdaptiveContextBase;
|
|
49
|
+
/** Default set of requirements used when a flow does not provide its own list. */
|
|
37
50
|
declare const defaultRequirements: DefaultAppRequirement[];
|
|
51
|
+
/** Default initial context used by the component and hook when no initialValue is provided. */
|
|
38
52
|
declare const initialContext: AdaptiveContextBase;
|
|
53
|
+
/** Utility type for APIs that may return either a synchronous or asynchronous value. */
|
|
39
54
|
type MaybePromise<T> = T | Promise<T>;
|
|
55
|
+
/** Resolver contract that maps one requirement to the step shown when it is unmet. */
|
|
40
56
|
type RequirementResolver<TContext = AdaptiveContextBase, TStep extends string = AdaptiveStep> = {
|
|
41
57
|
isMet: (context: TContext) => MaybePromise<boolean>;
|
|
42
58
|
step: TStep;
|
|
43
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* Single requirement node in the requirement graph.
|
|
62
|
+
* The engine evaluates nodes by priority, dependency readiness, and custom conditions.
|
|
63
|
+
*/
|
|
44
64
|
type RequirementGraphNode<TContext, TRequirement extends string, TStep extends string> = {
|
|
45
65
|
requirement: TRequirement;
|
|
46
66
|
step: TStep;
|
|
@@ -49,13 +69,24 @@ type RequirementGraphNode<TContext, TRequirement extends string, TStep extends s
|
|
|
49
69
|
priority?: number;
|
|
50
70
|
dependsOn?: readonly TRequirement[];
|
|
51
71
|
};
|
|
72
|
+
/** Ordered requirement graph consumed by the engine evaluation helpers. */
|
|
52
73
|
type RequirementGraph<TContext, TRequirement extends string, TStep extends string> = readonly RequirementGraphNode<TContext, TRequirement, TStep>[];
|
|
74
|
+
/** Default requirement-to-step resolvers used by the built-in flow UI. */
|
|
53
75
|
declare const defaultRequirementResolvers: Record<DefaultAppRequirement, RequirementResolver<AdaptiveContextBase, AdaptiveStep>>;
|
|
76
|
+
/**
|
|
77
|
+
* Build a requirement graph from a requirement list, resolver map, and optional graph metadata.
|
|
78
|
+
*
|
|
79
|
+
* The function validates that dependencies refer to known resolver-backed requirements and
|
|
80
|
+
* rejects circular dependency chains at graph creation time.
|
|
81
|
+
*/
|
|
54
82
|
declare function createRequirementGraph<TContext, TRequirement extends string, TStep extends string>(requirements: readonly TRequirement[], resolvers: Partial<Record<TRequirement, RequirementResolver<TContext, TStep>>>, options?: {
|
|
55
83
|
priorities?: Partial<Record<TRequirement, number>>;
|
|
56
84
|
conditions?: Partial<Record<TRequirement, (context: TContext) => MaybePromise<boolean>>>;
|
|
57
85
|
dependencies?: Partial<Record<TRequirement, readonly TRequirement[]>>;
|
|
58
86
|
}): RequirementGraph<TContext, TRequirement, TStep>;
|
|
87
|
+
/**
|
|
88
|
+
* Build a requirement graph using the built-in default resolvers plus any app-specific overrides.
|
|
89
|
+
*/
|
|
59
90
|
declare function createDefaultRequirementGraph<TContext extends AdaptiveContextBase = AdaptiveContextBase, TRequirement extends string = DefaultAppRequirement, TStep extends string = AdaptiveStep>(options?: {
|
|
60
91
|
requirements?: readonly TRequirement[];
|
|
61
92
|
resolvers?: Partial<Record<TRequirement, RequirementResolver<TContext, TStep>>>;
|
|
@@ -63,10 +94,25 @@ declare function createDefaultRequirementGraph<TContext extends AdaptiveContextB
|
|
|
63
94
|
conditions?: Partial<Record<TRequirement, (context: TContext) => MaybePromise<boolean>>>;
|
|
64
95
|
dependencies?: Partial<Record<TRequirement, readonly TRequirement[]>>;
|
|
65
96
|
}): RequirementGraph<TContext, TRequirement, TStep>;
|
|
97
|
+
/**
|
|
98
|
+
* Evaluate the graph against the current context and return the next unmet step.
|
|
99
|
+
*
|
|
100
|
+
* Nodes are evaluated in dependency-aware order with deterministic tie-breaking.
|
|
101
|
+
*/
|
|
66
102
|
declare function evaluateNextStep<TContext, TRequirement extends string, TStep extends string>(context: TContext, graph: RequirementGraph<TContext, TRequirement, TStep>, completeStep: TStep): Promise<TStep>;
|
|
103
|
+
/**
|
|
104
|
+
* Return every unmet requirement for the current context in graph evaluation order.
|
|
105
|
+
*/
|
|
67
106
|
declare function getMissingRequirements<TContext, TRequirement extends string, TStep extends string>(context: TContext, graph: RequirementGraph<TContext, TRequirement, TStep>): Promise<TRequirement[]>;
|
|
68
107
|
|
|
69
|
-
|
|
108
|
+
/** Supported OAuth provider identifiers accepted by the adapter and default UI. */
|
|
109
|
+
type OAuthProvider = "google" | "apple" | (string & {});
|
|
110
|
+
/** Configurable OAuth provider label/id pair used by the default footer buttons. */
|
|
111
|
+
type AdaptiveFlowOAuthProvider = {
|
|
112
|
+
id: OAuthProvider | (string & {});
|
|
113
|
+
label: string;
|
|
114
|
+
};
|
|
115
|
+
/** Result returned by lookupByEmail to seed the flow with backend identity state. */
|
|
70
116
|
type IdentityResolution = {
|
|
71
117
|
accountExists: boolean;
|
|
72
118
|
hasPassword?: boolean;
|
|
@@ -74,6 +120,7 @@ type IdentityResolution = {
|
|
|
74
120
|
agreedToTos?: boolean;
|
|
75
121
|
profile?: Partial<AdaptiveContextBase["profile"]>;
|
|
76
122
|
};
|
|
123
|
+
/** Backend adapter contract used by the flow to delegate all side effects. */
|
|
77
124
|
type AdaptiveFlowAdapter<TContext extends AdaptiveContextBase = AdaptiveContextBase> = {
|
|
78
125
|
lookupByEmail?: (email: string) => Promise<IdentityResolution | null>;
|
|
79
126
|
requestOtp?: (email: string) => Promise<void>;
|
|
@@ -85,29 +132,40 @@ type AdaptiveFlowAdapter<TContext extends AdaptiveContextBase = AdaptiveContextB
|
|
|
85
132
|
startOAuth?: (provider: OAuthProvider, context: TContext) => Promise<void>;
|
|
86
133
|
completeOAuth?: (provider: OAuthProvider | null, context: TContext) => Promise<Partial<TContext> | void>;
|
|
87
134
|
};
|
|
135
|
+
/** Named style slots used by the built-in component shell and step renderers. */
|
|
88
136
|
type AdaptiveFlowStyleSlot = "shell" | "headerRow" | "eyebrow" | "title" | "badge" | "success" | "error" | "info" | "caption" | "formRow" | "formColumn" | "input" | "button" | "checkboxRow" | "complete" | "footer" | "oauthButton";
|
|
137
|
+
/** Inline style overrides keyed by the built-in style slots. */
|
|
89
138
|
type AdaptiveFlowStyles = Partial<Record<AdaptiveFlowStyleSlot, React.CSSProperties>>;
|
|
139
|
+
/** CSS class overrides keyed by the built-in style slots. */
|
|
90
140
|
type AdaptiveFlowClassNames = Partial<Record<AdaptiveFlowStyleSlot, string>>;
|
|
141
|
+
/** Minimal storage interface used by persistence drivers. */
|
|
91
142
|
type AdaptiveFlowStorageDriver = Pick<Storage, "getItem" | "setItem" | "removeItem">;
|
|
143
|
+
/** Persistence settings for storing and restoring flow state across reloads. */
|
|
92
144
|
type AdaptiveFlowPersistence<TContext extends AdaptiveContextBase = AdaptiveContextBase> = {
|
|
93
145
|
key: string;
|
|
94
146
|
storage?: "session" | "local" | AdaptiveFlowStorageDriver;
|
|
95
147
|
serialize?: (state: PersistedAdaptiveFlowState<TContext>) => string;
|
|
96
148
|
deserialize?: (value: string) => PersistedAdaptiveFlowState<TContext>;
|
|
97
149
|
clearOnComplete?: boolean;
|
|
150
|
+
onError?: (error: Error, phase: "read" | "write" | "clear") => void;
|
|
98
151
|
};
|
|
152
|
+
/** Persisted flow payload written to session/local/custom storage. */
|
|
99
153
|
type PersistedAdaptiveFlowState<TContext extends AdaptiveContextBase = AdaptiveContextBase> = {
|
|
100
154
|
context: TContext;
|
|
101
155
|
oauthPendingProvider: OAuthProvider | null;
|
|
102
156
|
};
|
|
157
|
+
/** Context wrapper passed into validators so they can inspect the current flow state. */
|
|
103
158
|
type AdaptiveFlowValidationContext<TContext extends AdaptiveContextBase = AdaptiveContextBase> = {
|
|
104
159
|
context: TContext;
|
|
105
160
|
};
|
|
161
|
+
/** Validator failure payload that can target a specific field or the whole form. */
|
|
106
162
|
type AdaptiveFlowValidationIssue = {
|
|
107
163
|
message: string;
|
|
108
164
|
field?: string;
|
|
109
165
|
};
|
|
166
|
+
/** Validator return type supported by the component and hook. */
|
|
110
167
|
type AdaptiveFlowValidationResult = string | AdaptiveFlowValidationIssue | void | Promise<string | AdaptiveFlowValidationIssue | void>;
|
|
168
|
+
/** Schema adapter contract used for optional Zod-friendly validation. */
|
|
111
169
|
type AdaptiveFlowSchema<TValue> = {
|
|
112
170
|
safeParse?: (value: TValue) => {
|
|
113
171
|
success: boolean;
|
|
@@ -121,6 +179,7 @@ type AdaptiveFlowSchema<TValue> = {
|
|
|
121
179
|
};
|
|
122
180
|
parse?: (value: TValue) => unknown;
|
|
123
181
|
};
|
|
182
|
+
/** Optional schema map for built-in step fields. */
|
|
124
183
|
type AdaptiveFlowSchemas = {
|
|
125
184
|
email?: AdaptiveFlowSchema<string>;
|
|
126
185
|
otp?: AdaptiveFlowSchema<string>;
|
|
@@ -128,7 +187,19 @@ type AdaptiveFlowSchemas = {
|
|
|
128
187
|
profile?: AdaptiveFlowSchema<AdaptiveContextBase["profile"]>;
|
|
129
188
|
tos?: AdaptiveFlowSchema<boolean>;
|
|
130
189
|
};
|
|
190
|
+
/** Backoff settings used to retry transient adapter calls and OAuth completion. */
|
|
191
|
+
type AdaptiveFlowRetryPolicy = {
|
|
192
|
+
maxAttempts?: number;
|
|
193
|
+
initialDelayMs?: number;
|
|
194
|
+
factor?: number;
|
|
195
|
+
maxDelayMs?: number;
|
|
196
|
+
jitter?: boolean;
|
|
197
|
+
shouldRetry?: (error: Error, attempt: number) => boolean;
|
|
198
|
+
delay?: (attempt: number) => number;
|
|
199
|
+
};
|
|
200
|
+
/** Field error bag keyed by field path or logical field name. */
|
|
131
201
|
type AdaptiveFlowFieldErrors = Partial<Record<string, string>>;
|
|
202
|
+
/** Validator map for the built-in flow fields. */
|
|
132
203
|
type AdaptiveFlowValidators<TContext extends AdaptiveContextBase = AdaptiveContextBase> = {
|
|
133
204
|
email?: (input: string, payload: AdaptiveFlowValidationContext<TContext>) => AdaptiveFlowValidationResult;
|
|
134
205
|
otp?: (input: string, payload: AdaptiveFlowValidationContext<TContext> & {
|
|
@@ -140,12 +211,14 @@ type AdaptiveFlowValidators<TContext extends AdaptiveContextBase = AdaptiveConte
|
|
|
140
211
|
profile?: (input: AdaptiveContextBase["profile"], payload: AdaptiveFlowValidationContext<TContext>) => AdaptiveFlowValidationResult;
|
|
141
212
|
tos?: (accepted: boolean, payload: AdaptiveFlowValidationContext<TContext>) => AdaptiveFlowValidationResult;
|
|
142
213
|
};
|
|
214
|
+
/** Transition record emitted whenever the evaluated step changes. */
|
|
143
215
|
type AdaptiveStepTransition<TStep extends string = AdaptiveStep> = {
|
|
144
216
|
from: TStep | null;
|
|
145
217
|
to: TStep;
|
|
146
218
|
at: number;
|
|
147
219
|
attempt: number;
|
|
148
220
|
};
|
|
221
|
+
/** Arguments supplied to a stepRegistry renderer for a specific step. */
|
|
149
222
|
type AdaptiveStepRendererArgs<TContext extends AdaptiveContextBase, TRequirement extends string, TStep extends string> = {
|
|
150
223
|
step: TStep;
|
|
151
224
|
context: TContext;
|
|
@@ -160,7 +233,9 @@ type AdaptiveStepRendererArgs<TContext extends AdaptiveContextBase, TRequirement
|
|
|
160
233
|
adapter?: AdaptiveFlowAdapter<TContext>;
|
|
161
234
|
transitions: AdaptiveStepTransition<TStep>[];
|
|
162
235
|
};
|
|
236
|
+
/** Registry that overrides the UI for selected steps. */
|
|
163
237
|
type AdaptiveStepRegistry<TContext extends AdaptiveContextBase, TRequirement extends string, TStep extends string> = Partial<Record<TStep, (args: AdaptiveStepRendererArgs<TContext, TRequirement, TStep>) => React.ReactNode>>;
|
|
238
|
+
/** Arguments supplied to renderStep for full step-body customization. */
|
|
164
239
|
type AdaptiveStepRenderArgs<TContext extends AdaptiveContextBase = AdaptiveContextBase, TRequirement extends string = AppRequirement, TStep extends string = AdaptiveStep> = {
|
|
165
240
|
step: TStep;
|
|
166
241
|
context: TContext;
|
|
@@ -176,6 +251,7 @@ type AdaptiveStepRenderArgs<TContext extends AdaptiveContextBase = AdaptiveConte
|
|
|
176
251
|
adapter?: AdaptiveFlowAdapter<TContext>;
|
|
177
252
|
transitions: AdaptiveStepTransition<TStep>[];
|
|
178
253
|
};
|
|
254
|
+
/** Props accepted by the AdaptiveFlow component. */
|
|
179
255
|
type AdaptiveFlowProps<TContext extends AdaptiveContextBase = AdaptiveContext, TRequirement extends string = AppRequirement, TStep extends string = AdaptiveStep> = {
|
|
180
256
|
adapter?: AdaptiveFlowAdapter<TContext>;
|
|
181
257
|
requirements?: readonly TRequirement[];
|
|
@@ -201,8 +277,12 @@ type AdaptiveFlowProps<TContext extends AdaptiveContextBase = AdaptiveContext, T
|
|
|
201
277
|
persistence?: AdaptiveFlowPersistence<TContext>;
|
|
202
278
|
validators?: AdaptiveFlowValidators<TContext>;
|
|
203
279
|
schemas?: AdaptiveFlowSchemas;
|
|
280
|
+
oauthProviders?: readonly AdaptiveFlowOAuthProvider[];
|
|
281
|
+
retryPolicy?: AdaptiveFlowRetryPolicy;
|
|
204
282
|
};
|
|
283
|
+
/** Options accepted by the headless useAdaptiveFlow hook. */
|
|
205
284
|
type UseAdaptiveFlowOptions<TContext extends AdaptiveContextBase = AdaptiveContext, TRequirement extends string = AppRequirement, TStep extends string = AdaptiveStep> = Omit<AdaptiveFlowProps<TContext, TRequirement, TStep>, "stepTitles" | "renderStep" | "stepRegistry" | "className" | "classNames" | "styles" | "unstyled">;
|
|
285
|
+
/** Result object returned by useAdaptiveFlow. */
|
|
206
286
|
type UseAdaptiveFlowResult<TContext extends AdaptiveContextBase, TRequirement extends string, TStep extends string> = {
|
|
207
287
|
context: TContext;
|
|
208
288
|
step: TStep;
|
|
@@ -223,7 +303,9 @@ type UseAdaptiveFlowResult<TContext extends AdaptiveContextBase, TRequirement ex
|
|
|
223
303
|
handleTos: () => void;
|
|
224
304
|
handleOAuth: (provider: OAuthProvider) => void;
|
|
225
305
|
};
|
|
226
|
-
|
|
227
|
-
declare function
|
|
306
|
+
/** Headless flow hook that owns state, evaluation, persistence, retries, and adapter wiring. */
|
|
307
|
+
declare function useAdaptiveFlow<TContext extends AdaptiveContextBase = AdaptiveContext, TRequirement extends string = AppRequirement, TStep extends string = AdaptiveStep>({ adapter, requirements, requirementGraph, requirementGraphConfig, requirementResolvers, completeStep, initialValue, onComplete, onError, onStepTransition, persistence, validators, schemas, oauthProviders, retryPolicy, }: UseAdaptiveFlowOptions<TContext, TRequirement, TStep>): UseAdaptiveFlowResult<TContext, TRequirement, TStep>;
|
|
308
|
+
/** Default UI wrapper around useAdaptiveFlow that renders the built-in flow shell and step UI. */
|
|
309
|
+
declare function AdaptiveFlow<TContext extends AdaptiveContextBase = AdaptiveContext, TRequirement extends string = AppRequirement, TStep extends string = AdaptiveStep>({ adapter, requirements, requirementGraph, requirementGraphConfig, requirementResolvers, completeStep, stepTitles, renderStep, stepRegistry, initialValue, onComplete, onError, onStepTransition, className, classNames, styles, unstyled, persistence, validators, schemas, oauthProviders, retryPolicy, }: AdaptiveFlowProps<TContext, TRequirement, TStep>): react_jsx_runtime.JSX.Element;
|
|
228
310
|
|
|
229
|
-
export { type AdaptiveContext, type AdaptiveContextBase, AdaptiveFlow, type AdaptiveFlowAdapter, type AdaptiveFlowClassNames, type AdaptiveFlowFieldErrors, type AdaptiveFlowPersistence, type AdaptiveFlowProps, type AdaptiveFlowSchema, type AdaptiveFlowSchemas, type AdaptiveFlowStorageDriver, type AdaptiveFlowStyleSlot, type AdaptiveFlowStyles, type AdaptiveFlowValidationContext, type AdaptiveFlowValidationIssue, type AdaptiveFlowValidationResult, type AdaptiveFlowValidators, type AdaptiveStep, type AdaptiveStepRegistry, type AdaptiveStepRenderArgs, type AdaptiveStepRendererArgs, type AdaptiveStepTransition, type AppRequirement, type DefaultAdaptiveStep, DefaultAdaptiveSteps, type DefaultAppRequirement, DefaultAppRequirements, type IdentityResolution, type MaybePromise, type OAuthProvider, type PersistedAdaptiveFlowState, type RequirementGraph, type RequirementGraphNode, type RequirementResolver, type UseAdaptiveFlowOptions, type UseAdaptiveFlowResult, createDefaultRequirementGraph, createRequirementGraph, defaultRequirementResolvers, defaultRequirements, evaluateNextStep, getMissingRequirements, initialContext, useAdaptiveFlow };
|
|
311
|
+
export { type AdaptiveContext, type AdaptiveContextBase, AdaptiveFlow, type AdaptiveFlowAdapter, type AdaptiveFlowClassNames, type AdaptiveFlowFieldErrors, type AdaptiveFlowOAuthProvider, type AdaptiveFlowPersistence, type AdaptiveFlowProps, type AdaptiveFlowRetryPolicy, type AdaptiveFlowSchema, type AdaptiveFlowSchemas, type AdaptiveFlowStorageDriver, type AdaptiveFlowStyleSlot, type AdaptiveFlowStyles, type AdaptiveFlowValidationContext, type AdaptiveFlowValidationIssue, type AdaptiveFlowValidationResult, type AdaptiveFlowValidators, type AdaptiveStep, type AdaptiveStepRegistry, type AdaptiveStepRenderArgs, type AdaptiveStepRendererArgs, type AdaptiveStepTransition, type AppRequirement, type DefaultAdaptiveStep, DefaultAdaptiveSteps, type DefaultAppRequirement, DefaultAppRequirements, type IdentityResolution, type MaybePromise, type OAuthProvider, type PersistedAdaptiveFlowState, type RequirementGraph, type RequirementGraphNode, type RequirementResolver, type UseAdaptiveFlowOptions, type UseAdaptiveFlowResult, createDefaultRequirementGraph, createRequirementGraph, defaultRequirementResolvers, defaultRequirements, evaluateNextStep, getMissingRequirements, initialContext, useAdaptiveFlow };
|