@asgardeo/react 0.6.26 → 0.6.27

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 CHANGED
@@ -7300,6 +7300,9 @@ var extractErrorMessage = (error, t, defaultErrorKey = "errors.flow.generic") =>
7300
7300
  if (error && typeof error === "object" && error.failureReason) {
7301
7301
  return error.failureReason;
7302
7302
  }
7303
+ if (error instanceof Error && error.message) {
7304
+ return error.message;
7305
+ }
7303
7306
  return t(defaultErrorKey);
7304
7307
  };
7305
7308
  var checkForErrorResponse = (response, t, defaultErrorKey = "errors.flow.generic") => {
@@ -7395,6 +7398,7 @@ var BaseSignInContent2 = ({
7395
7398
  components = [],
7396
7399
  onSubmit,
7397
7400
  onError,
7401
+ error: externalError,
7398
7402
  className = "",
7399
7403
  inputClassName = "",
7400
7404
  buttonClassName = "",
@@ -7413,10 +7417,12 @@ var BaseSignInContent2 = ({
7413
7417
  const { subtitle: flowSubtitle, title: flowTitle, messages: flowMessages, addMessage, clearMessages } = useFlow_default();
7414
7418
  const styles = BaseSignIn_styles_default(theme, theme.vars.colors.text.primary);
7415
7419
  const [isSubmitting, setIsSubmitting] = (0, import_react58.useState)(false);
7420
+ const [apiError, setApiError] = (0, import_react58.useState)(null);
7416
7421
  const isLoading = externalIsLoading || isSubmitting;
7417
7422
  const handleError = (0, import_react58.useCallback)(
7418
7423
  (error) => {
7419
- const errorMessage = extractErrorMessage(error, t);
7424
+ const errorMessage = error?.failureReason || extractErrorMessage(error, t);
7425
+ setApiError(error instanceof Error ? error : new Error(errorMessage));
7420
7426
  clearMessages();
7421
7427
  addMessage({
7422
7428
  type: "error",
@@ -7430,7 +7436,7 @@ var BaseSignInContent2 = ({
7430
7436
  const fields = [];
7431
7437
  const processComponents = (comps) => {
7432
7438
  comps.forEach((component) => {
7433
- if (component.type === "TEXT_INPUT" || component.type === "PASSWORD_INPUT") {
7439
+ if (component.type === "TEXT_INPUT" || component.type === "PASSWORD_INPUT" || component.type === "EMAIL_INPUT") {
7434
7440
  const identifier = component.ref;
7435
7441
  fields.push({
7436
7442
  name: identifier,
@@ -7440,6 +7446,9 @@ var BaseSignInContent2 = ({
7440
7446
  if (component.required && (!value || value.trim() === "")) {
7441
7447
  return t("validations.required.field.error");
7442
7448
  }
7449
+ if ((component.type === "EMAIL_INPUT" || component.variant === "EMAIL") && value && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)) {
7450
+ return t("field.email.invalid");
7451
+ }
7443
7452
  return null;
7444
7453
  }
7445
7454
  });
@@ -7487,6 +7496,7 @@ var BaseSignInContent2 = ({
7487
7496
  }
7488
7497
  }
7489
7498
  setIsSubmitting(true);
7499
+ setApiError(null);
7490
7500
  clearMessages();
7491
7501
  console.log("Submitting component:", component, "with data:", data);
7492
7502
  try {
@@ -7573,14 +7583,18 @@ var BaseSignInContent2 = ({
7573
7583
  if (children) {
7574
7584
  const renderProps = {
7575
7585
  values: formValues,
7576
- errors: formErrors,
7586
+ fieldErrors: formErrors,
7587
+ error: apiError,
7577
7588
  touched: touchedFields,
7578
7589
  isValid: isFormValid,
7579
7590
  isLoading,
7580
7591
  components,
7581
7592
  handleInputChange,
7582
7593
  handleSubmit,
7583
- validateForm,
7594
+ validateForm: () => {
7595
+ const result = validateForm();
7596
+ return { isValid: result.isValid, fieldErrors: result.errors };
7597
+ },
7584
7598
  title: flowTitle || t("signin.heading"),
7585
7599
  subtitle: flowSubtitle || t("signin.subheading"),
7586
7600
  messages: flowMessages || []
@@ -7606,6 +7620,7 @@ var BaseSignInContent2 = ({
7606
7620
  showSubtitle && /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(Typography_default, { variant: "body1", className: styles.subtitle, children: subtitle })
7607
7621
  ] }),
7608
7622
  /* @__PURE__ */ (0, import_jsx_runtime56.jsxs)(Card_default.Content, { children: [
7623
+ externalError && /* @__PURE__ */ (0, import_jsx_runtime56.jsx)("div", { className: styles.flowMessagesContainer, children: /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(Alert_default, { variant: "error", className: (0, import_css36.cx)(styles.flowMessageItem, messageClasses), children: /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(Alert_default.Description, { children: externalError.message }) }) }),
7609
7624
  flowMessages && flowMessages.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime56.jsx)("div", { className: styles.flowMessagesContainer, children: flowMessages.map((message, index) => /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(
7610
7625
  Alert_default,
7611
7626
  {
@@ -7705,7 +7720,6 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7705
7720
  window?.history?.replaceState({}, "", url.toString());
7706
7721
  };
7707
7722
  const handleOAuthError = (error, errorDescription) => {
7708
- console.warn("[SignIn] OAuth error detected:", error);
7709
7723
  clearFlowState();
7710
7724
  const errorMessage = errorDescription || `OAuth error: ${error}`;
7711
7725
  const err = new import_browser48.AsgardeoRuntimeError(errorMessage, "SIGN_IN_ERROR", "react");
@@ -7791,9 +7805,8 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7791
7805
  } catch (error) {
7792
7806
  const err = error;
7793
7807
  clearFlowState();
7794
- const errorMessage = err instanceof Error ? err.message : String(err);
7795
- const displayError = new import_browser48.AsgardeoRuntimeError(errorMessage, "SIGN_IN_ERROR", "react");
7796
- setError(displayError);
7808
+ const errorMessage = err?.failureReason || (err instanceof Error ? err.message : String(err));
7809
+ setError(new Error(errorMessage));
7797
7810
  initializationAttemptedRef.current = false;
7798
7811
  return;
7799
7812
  }
@@ -7801,10 +7814,6 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7801
7814
  const handleSubmit = async (payload) => {
7802
7815
  const effectiveFlowId = payload.flowId || currentFlowId;
7803
7816
  if (!effectiveFlowId) {
7804
- console.error("[SignIn] handleSubmit - ERROR: No flowId available", {
7805
- payloadFlowId: payload.flowId,
7806
- currentFlowId
7807
- });
7808
7817
  throw new Error("No active flow ID");
7809
7818
  }
7810
7819
  try {
@@ -7817,18 +7826,17 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7817
7826
  if (handleRedirection(response)) {
7818
7827
  return;
7819
7828
  }
7820
- const { flowId, components: components2 } = normalizeFlowResponse(response, t, {
7829
+ const { flowId, components: components2, ...rest } = normalizeFlowResponse(response, t, {
7821
7830
  resolveTranslations: !children
7822
7831
  });
7823
7832
  if (response.flowStatus === import_browser48.EmbeddedSignInFlowStatusV2.Error) {
7824
- console.error("[SignIn] Flow returned Error status, clearing flow state");
7825
7833
  clearFlowState();
7826
7834
  const failureReason = response?.failureReason;
7827
7835
  const errorMessage = failureReason || "Authentication flow failed. Please try again.";
7828
- const err = new import_browser48.AsgardeoRuntimeError(errorMessage, "SIGN_IN_ERROR", "react");
7836
+ const err = new Error(errorMessage);
7829
7837
  setError(err);
7830
7838
  cleanupFlowUrlParams();
7831
- return;
7839
+ throw err;
7832
7840
  }
7833
7841
  if (response.flowStatus === import_browser48.EmbeddedSignInFlowStatusV2.Complete) {
7834
7842
  const redirectUrl = response?.redirectUrl || response?.redirect_uri;
@@ -7845,8 +7853,6 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7845
7853
  });
7846
7854
  if (finalRedirectUrl && window?.location) {
7847
7855
  window.location.href = finalRedirectUrl;
7848
- } else {
7849
- console.warn("[SignIn] Flow completed but no redirect URL available");
7850
7856
  }
7851
7857
  return;
7852
7858
  }
@@ -7859,16 +7865,14 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7859
7865
  } catch (error) {
7860
7866
  const err = error;
7861
7867
  clearFlowState();
7862
- const errorMessage = err instanceof Error ? err.message : String(err);
7863
- const displayError = new import_browser48.AsgardeoRuntimeError(errorMessage, "SIGN_IN_ERROR", "react");
7864
- setError(displayError);
7868
+ const errorMessage = err?.failureReason || (err instanceof Error ? err.message : String(err));
7869
+ setError(new Error(errorMessage));
7865
7870
  return;
7866
7871
  } finally {
7867
7872
  setIsSubmitting(false);
7868
7873
  }
7869
7874
  };
7870
7875
  const handleError = (error) => {
7871
- console.error("Authentication error:", error);
7872
7876
  setError(error);
7873
7877
  };
7874
7878
  (0, import_react59.useEffect)(() => {
@@ -7898,7 +7902,6 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7898
7902
  }
7899
7903
  };
7900
7904
  handleSubmit(submitPayload).catch((error) => {
7901
- console.error("[SignIn] OAuth callback submission failed:", error);
7902
7905
  cleanupOAuthUrlParams(true);
7903
7906
  });
7904
7907
  }, [isFlowInitialized, currentFlowId, isInitialized, isLoading, isSubmitting, signIn]);
@@ -7920,6 +7923,7 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7920
7923
  isLoading: isLoading || !isInitialized || !isFlowInitialized,
7921
7924
  onSubmit: handleSubmit,
7922
7925
  onError: handleError,
7926
+ error: flowError,
7923
7927
  className,
7924
7928
  size,
7925
7929
  variant
@@ -9133,6 +9137,7 @@ var BaseSignUpContent2 = ({
9133
9137
  onError,
9134
9138
  onFlowChange,
9135
9139
  onComplete,
9140
+ error: externalError,
9136
9141
  className = "",
9137
9142
  inputClassName = "",
9138
9143
  buttonClassName = "",
@@ -9152,7 +9157,8 @@ var BaseSignUpContent2 = ({
9152
9157
  const styles = BaseSignUp_styles_default(theme, colorScheme);
9153
9158
  const handleError = (0, import_react62.useCallback)(
9154
9159
  (error) => {
9155
- const errorMessage = extractErrorMessage(error, t);
9160
+ const errorMessage = error?.failureReason || extractErrorMessage(error, t);
9161
+ setApiError(error instanceof Error ? error : new Error(errorMessage));
9156
9162
  clearMessages();
9157
9163
  addMessage({
9158
9164
  type: "error",
@@ -9164,7 +9170,7 @@ var BaseSignUpContent2 = ({
9164
9170
  const [isLoading, setIsLoading] = (0, import_react62.useState)(false);
9165
9171
  const [isFlowInitialized, setIsFlowInitialized] = (0, import_react62.useState)(false);
9166
9172
  const [currentFlow, setCurrentFlow] = (0, import_react62.useState)(null);
9167
- const [formData, setFormData] = (0, import_react62.useState)({});
9173
+ const [apiError, setApiError] = (0, import_react62.useState)(null);
9168
9174
  const initializationAttemptedRef = (0, import_react62.useRef)(false);
9169
9175
  const normalizeFlowResponseLocal = (0, import_react62.useCallback)(
9170
9176
  (response) => {
@@ -9197,7 +9203,7 @@ var BaseSignUpContent2 = ({
9197
9203
  const fields = [];
9198
9204
  const processComponents = (comps) => {
9199
9205
  comps.forEach((component) => {
9200
- if (component.type === import_browser59.EmbeddedFlowComponentTypeV2.TextInput) {
9206
+ if (component.type === import_browser59.EmbeddedFlowComponentTypeV2.TextInput || component.type === import_browser59.EmbeddedFlowComponentTypeV2.PasswordInput || component.type === import_browser59.EmbeddedFlowComponentTypeV2.EmailInput) {
9201
9207
  const fieldName = component.ref || component.id;
9202
9208
  fields.push({
9203
9209
  name: fieldName,
@@ -9207,12 +9213,9 @@ var BaseSignUpContent2 = ({
9207
9213
  if (component.required && (!value || value.trim() === "")) {
9208
9214
  return t("validations.required.field.error");
9209
9215
  }
9210
- if (component.variant === "EMAIL" && value && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)) {
9216
+ if ((component.type === import_browser59.EmbeddedFlowComponentTypeV2.EmailInput || component.variant === "EMAIL") && value && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)) {
9211
9217
  return t("field.email.invalid");
9212
9218
  }
9213
- if (component.type === "PASSWORD_INPUT" && value && value.length < 8) {
9214
- return t("field.password.weak");
9215
- }
9216
9219
  return null;
9217
9220
  }
9218
9221
  });
@@ -9232,7 +9235,7 @@ var BaseSignUpContent2 = ({
9232
9235
  initialValues: {},
9233
9236
  fields: formFields,
9234
9237
  validateOnBlur: true,
9235
- validateOnChange: true,
9238
+ validateOnChange: false,
9236
9239
  requiredMessage: t("validations.required.field.error")
9237
9240
  });
9238
9241
  const {
@@ -9264,6 +9267,8 @@ var BaseSignUpContent2 = ({
9264
9267
  );
9265
9268
  const handleInputChange = (name, value) => {
9266
9269
  setFormValue(name, value);
9270
+ };
9271
+ const handleInputBlur = (name) => {
9267
9272
  setFormTouched(name, true);
9268
9273
  };
9269
9274
  const handleSubmit = async (component, data, skipValidation) => {
@@ -9278,6 +9283,7 @@ var BaseSignUpContent2 = ({
9278
9283
  }
9279
9284
  }
9280
9285
  setIsLoading(true);
9286
+ setApiError(null);
9281
9287
  clearMessages();
9282
9288
  try {
9283
9289
  const filteredInputs = {};
@@ -9291,7 +9297,7 @@ var BaseSignUpContent2 = ({
9291
9297
  const payload = {
9292
9298
  ...currentFlow.flowId && { flowId: currentFlow.flowId },
9293
9299
  flowType: currentFlow.flowType || "REGISTRATION",
9294
- ...component.id && { actionId: component.id },
9300
+ ...component.id && { action: component.id },
9295
9301
  inputs: filteredInputs
9296
9302
  };
9297
9303
  const rawResponse = await onSubmit(payload);
@@ -9340,7 +9346,7 @@ var BaseSignUpContent2 = ({
9340
9346
  code,
9341
9347
  state
9342
9348
  },
9343
- actionId: ""
9349
+ action: ""
9344
9350
  };
9345
9351
  try {
9346
9352
  const continueResponse = await onSubmit(payload);
@@ -9400,7 +9406,7 @@ var BaseSignUpContent2 = ({
9400
9406
  code,
9401
9407
  state
9402
9408
  },
9403
- actionId: ""
9409
+ action: ""
9404
9410
  };
9405
9411
  try {
9406
9412
  const continueResponse = await onSubmit(payload);
@@ -9467,6 +9473,7 @@ var BaseSignUpContent2 = ({
9467
9473
  {
9468
9474
  buttonClassName: buttonClasses,
9469
9475
  inputClassName: inputClasses,
9476
+ onInputBlur: handleInputBlur,
9470
9477
  onSubmit: handleSubmit,
9471
9478
  size,
9472
9479
  variant
@@ -9482,7 +9489,8 @@ var BaseSignUpContent2 = ({
9482
9489
  variant,
9483
9490
  inputClasses,
9484
9491
  buttonClasses,
9485
- handleSubmit
9492
+ handleSubmit,
9493
+ handleInputBlur
9486
9494
  ]
9487
9495
  );
9488
9496
  const getUrlParams = () => {
@@ -9502,6 +9510,7 @@ var BaseSignUpContent2 = ({
9502
9510
  initializationAttemptedRef.current = true;
9503
9511
  (async () => {
9504
9512
  setIsLoading(true);
9513
+ setApiError(null);
9505
9514
  clearMessages();
9506
9515
  try {
9507
9516
  const rawResponse = await onInitialize();
@@ -9539,14 +9548,18 @@ var BaseSignUpContent2 = ({
9539
9548
  if (children) {
9540
9549
  const renderProps = {
9541
9550
  values: formValues,
9542
- errors: formErrors,
9551
+ fieldErrors: formErrors,
9552
+ error: apiError,
9543
9553
  touched: touchedFields,
9544
9554
  isValid: isFormValid,
9545
9555
  isLoading,
9546
9556
  components: currentFlow?.data?.components || [],
9547
9557
  handleInputChange,
9548
9558
  handleSubmit,
9549
- validateForm,
9559
+ validateForm: () => {
9560
+ const result = validateForm();
9561
+ return { isValid: result.isValid, fieldErrors: result.errors };
9562
+ },
9550
9563
  title: flowTitle || t("signup.heading"),
9551
9564
  subtitle: flowSubtitle || t("signup.subheading"),
9552
9565
  messages: flowMessages || []
@@ -9576,6 +9589,7 @@ var BaseSignUpContent2 = ({
9576
9589
  showSubtitle && /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(Typography_default, { variant: "body1", className: styles.subtitle, children: subtitle })
9577
9590
  ] }),
9578
9591
  /* @__PURE__ */ (0, import_jsx_runtime68.jsxs)(Card_default.Content, { children: [
9592
+ externalError && /* @__PURE__ */ (0, import_jsx_runtime68.jsx)("div", { className: styles.flowMessagesContainer, children: /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(Alert_default, { variant: "error", className: (0, import_css39.cx)(styles.flowMessageItem, messageClasses), children: /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(Alert_default.Description, { children: externalError.message }) }) }),
9579
9593
  flowMessages && flowMessages.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime68.jsx)("div", { className: styles.flowMessagesContainer, children: flowMessages.map((message, index) => /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(
9580
9594
  Alert_default,
9581
9595
  {