@asgardeo/react 0.14.1 → 0.14.2

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.
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Copyright (c) 2026, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ import { type ConsentPurposeDataV2 as ConsentPurposeData } from '@asgardeo/browser';
19
+ import { FC, ReactNode } from 'react';
20
+ /**
21
+ * Consent purpose structure as expected from the backend.
22
+ * The `essential` and `optional` arrays contain the list of attribute names that fall under
23
+ * each category for the given purpose.
24
+ */
25
+ export interface ConsentPurpose {
26
+ /** Optional human-readable description of the purpose */
27
+ description?: string;
28
+ /** Attributes that are always required and cannot be declined */
29
+ essential?: string[];
30
+ /** Attributes that the user can optionally decline */
31
+ optional?: string[];
32
+ /** Unique identifier for the purpose */
33
+ purpose_id: string;
34
+ /** Name of the purpose to display in the UI */
35
+ purpose_name: string;
36
+ }
37
+ /**
38
+ * Render props exposed by Consent when using the render-prop pattern.
39
+ */
40
+ export interface ConsentRenderProps {
41
+ /** Current form values - used to read optional checkbox state. */
42
+ formValues: Record<string, string>;
43
+ /** Callback invoked when a user toggles an optional attribute. */
44
+ onInputChange: (name: string, value: string) => void;
45
+ /** The resolved list of consent purposes parsed from `consentData`. */
46
+ purposes: ConsentPurposeData[];
47
+ }
48
+ /**
49
+ * Props for the Consent component.
50
+ */
51
+ export interface ConsentProps {
52
+ /**
53
+ * Render-props callback. When provided, the default consent UI is replaced with
54
+ * whatever JSX the callback returns. The parsed `purposes` list is injected so
55
+ * consumers do not need to re-parse `consentData` themselves.
56
+ *
57
+ * @example
58
+ * ```tsx
59
+ * <Consent consentData={raw} formValues={formInputs} onInputChange={onChange} t={t}>
60
+ * {({ purposes, formValues, onInputChange, t }) => (
61
+ * <div>
62
+ * {purposes.map(p => <MyConsentSection key={p.purpose_id} purpose={p} />)}
63
+ * </div>
64
+ * )}
65
+ * </Consent>
66
+ * ```
67
+ */
68
+ children?: (props: ConsentRenderProps) => ReactNode;
69
+ /**
70
+ * The raw JSON string returned by the backend in `additionalData.consentPrompt`.
71
+ */
72
+ consentData?: string | ConsentPurpose[] | {
73
+ purposes: ConsentPurpose[];
74
+ };
75
+ /**
76
+ * Current form values - used to read optional checkbox state.
77
+ */
78
+ formValues: Record<string, string>;
79
+ /**
80
+ * Callback invoked when a user toggles an optional attribute.
81
+ */
82
+ onInputChange: (name: string, value: string) => void;
83
+ }
84
+ /**
85
+ * Consent component renders the list of purposes and their associated attributes (essential and optional)
86
+ * based on the data provided by the backend. It allows users to toggle optional attributes while essential
87
+ * attributes are displayed as read-only.
88
+ */
89
+ declare const Consent: FC<ConsentProps>;
90
+ export default Consent;
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Copyright (c) 2026, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ import { type ConsentPurposeDataV2 as ConsentPurposeData } from '@asgardeo/browser';
19
+ import { FC, ReactNode } from 'react';
20
+ /**
21
+ * Computes the form value key for tracking an optional attribute's consent state.
22
+ *
23
+ * @param purposeId - The ID of the consent purpose.
24
+ * @param attrName - The name of the attribute.
25
+ * @returns A stable form key string.
26
+ */
27
+ export declare const getConsentOptionalKey: (purposeId: string, attrName: string) => string;
28
+ /**
29
+ * ConsentInputVariant defines whether the ConsentCheckboxList is rendering essential (read-only) or
30
+ * optional (toggleable) attributes.
31
+ */
32
+ export type ConsentInputVariant = 'ESSENTIAL' | 'OPTIONAL';
33
+ /**
34
+ * Render props exposed by ConsentCheckboxList when using the render-prop pattern.
35
+ */
36
+ export interface ConsentCheckboxListRenderProps {
37
+ /** The list of attribute names to render. */
38
+ attributes: string[];
39
+ /**
40
+ * Call this when an optional attribute checkbox is toggled.
41
+ * No-op for ESSENTIAL attributes (they cannot be changed).
42
+ */
43
+ handleChange: (attrName: string, checked: boolean) => void;
44
+ /**
45
+ * Returns the current checked state for the given attribute name.
46
+ * Always returns true for ESSENTIAL attributes.
47
+ */
48
+ isChecked: (attrName: string) => boolean;
49
+ /** Whether the list is rendering essential or optional attributes. */
50
+ variant: ConsentInputVariant;
51
+ }
52
+ /**
53
+ * Props for the ConsentCheckboxList component.
54
+ */
55
+ export interface ConsentCheckboxListProps {
56
+ /**
57
+ * Render-props callback. When provided, the default checkbox list UI is replaced
58
+ * with whatever JSX the callback returns.
59
+ *
60
+ * @example
61
+ * ```tsx
62
+ * <ConsentCheckboxList variant="OPTIONAL" purpose={purpose} formValues={formValues} onInputChange={onChange}>
63
+ * {({ attributes, isChecked, handleChange }) => (
64
+ * <ul>
65
+ * {attributes.map(attr => (
66
+ * <li key={attr}>
67
+ * <Checkbox checked={isChecked(attr)} onChange={e => handleChange(attr, e.target.checked)} />
68
+ * {attr}
69
+ * </li>
70
+ * ))}
71
+ * </ul>
72
+ * )}
73
+ * </ConsentCheckboxList>
74
+ * ```
75
+ */
76
+ children?: (props: ConsentCheckboxListRenderProps) => ReactNode;
77
+ /** Current form values - used to read optional checkbox state */
78
+ formValues: Record<string, string>;
79
+ /** Callback invoked when an optional attribute checkbox is toggled */
80
+ onInputChange: (name: string, value: string) => void;
81
+ /** The consent purpose data containing attribute lists */
82
+ purpose: ConsentPurposeData;
83
+ /** Whether to render essential (disabled) or optional (toggleable) attributes */
84
+ variant: ConsentInputVariant;
85
+ }
86
+ /**
87
+ * Renders a list of consent attribute checkboxes.
88
+ *
89
+ * - ESSENTIAL variant: renders read-only checked checkboxes for required attributes.
90
+ * - OPTIONAL variant: renders toggleable checkboxes for optional attributes.
91
+ * Opt-in is the default when no prior form value exists.
92
+ */
93
+ declare const ConsentCheckboxList: FC<ConsentCheckboxListProps>;
94
+ export default ConsentCheckboxList;
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Copyright (c) 2026, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ import { FC, ReactNode } from 'react';
19
+ /**
20
+ * Render props exposed by FlowTimer when using the render-prop pattern.
21
+ */
22
+ export interface FlowTimerRenderProps {
23
+ /** Human-readable formatted time string (e.g. "2:30" or "Timed out"). */
24
+ formattedTime: string;
25
+ /** Whether the timer has expired. */
26
+ isExpired: boolean;
27
+ /** Remaining time in seconds. 0 when expired. */
28
+ remaining: number;
29
+ }
30
+ /**
31
+ * Props for the FlowTimer component.
32
+ */
33
+ export interface FlowTimerProps {
34
+ /**
35
+ * Render-props callback. When provided, the default countdown display is replaced
36
+ * with whatever JSX the callback returns.
37
+ *
38
+ * @example
39
+ * ```tsx
40
+ * <FlowTimer expiresIn={300}>
41
+ * {({ remaining, isExpired, formattedTime }) => (
42
+ * <span style={{ color: isExpired ? 'red' : 'inherit' }}>
43
+ * {isExpired ? 'Session expired' : `Time left: ${formattedTime}`}
44
+ * </span>
45
+ * )}
46
+ * </FlowTimer>
47
+ * ```
48
+ */
49
+ children?: (props: FlowTimerRenderProps) => ReactNode;
50
+ /** Initial number of seconds for the countdown. 0 or negative means no timer. */
51
+ expiresIn?: number;
52
+ /** Text template for the countdown display. Use {time} as a placeholder. */
53
+ textTemplate?: string;
54
+ }
55
+ /**
56
+ * Flow countdown timer component.
57
+ *
58
+ * Displays a countdown from the given number of seconds. When the time expires,
59
+ * shows "Timed out". Returns null if expiresIn <= 0.
60
+ */
61
+ declare const FlowTimer: FC<FlowTimerProps>;
62
+ export default FlowTimer;
@@ -23,8 +23,12 @@ export type AuthType = 'signin' | 'signup';
23
23
  * Processes an array of components and renders them as React elements for sign-in.
24
24
  */
25
25
  export declare const renderSignInComponents: (components: EmbeddedFlowComponent[], formValues: Record<string, string>, touchedFields: Record<string, boolean>, formErrors: Record<string, string>, isLoading: boolean, isFormValid: boolean, onInputChange: (name: string, value: string) => void, options?: {
26
+ /** Additional data from the flow response */
27
+ additionalData?: Record<string, any>;
26
28
  buttonClassName?: string;
27
29
  inputClassName?: string;
30
+ /** Flag to determine if the step timeline has expired */
31
+ isTimeoutDisabled?: boolean;
28
32
  /** Flow metadata for resolving {{meta(...)}} expressions at render time */
29
33
  meta?: FlowMetadataResponse | null;
30
34
  onInputBlur?: (name: string) => void;
@@ -38,6 +42,8 @@ export declare const renderSignInComponents: (components: EmbeddedFlowComponent[
38
42
  * Processes an array of components and renders them as React elements for sign-up.
39
43
  */
40
44
  export declare const renderSignUpComponents: (components: EmbeddedFlowComponent[], formValues: Record<string, string>, touchedFields: Record<string, boolean>, formErrors: Record<string, string>, isLoading: boolean, isFormValid: boolean, onInputChange: (name: string, value: string) => void, options?: {
45
+ /** Additional data from the flow response */
46
+ additionalData?: Record<string, any>;
41
47
  buttonClassName?: string;
42
48
  inputClassName?: string;
43
49
  /** Flow metadata for resolving {{meta(...)}} expressions at render time */
@@ -54,6 +60,8 @@ export declare const renderSignUpComponents: (components: EmbeddedFlowComponent[
54
60
  * This is used by both InviteUser and AcceptInvite components.
55
61
  */
56
62
  export declare const renderInviteUserComponents: (components: EmbeddedFlowComponent[], formValues: Record<string, string>, touchedFields: Record<string, boolean>, formErrors: Record<string, string>, isLoading: boolean, isFormValid: boolean, onInputChange: (name: string, value: string) => void, options?: {
63
+ /** Additional data from the flow response */
64
+ additionalData?: Record<string, any>;
57
65
  buttonClassName?: string;
58
66
  inputClassName?: string;
59
67
  /** Flow metadata for resolving {{meta(...)}} expressions at render time */
@@ -46,6 +46,10 @@ export interface BaseSignInRenderProps {
46
46
  * Loading state
47
47
  */
48
48
  isLoading: boolean;
49
+ /**
50
+ * Flag indicating if the step timer has reached zero
51
+ */
52
+ isTimeoutDisabled?: boolean;
49
53
  /**
50
54
  * Whether the form is valid
51
55
  */
@@ -89,6 +93,10 @@ export interface BaseSignInRenderProps {
89
93
  * Props for the BaseSignIn component.
90
94
  */
91
95
  export interface BaseSignInProps {
96
+ /**
97
+ * Additional data from the flow response.
98
+ */
99
+ additionalData?: Record<string, any>;
92
100
  /**
93
101
  * Custom CSS class name for the submit button.
94
102
  */
@@ -121,6 +129,10 @@ export interface BaseSignInProps {
121
129
  * Flag to determine if the component is ready to be rendered.
122
130
  */
123
131
  isLoading?: boolean;
132
+ /**
133
+ * Timer flag disabling actions
134
+ */
135
+ isTimeoutDisabled?: boolean;
124
136
  /**
125
137
  * Custom CSS class name for info messages.
126
138
  */
@@ -22,6 +22,11 @@ import { BaseSignInProps } from './BaseSignIn';
22
22
  * Render props function parameters
23
23
  */
24
24
  export interface SignInRenderProps {
25
+ /**
26
+ * Additional data from the flow response containing contextual information
27
+ * like consent prompt details and session timeouts.
28
+ */
29
+ additionalData?: Record<string, any>;
25
30
  /**
26
31
  * Current flow components
27
32
  */
@@ -42,6 +47,11 @@ export interface SignInRenderProps {
42
47
  * Loading state indicator
43
48
  */
44
49
  isLoading: boolean;
50
+ /**
51
+ * Flag indicating whether the flow step timeout has expired.
52
+ * Consuming components can use this to disable submit buttons.
53
+ */
54
+ isTimeoutDisabled?: boolean;
45
55
  /**
46
56
  * Flow metadata returned by the platform (v2 only). `null` while loading or unavailable.
47
57
  */
package/dist/index.d.ts CHANGED
@@ -99,6 +99,12 @@ export { default as SmsOtp } from './components/presentation/auth/SignIn/v1/opti
99
99
  export { default as SocialButton } from './components/presentation/auth/SignIn/v1/options/SocialButton';
100
100
  export { default as MultiOptionButton } from './components/presentation/auth/SignIn/v1/options/MultiOptionButton';
101
101
  export * from './components/presentation/auth/SignIn/v1/options/SignInOptionFactory';
102
+ export { default as FlowTimer } from './components/adapters/FlowTimer';
103
+ export * from './components/adapters/FlowTimer';
104
+ export { default as ConsentCheckboxList } from './components/adapters/ConsentCheckboxList';
105
+ export * from './components/adapters/ConsentCheckboxList';
106
+ export { default as Consent } from './components/adapters/Consent';
107
+ export * from './components/adapters/Consent';
102
108
  export { default as BaseUser } from './components/presentation/User/BaseUser';
103
109
  export * from './components/presentation/User/BaseUser';
104
110
  export { default as User } from './components/presentation/User/User';