@asgardeo/react 0.6.25 → 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
@@ -7042,9 +7042,6 @@ var matchesSocialProvider = (actionId, eventType, buttonText, provider, authType
7042
7042
  };
7043
7043
  var createAuthComponentFromFlow = (component, formValues, touchedFields, formErrors, isLoading, isFormValid, onInputChange, authType, options = {}) => {
7044
7044
  const key = options.key || component.id;
7045
- if (authType === "signin") {
7046
- console.log("Creating sign-in component for:", component);
7047
- }
7048
7045
  switch (component.type) {
7049
7046
  case import_browser45.EmbeddedFlowComponentTypeV2.TextInput:
7050
7047
  case import_browser45.EmbeddedFlowComponentTypeV2.PasswordInput:
@@ -7078,9 +7075,7 @@ var createAuthComponentFromFlow = (component, formValues, touchedFields, formErr
7078
7075
  if (options.onSubmit) {
7079
7076
  const formData = {};
7080
7077
  Object.keys(formValues).forEach((field) => {
7081
- if (formValues[field]) {
7082
- formData[field] = formValues[field];
7083
- }
7078
+ formData[field] = formValues[field];
7084
7079
  });
7085
7080
  options.onSubmit(component, formData, shouldSkipValidation);
7086
7081
  }
@@ -7248,17 +7243,66 @@ var resolveTranslationsInArray = (items, t, properties) => {
7248
7243
  var resolveTranslationsInArray_default = resolveTranslationsInArray;
7249
7244
 
7250
7245
  // src/utils/v2/flowTransformer.ts
7246
+ var createInputRefMapping = (response) => {
7247
+ const mapping = /* @__PURE__ */ new Map();
7248
+ if (response?.data?.inputs && Array.isArray(response.data.inputs)) {
7249
+ response.data.inputs.forEach((input) => {
7250
+ if (input.ref && input.identifier) {
7251
+ mapping.set(input.ref, input.identifier);
7252
+ }
7253
+ });
7254
+ }
7255
+ return mapping;
7256
+ };
7257
+ var createActionRefMapping = (response) => {
7258
+ const mapping = /* @__PURE__ */ new Map();
7259
+ if (response?.data?.actions && Array.isArray(response.data.actions)) {
7260
+ response.data.actions.forEach((action) => {
7261
+ if (action.ref && action.nextNode) {
7262
+ mapping.set(action.ref, action.nextNode);
7263
+ }
7264
+ });
7265
+ }
7266
+ return mapping;
7267
+ };
7268
+ var applyInputRefMapping = (components, refMapping, actionMapping) => {
7269
+ return components.map((component) => {
7270
+ const transformedComponent = { ...component };
7271
+ if (transformedComponent.ref && refMapping.has(transformedComponent.ref)) {
7272
+ transformedComponent.ref = refMapping.get(transformedComponent.ref);
7273
+ }
7274
+ if (transformedComponent.type === "ACTION" && transformedComponent.id && actionMapping.has(transformedComponent.id)) {
7275
+ transformedComponent.actionRef = actionMapping.get(transformedComponent.id);
7276
+ }
7277
+ if (transformedComponent.components && Array.isArray(transformedComponent.components)) {
7278
+ transformedComponent.components = applyInputRefMapping(
7279
+ transformedComponent.components,
7280
+ refMapping,
7281
+ actionMapping
7282
+ );
7283
+ }
7284
+ return transformedComponent;
7285
+ });
7286
+ };
7251
7287
  var transformComponents = (response, t, resolveTranslations = true) => {
7252
7288
  if (!response?.data?.meta?.components) {
7253
7289
  return [];
7254
7290
  }
7255
- const components = response.data.meta.components;
7291
+ let components = response.data.meta.components;
7292
+ const refMapping = createInputRefMapping(response);
7293
+ const actionMapping = createActionRefMapping(response);
7294
+ if (refMapping.size > 0 || actionMapping.size > 0) {
7295
+ components = applyInputRefMapping(components, refMapping, actionMapping);
7296
+ }
7256
7297
  return resolveTranslations ? resolveTranslationsInArray_default(components, t) : components;
7257
7298
  };
7258
7299
  var extractErrorMessage = (error, t, defaultErrorKey = "errors.flow.generic") => {
7259
7300
  if (error && typeof error === "object" && error.failureReason) {
7260
7301
  return error.failureReason;
7261
7302
  }
7303
+ if (error instanceof Error && error.message) {
7304
+ return error.message;
7305
+ }
7262
7306
  return t(defaultErrorKey);
7263
7307
  };
7264
7308
  var checkForErrorResponse = (response, t, defaultErrorKey = "errors.flow.generic") => {
@@ -7354,6 +7398,7 @@ var BaseSignInContent2 = ({
7354
7398
  components = [],
7355
7399
  onSubmit,
7356
7400
  onError,
7401
+ error: externalError,
7357
7402
  className = "",
7358
7403
  inputClassName = "",
7359
7404
  buttonClassName = "",
@@ -7372,10 +7417,12 @@ var BaseSignInContent2 = ({
7372
7417
  const { subtitle: flowSubtitle, title: flowTitle, messages: flowMessages, addMessage, clearMessages } = useFlow_default();
7373
7418
  const styles = BaseSignIn_styles_default(theme, theme.vars.colors.text.primary);
7374
7419
  const [isSubmitting, setIsSubmitting] = (0, import_react58.useState)(false);
7420
+ const [apiError, setApiError] = (0, import_react58.useState)(null);
7375
7421
  const isLoading = externalIsLoading || isSubmitting;
7376
7422
  const handleError = (0, import_react58.useCallback)(
7377
7423
  (error) => {
7378
- const errorMessage = extractErrorMessage(error, t);
7424
+ const errorMessage = error?.failureReason || extractErrorMessage(error, t);
7425
+ setApiError(error instanceof Error ? error : new Error(errorMessage));
7379
7426
  clearMessages();
7380
7427
  addMessage({
7381
7428
  type: "error",
@@ -7389,7 +7436,7 @@ var BaseSignInContent2 = ({
7389
7436
  const fields = [];
7390
7437
  const processComponents = (comps) => {
7391
7438
  comps.forEach((component) => {
7392
- if (component.type === "TEXT_INPUT" || component.type === "PASSWORD_INPUT") {
7439
+ if (component.type === "TEXT_INPUT" || component.type === "PASSWORD_INPUT" || component.type === "EMAIL_INPUT") {
7393
7440
  const identifier = component.ref;
7394
7441
  fields.push({
7395
7442
  name: identifier,
@@ -7399,6 +7446,9 @@ var BaseSignInContent2 = ({
7399
7446
  if (component.required && (!value || value.trim() === "")) {
7400
7447
  return t("validations.required.field.error");
7401
7448
  }
7449
+ if ((component.type === "EMAIL_INPUT" || component.variant === "EMAIL") && value && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)) {
7450
+ return t("field.email.invalid");
7451
+ }
7402
7452
  return null;
7403
7453
  }
7404
7454
  });
@@ -7446,6 +7496,7 @@ var BaseSignInContent2 = ({
7446
7496
  }
7447
7497
  }
7448
7498
  setIsSubmitting(true);
7499
+ setApiError(null);
7449
7500
  clearMessages();
7450
7501
  console.log("Submitting component:", component, "with data:", data);
7451
7502
  try {
@@ -7532,14 +7583,18 @@ var BaseSignInContent2 = ({
7532
7583
  if (children) {
7533
7584
  const renderProps = {
7534
7585
  values: formValues,
7535
- errors: formErrors,
7586
+ fieldErrors: formErrors,
7587
+ error: apiError,
7536
7588
  touched: touchedFields,
7537
7589
  isValid: isFormValid,
7538
7590
  isLoading,
7539
7591
  components,
7540
7592
  handleInputChange,
7541
7593
  handleSubmit,
7542
- validateForm,
7594
+ validateForm: () => {
7595
+ const result = validateForm();
7596
+ return { isValid: result.isValid, fieldErrors: result.errors };
7597
+ },
7543
7598
  title: flowTitle || t("signin.heading"),
7544
7599
  subtitle: flowSubtitle || t("signin.subheading"),
7545
7600
  messages: flowMessages || []
@@ -7565,6 +7620,7 @@ var BaseSignInContent2 = ({
7565
7620
  showSubtitle && /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(Typography_default, { variant: "body1", className: styles.subtitle, children: subtitle })
7566
7621
  ] }),
7567
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 }) }) }),
7568
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)(
7569
7625
  Alert_default,
7570
7626
  {
@@ -7664,7 +7720,6 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7664
7720
  window?.history?.replaceState({}, "", url.toString());
7665
7721
  };
7666
7722
  const handleOAuthError = (error, errorDescription) => {
7667
- console.warn("[SignIn] OAuth error detected:", error);
7668
7723
  clearFlowState();
7669
7724
  const errorMessage = errorDescription || `OAuth error: ${error}`;
7670
7725
  const err = new import_browser48.AsgardeoRuntimeError(errorMessage, "SIGN_IN_ERROR", "react");
@@ -7750,9 +7805,8 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7750
7805
  } catch (error) {
7751
7806
  const err = error;
7752
7807
  clearFlowState();
7753
- const errorMessage = err instanceof Error ? err.message : String(err);
7754
- const displayError = new import_browser48.AsgardeoRuntimeError(errorMessage, "SIGN_IN_ERROR", "react");
7755
- setError(displayError);
7808
+ const errorMessage = err?.failureReason || (err instanceof Error ? err.message : String(err));
7809
+ setError(new Error(errorMessage));
7756
7810
  initializationAttemptedRef.current = false;
7757
7811
  return;
7758
7812
  }
@@ -7760,10 +7814,6 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7760
7814
  const handleSubmit = async (payload) => {
7761
7815
  const effectiveFlowId = payload.flowId || currentFlowId;
7762
7816
  if (!effectiveFlowId) {
7763
- console.error("[SignIn] handleSubmit - ERROR: No flowId available", {
7764
- payloadFlowId: payload.flowId,
7765
- currentFlowId
7766
- });
7767
7817
  throw new Error("No active flow ID");
7768
7818
  }
7769
7819
  try {
@@ -7776,18 +7826,17 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7776
7826
  if (handleRedirection(response)) {
7777
7827
  return;
7778
7828
  }
7779
- const { flowId, components: components2 } = normalizeFlowResponse(response, t, {
7829
+ const { flowId, components: components2, ...rest } = normalizeFlowResponse(response, t, {
7780
7830
  resolveTranslations: !children
7781
7831
  });
7782
7832
  if (response.flowStatus === import_browser48.EmbeddedSignInFlowStatusV2.Error) {
7783
- console.error("[SignIn] Flow returned Error status, clearing flow state");
7784
7833
  clearFlowState();
7785
7834
  const failureReason = response?.failureReason;
7786
7835
  const errorMessage = failureReason || "Authentication flow failed. Please try again.";
7787
- const err = new import_browser48.AsgardeoRuntimeError(errorMessage, "SIGN_IN_ERROR", "react");
7836
+ const err = new Error(errorMessage);
7788
7837
  setError(err);
7789
7838
  cleanupFlowUrlParams();
7790
- return;
7839
+ throw err;
7791
7840
  }
7792
7841
  if (response.flowStatus === import_browser48.EmbeddedSignInFlowStatusV2.Complete) {
7793
7842
  const redirectUrl = response?.redirectUrl || response?.redirect_uri;
@@ -7804,8 +7853,6 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7804
7853
  });
7805
7854
  if (finalRedirectUrl && window?.location) {
7806
7855
  window.location.href = finalRedirectUrl;
7807
- } else {
7808
- console.warn("[SignIn] Flow completed but no redirect URL available");
7809
7856
  }
7810
7857
  return;
7811
7858
  }
@@ -7818,16 +7865,14 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7818
7865
  } catch (error) {
7819
7866
  const err = error;
7820
7867
  clearFlowState();
7821
- const errorMessage = err instanceof Error ? err.message : String(err);
7822
- const displayError = new import_browser48.AsgardeoRuntimeError(errorMessage, "SIGN_IN_ERROR", "react");
7823
- setError(displayError);
7868
+ const errorMessage = err?.failureReason || (err instanceof Error ? err.message : String(err));
7869
+ setError(new Error(errorMessage));
7824
7870
  return;
7825
7871
  } finally {
7826
7872
  setIsSubmitting(false);
7827
7873
  }
7828
7874
  };
7829
7875
  const handleError = (error) => {
7830
- console.error("Authentication error:", error);
7831
7876
  setError(error);
7832
7877
  };
7833
7878
  (0, import_react59.useEffect)(() => {
@@ -7857,7 +7902,6 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7857
7902
  }
7858
7903
  };
7859
7904
  handleSubmit(submitPayload).catch((error) => {
7860
- console.error("[SignIn] OAuth callback submission failed:", error);
7861
7905
  cleanupOAuthUrlParams(true);
7862
7906
  });
7863
7907
  }, [isFlowInitialized, currentFlowId, isInitialized, isLoading, isSubmitting, signIn]);
@@ -7879,6 +7923,7 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7879
7923
  isLoading: isLoading || !isInitialized || !isFlowInitialized,
7880
7924
  onSubmit: handleSubmit,
7881
7925
  onError: handleError,
7926
+ error: flowError,
7882
7927
  className,
7883
7928
  size,
7884
7929
  variant
@@ -9092,6 +9137,7 @@ var BaseSignUpContent2 = ({
9092
9137
  onError,
9093
9138
  onFlowChange,
9094
9139
  onComplete,
9140
+ error: externalError,
9095
9141
  className = "",
9096
9142
  inputClassName = "",
9097
9143
  buttonClassName = "",
@@ -9111,7 +9157,8 @@ var BaseSignUpContent2 = ({
9111
9157
  const styles = BaseSignUp_styles_default(theme, colorScheme);
9112
9158
  const handleError = (0, import_react62.useCallback)(
9113
9159
  (error) => {
9114
- const errorMessage = extractErrorMessage(error, t);
9160
+ const errorMessage = error?.failureReason || extractErrorMessage(error, t);
9161
+ setApiError(error instanceof Error ? error : new Error(errorMessage));
9115
9162
  clearMessages();
9116
9163
  addMessage({
9117
9164
  type: "error",
@@ -9123,7 +9170,7 @@ var BaseSignUpContent2 = ({
9123
9170
  const [isLoading, setIsLoading] = (0, import_react62.useState)(false);
9124
9171
  const [isFlowInitialized, setIsFlowInitialized] = (0, import_react62.useState)(false);
9125
9172
  const [currentFlow, setCurrentFlow] = (0, import_react62.useState)(null);
9126
- const [formData, setFormData] = (0, import_react62.useState)({});
9173
+ const [apiError, setApiError] = (0, import_react62.useState)(null);
9127
9174
  const initializationAttemptedRef = (0, import_react62.useRef)(false);
9128
9175
  const normalizeFlowResponseLocal = (0, import_react62.useCallback)(
9129
9176
  (response) => {
@@ -9156,21 +9203,19 @@ var BaseSignUpContent2 = ({
9156
9203
  const fields = [];
9157
9204
  const processComponents = (comps) => {
9158
9205
  comps.forEach((component) => {
9159
- 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) {
9207
+ const fieldName = component.ref || component.id;
9160
9208
  fields.push({
9161
- name: component.id,
9209
+ name: fieldName,
9162
9210
  required: component.required || false,
9163
9211
  initialValue: "",
9164
9212
  validator: (value) => {
9165
9213
  if (component.required && (!value || value.trim() === "")) {
9166
9214
  return t("validations.required.field.error");
9167
9215
  }
9168
- 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)) {
9169
9217
  return t("field.email.invalid");
9170
9218
  }
9171
- if (component.type === "PASSWORD_INPUT" && value && value.length < 8) {
9172
- return t("field.password.weak");
9173
- }
9174
9219
  return null;
9175
9220
  }
9176
9221
  });
@@ -9190,7 +9235,7 @@ var BaseSignUpContent2 = ({
9190
9235
  initialValues: {},
9191
9236
  fields: formFields,
9192
9237
  validateOnBlur: true,
9193
- validateOnChange: true,
9238
+ validateOnChange: false,
9194
9239
  requiredMessage: t("validations.required.field.error")
9195
9240
  });
9196
9241
  const {
@@ -9222,6 +9267,8 @@ var BaseSignUpContent2 = ({
9222
9267
  );
9223
9268
  const handleInputChange = (name, value) => {
9224
9269
  setFormValue(name, value);
9270
+ };
9271
+ const handleInputBlur = (name) => {
9225
9272
  setFormTouched(name, true);
9226
9273
  };
9227
9274
  const handleSubmit = async (component, data, skipValidation) => {
@@ -9236,6 +9283,7 @@ var BaseSignUpContent2 = ({
9236
9283
  }
9237
9284
  }
9238
9285
  setIsLoading(true);
9286
+ setApiError(null);
9239
9287
  clearMessages();
9240
9288
  try {
9241
9289
  const filteredInputs = {};
@@ -9298,7 +9346,7 @@ var BaseSignUpContent2 = ({
9298
9346
  code,
9299
9347
  state
9300
9348
  },
9301
- actionId: ""
9349
+ action: ""
9302
9350
  };
9303
9351
  try {
9304
9352
  const continueResponse = await onSubmit(payload);
@@ -9358,7 +9406,7 @@ var BaseSignUpContent2 = ({
9358
9406
  code,
9359
9407
  state
9360
9408
  },
9361
- actionId: ""
9409
+ action: ""
9362
9410
  };
9363
9411
  try {
9364
9412
  const continueResponse = await onSubmit(payload);
@@ -9425,6 +9473,7 @@ var BaseSignUpContent2 = ({
9425
9473
  {
9426
9474
  buttonClassName: buttonClasses,
9427
9475
  inputClassName: inputClasses,
9476
+ onInputBlur: handleInputBlur,
9428
9477
  onSubmit: handleSubmit,
9429
9478
  size,
9430
9479
  variant
@@ -9440,7 +9489,8 @@ var BaseSignUpContent2 = ({
9440
9489
  variant,
9441
9490
  inputClasses,
9442
9491
  buttonClasses,
9443
- handleSubmit
9492
+ handleSubmit,
9493
+ handleInputBlur
9444
9494
  ]
9445
9495
  );
9446
9496
  const getUrlParams = () => {
@@ -9460,6 +9510,7 @@ var BaseSignUpContent2 = ({
9460
9510
  initializationAttemptedRef.current = true;
9461
9511
  (async () => {
9462
9512
  setIsLoading(true);
9513
+ setApiError(null);
9463
9514
  clearMessages();
9464
9515
  try {
9465
9516
  const rawResponse = await onInitialize();
@@ -9497,14 +9548,18 @@ var BaseSignUpContent2 = ({
9497
9548
  if (children) {
9498
9549
  const renderProps = {
9499
9550
  values: formValues,
9500
- errors: formErrors,
9551
+ fieldErrors: formErrors,
9552
+ error: apiError,
9501
9553
  touched: touchedFields,
9502
9554
  isValid: isFormValid,
9503
9555
  isLoading,
9504
9556
  components: currentFlow?.data?.components || [],
9505
9557
  handleInputChange,
9506
9558
  handleSubmit,
9507
- validateForm,
9559
+ validateForm: () => {
9560
+ const result = validateForm();
9561
+ return { isValid: result.isValid, fieldErrors: result.errors };
9562
+ },
9508
9563
  title: flowTitle || t("signup.heading"),
9509
9564
  subtitle: flowSubtitle || t("signup.subheading"),
9510
9565
  messages: flowMessages || []
@@ -9534,6 +9589,7 @@ var BaseSignUpContent2 = ({
9534
9589
  showSubtitle && /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(Typography_default, { variant: "body1", className: styles.subtitle, children: subtitle })
9535
9590
  ] }),
9536
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 }) }) }),
9537
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)(
9538
9594
  Alert_default,
9539
9595
  {