@asgardeo/react 0.6.0 → 0.6.1
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/dist/cjs/index.js +620 -554
- package/dist/cjs/index.js.map +4 -4
- package/dist/components/factories/FieldFactory.d.ts +4 -0
- package/dist/components/presentation/SignIn/BaseSignIn.d.ts +27 -0
- package/dist/components/presentation/SignIn/SignIn.d.ts +2 -2
- package/dist/components/presentation/SignIn/component-driven/SignInOptionFactory.d.ts +1 -0
- package/dist/components/presentation/SignUp/BaseSignUp.d.ts +0 -4
- package/dist/components/presentation/SignUp/SignUpOptionFactory.d.ts +0 -6
- package/dist/components/presentation/SignUp/transformer.d.ts +75 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +432 -363
- package/dist/index.js.map +4 -4
- package/package.json +3 -3
|
@@ -46,6 +46,10 @@ export interface FieldConfig {
|
|
|
46
46
|
* Callback function when the field value changes.
|
|
47
47
|
*/
|
|
48
48
|
onChange: (value: string) => void;
|
|
49
|
+
/**
|
|
50
|
+
* Callback function when the field loses focus.
|
|
51
|
+
*/
|
|
52
|
+
onBlur?: () => void;
|
|
49
53
|
/**
|
|
50
54
|
* Whether the field is disabled.
|
|
51
55
|
*/
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025, 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 } from 'react';
|
|
19
|
+
import { BaseSignInProps as BaseSignInV1Props } from './non-component-driven/BaseSignIn';
|
|
20
|
+
import { BaseSignInProps as BaseSignInV2Props } from './component-driven/BaseSignIn';
|
|
21
|
+
/**
|
|
22
|
+
* Props for the BaseSignIn component.
|
|
23
|
+
* Extends BaseSignInV1Props & BaseSignInV2Props for full compatibility with both React BaseSignIn components.
|
|
24
|
+
*/
|
|
25
|
+
export type BaseSignInProps = BaseSignInV1Props | BaseSignInV2Props;
|
|
26
|
+
declare const BaseSignIn: FC<BaseSignInProps>;
|
|
27
|
+
export default BaseSignIn;
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
* under the License.
|
|
17
17
|
*/
|
|
18
18
|
import { FC, ReactElement } from 'react';
|
|
19
|
-
import { BaseSignInProps } from './non-component-driven/BaseSignIn';
|
|
19
|
+
import { BaseSignInProps as BaseSignInV1Props } from './non-component-driven/BaseSignIn';
|
|
20
20
|
import { SignInRenderProps } from './component-driven/SignIn';
|
|
21
21
|
/**
|
|
22
22
|
* Props for the SignIn component.
|
|
23
23
|
* Extends BaseSignInProps for full compatibility with the React BaseSignIn component
|
|
24
24
|
*/
|
|
25
|
-
export type SignInProps = Pick<
|
|
25
|
+
export type SignInProps = Pick<BaseSignInV1Props, 'className' | 'onSuccess' | 'onError' | 'variant' | 'size'> & {
|
|
26
26
|
/**
|
|
27
27
|
* Render function for custom UI (render props pattern).
|
|
28
28
|
*/
|
|
@@ -24,6 +24,7 @@ export declare const renderSignInComponents: (components: EmbeddedFlowComponent[
|
|
|
24
24
|
buttonClassName?: string;
|
|
25
25
|
error?: string | null;
|
|
26
26
|
inputClassName?: string;
|
|
27
|
+
onInputBlur?: (name: string) => void;
|
|
27
28
|
onSubmit?: (component: EmbeddedFlowComponent, data?: Record<string, any>) => void;
|
|
28
29
|
size?: "small" | "medium" | "large";
|
|
29
30
|
variant?: any;
|
|
@@ -29,10 +29,6 @@ export interface BaseSignUpOptionProps extends WithPreferences {
|
|
|
29
29
|
* The component configuration from the flow response.
|
|
30
30
|
*/
|
|
31
31
|
component: EmbeddedFlowComponent;
|
|
32
|
-
/**
|
|
33
|
-
* Global error message to display.
|
|
34
|
-
*/
|
|
35
|
-
error?: string | null;
|
|
36
32
|
/**
|
|
37
33
|
* Form validation errors.
|
|
38
34
|
*/
|
|
@@ -80,7 +76,6 @@ export declare const createSignUpComponent: ({ component, onSubmit, ...rest }: B
|
|
|
80
76
|
*/
|
|
81
77
|
export declare const createSignUpOptionFromComponent: (component: EmbeddedFlowComponent, formValues: Record<string, string>, touchedFields: Record<string, boolean>, formErrors: Record<string, string>, isLoading: boolean, isFormValid: boolean, onInputChange: (name: string, value: string) => void, options?: {
|
|
82
78
|
buttonClassName?: string;
|
|
83
|
-
error?: string | null;
|
|
84
79
|
inputClassName?: string;
|
|
85
80
|
key?: string | number;
|
|
86
81
|
onSubmit?: (component: EmbeddedFlowComponent, data?: Record<string, any>) => void;
|
|
@@ -92,7 +87,6 @@ export declare const createSignUpOptionFromComponent: (component: EmbeddedFlowCo
|
|
|
92
87
|
*/
|
|
93
88
|
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?: {
|
|
94
89
|
buttonClassName?: string;
|
|
95
|
-
error?: string | null;
|
|
96
90
|
inputClassName?: string;
|
|
97
91
|
onSubmit?: (component: EmbeddedFlowComponent, data?: Record<string, any>) => void;
|
|
98
92
|
size?: "small" | "medium" | "large";
|
|
@@ -15,14 +15,88 @@
|
|
|
15
15
|
* specific language governing permissions and limitations
|
|
16
16
|
* under the License.
|
|
17
17
|
*/
|
|
18
|
-
import { EmbeddedFlowComponent } from '@asgardeo/browser';
|
|
18
|
+
import { EmbeddedFlowComponent, EmbeddedSignUpFlowErrorResponseV2, EmbeddedFlowExecuteErrorResponse } from '@asgardeo/browser';
|
|
19
19
|
import { UseTranslation } from '../../../hooks/useTranslation';
|
|
20
20
|
/**
|
|
21
21
|
* Transform simple flow response to component-driven format
|
|
22
22
|
*/
|
|
23
23
|
export declare const transformSimpleToComponentDriven: (response: any, t: UseTranslation["t"]) => EmbeddedFlowComponent[];
|
|
24
|
+
/**
|
|
25
|
+
* Extract error message from various error response formats.
|
|
26
|
+
*
|
|
27
|
+
* This function supports multiple error formats from different versions of Asgardeo APIs:
|
|
28
|
+
* - **AsgardeoV2 format**: Uses `failureReason` field from responses with `flowStatus: "ERROR"`
|
|
29
|
+
* - **AsgardeoV1 format**: Uses `description` or `message` fields from responses with error `code`
|
|
30
|
+
* - **AsgardeoAPIError**: Parses JSON from error messages to extract detailed error information
|
|
31
|
+
* - **Standard Error objects**: Falls back to the `message` property
|
|
32
|
+
* - **String errors**: Returns the string as-is
|
|
33
|
+
*
|
|
34
|
+
* @param error - The error object, which can be:
|
|
35
|
+
* - AsgardeoV2 error response: `{ flowStatus: "ERROR", failureReason: string, ... }`
|
|
36
|
+
* - AsgardeoV1 error response: `{ code: string, message?: string, description?: string, ... }`
|
|
37
|
+
* - AsgardeoAPIError instance with JSON message
|
|
38
|
+
* - Standard Error object
|
|
39
|
+
* - String error message
|
|
40
|
+
* @param t - Translation function for fallback error messages
|
|
41
|
+
* @returns Localized error message extracted from the error object
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* // AsgardeoV2 error
|
|
46
|
+
* const v2Error = { flowStatus: "ERROR", failureReason: "User already exists" };
|
|
47
|
+
* const message = extractErrorMessage(v2Error, t); // "User already exists"
|
|
48
|
+
*
|
|
49
|
+
* // AsgardeoV1 error
|
|
50
|
+
* const v1Error = { code: "FEE-60005", description: "Error while provisioning user" };
|
|
51
|
+
* const message = extractErrorMessage(v1Error, t); // "Error while provisioning user"
|
|
52
|
+
*
|
|
53
|
+
* // AsgardeoAPIError
|
|
54
|
+
* const apiError = new AsgardeoAPIError('{"failureReason": "Invalid credentials"}');
|
|
55
|
+
* const message = extractErrorMessage(apiError, t); // "Invalid credentials"
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare const extractErrorMessage: (error: EmbeddedSignUpFlowErrorResponseV2 | EmbeddedFlowExecuteErrorResponse, t: UseTranslation["t"]) => string;
|
|
59
|
+
/**
|
|
60
|
+
* Check if a response is an error response and extract the error message.
|
|
61
|
+
*
|
|
62
|
+
* This function serves as a guard to identify error responses from successful responses
|
|
63
|
+
* in both AsgardeoV1 and AsgardeoV2 API formats. It's particularly useful for flow
|
|
64
|
+
* normalization where error responses should be handled differently from success responses.
|
|
65
|
+
*
|
|
66
|
+
* **Supported Error Response Formats:**
|
|
67
|
+
* - **AsgardeoV2**: Responses with `flowStatus: "ERROR"` and `failureReason`
|
|
68
|
+
* - **AsgardeoV1**: Responses with error `code` and `message`/`description` fields
|
|
69
|
+
*
|
|
70
|
+
* @param response - The API response object to check for error indicators
|
|
71
|
+
* @param t - Translation function for extracting localized error messages
|
|
72
|
+
* @returns `null` if the response is not an error, or the extracted error message string if it is an error
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* // Success response
|
|
77
|
+
* const successResponse = { flowStatus: "INCOMPLETE", data: { components: [] } };
|
|
78
|
+
* const error = checkForErrorResponse(successResponse, t); // null
|
|
79
|
+
*
|
|
80
|
+
* // AsgardeoV2 error response
|
|
81
|
+
* const v2ErrorResponse = {
|
|
82
|
+
* flowStatus: "ERROR",
|
|
83
|
+
* failureReason: "User already exists with the provided username."
|
|
84
|
+
* };
|
|
85
|
+
* const error = checkForErrorResponse(v2ErrorResponse, t); // "User already exists with the provided username."
|
|
86
|
+
*
|
|
87
|
+
* // AsgardeoV1 error response
|
|
88
|
+
* const v1ErrorResponse = {
|
|
89
|
+
* code: "FEE-60005",
|
|
90
|
+
* message: "Error while provisioning user.",
|
|
91
|
+
* description: "Error occurred while provisioning user in the request of flow id: ac57315c-6ca6-49dc-8664-fcdcff354f46"
|
|
92
|
+
* };
|
|
93
|
+
* const error = checkForErrorResponse(v1ErrorResponse, t); // "Error occurred while provisioning user in the request of flow id: ac57315c-6ca6-49dc-8664-fcdcff354f46"
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export declare const checkForErrorResponse: (response: any, t: UseTranslation["t"]) => string | null;
|
|
24
97
|
/**
|
|
25
98
|
* Generic transformer that handles both simple and component-driven responses
|
|
99
|
+
* Also handles AsgardeoV2 error responses that should be thrown as errors
|
|
26
100
|
*/
|
|
27
101
|
export declare const normalizeFlowResponse: (response: any, t: UseTranslation["t"]) => {
|
|
28
102
|
flowId: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -83,8 +83,8 @@ export { default as SignedOut } from './components/control/SignedOut';
|
|
|
83
83
|
export * from './components/control/SignedOut';
|
|
84
84
|
export { default as Loading } from './components/control/Loading';
|
|
85
85
|
export * from './components/control/Loading';
|
|
86
|
-
export { default as BaseSignIn } from './components/presentation/SignIn/
|
|
87
|
-
export * from './components/presentation/SignIn/
|
|
86
|
+
export { default as BaseSignIn } from './components/presentation/SignIn/BaseSignIn';
|
|
87
|
+
export * from './components/presentation/SignIn/BaseSignIn';
|
|
88
88
|
export { default as SignIn } from './components/presentation/SignIn/SignIn';
|
|
89
89
|
export * from './components/presentation/SignIn/SignIn';
|
|
90
90
|
export { default as BaseSignUp } from './components/presentation/SignUp/BaseSignUp';
|