@ory/elements-react 1.0.0-next.16 → 1.0.0-next.17

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/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { UiNodeGroupEnum, isUiNodeInputAttributes, isUiNodeAnchorAttributes, isUiNodeImageAttributes, isUiNodeScriptAttributes, isUiNodeTextAttributes, FlowType, handleFlowError, loginUrl, handleContinueWith, recoveryUrl, registrationUrl, settingsUrl, isResponseError, verificationUrl, UiNodeInputAttributesTypeEnum, Configuration, FrontendApi } from '@ory/client-fetch';
1
+ import { UiNodeGroupEnum, isUiNodeInputAttributes, isUiNodeAnchorAttributes, isUiNodeImageAttributes, isUiNodeScriptAttributes, isUiNodeTextAttributes, FlowType, handleFlowError, loginUrl, handleContinueWith, recoveryUrl, instanceOfContinueWithRecoveryUi, registrationUrl, settingsUrl, isResponseError, verificationUrl, UiNodeInputAttributesTypeEnum, Configuration, FrontendApi } from '@ory/client-fetch';
2
2
  import { createContext, useContext, useState, useMemo, useReducer, useRef, useEffect } from 'react';
3
3
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
4
4
  import { useIntl, IntlProvider as IntlProvider$1 } from 'react-intl';
@@ -113,6 +113,7 @@ function findMethodWithMessage(nodes) {
113
113
  });
114
114
  }
115
115
  function parseStateFromFlow(flow) {
116
+ var _a;
116
117
  switch (flow.flowType) {
117
118
  case FlowType.Registration:
118
119
  case FlowType.Login: {
@@ -123,10 +124,12 @@ function parseStateFromFlow(flow) {
123
124
  return { current: "method_active", method: "code" };
124
125
  } else if (methodWithMessage) {
125
126
  return { current: "method_active", method: methodWithMessage.group };
126
- } else if (flow.flow.active && !["default", "identifier_first"].includes(flow.flow.active)) {
127
+ } else if (flow.flow.active && !["default", "identifier_first", "oidc"].includes(flow.flow.active)) {
127
128
  return { current: "method_active", method: flow.flow.active };
128
129
  } else if (isChoosingMethod(flow.flow.ui.nodes)) {
129
130
  return { current: "select_method" };
131
+ } else if ((_a = flow.flow.ui.messages) == null ? void 0 : _a.some((m) => m.id === 1010016)) {
132
+ return { current: "select_method" };
130
133
  }
131
134
  return { current: "provide_identifier" };
132
135
  }
@@ -436,7 +439,8 @@ var en_default = {
436
439
  "settings.passkey.title": "Manage Passkeys",
437
440
  "settings.passkey.description": "Manage your passkey settings",
438
441
  "settings.passkey.info": "Manage your passkey settings",
439
- "card.footer.select-another-method": "Select another method"
442
+ "card.footer.select-another-method": "Select another method",
443
+ "account-linking.title": "Link account"
440
444
  };
441
445
 
442
446
  // src/locales/de.json
@@ -682,7 +686,8 @@ var de_default = {
682
686
  "settings.title-totp": "Verwalten Sie die 2FA TOTP Authenticator-App",
683
687
  "settings.title-webauthn": "Hardware-Token verwalten",
684
688
  "settings.webauthn.info": "Hardware-Tokens werden f\xFCr die Zweitfaktor-Authentifizierung oder als Erstfaktor-Authentifizierung mit Passkeys verwendet",
685
- "card.footer.select-another-method": "Eine andere Methode verwenden"
689
+ "card.footer.select-another-method": "Eine andere Methode verwenden",
690
+ "account-linking.title": "Account Verbinden"
686
691
  };
687
692
 
688
693
  // src/locales/es.json
@@ -928,7 +933,8 @@ var es_default = {
928
933
  "settings.title-totp": "",
929
934
  "settings.title-webauthn": "",
930
935
  "settings.webauthn.info": "",
931
- "card.footer.select-another-method": ""
936
+ "card.footer.select-another-method": "",
937
+ "account-linking.title": ""
932
938
  };
933
939
 
934
940
  // src/locales/fr.json
@@ -1174,7 +1180,8 @@ var fr_default = {
1174
1180
  "settings.webauthn.description": "",
1175
1181
  "settings.webauthn.info": "",
1176
1182
  "settings.webauthn.title": "",
1177
- "card.footer.select-another-method": ""
1183
+ "card.footer.select-another-method": "",
1184
+ "account-linking.title": ""
1178
1185
  };
1179
1186
 
1180
1187
  // src/locales/nl.json
@@ -1420,7 +1427,8 @@ var nl_default = {
1420
1427
  "settings.webauthn.description": "",
1421
1428
  "settings.webauthn.info": "",
1422
1429
  "settings.webauthn.title": "",
1423
- "card.footer.select-another-method": ""
1430
+ "card.footer.select-another-method": "",
1431
+ "account-linking.title": ""
1424
1432
  };
1425
1433
 
1426
1434
  // src/locales/pl.json
@@ -1666,7 +1674,8 @@ var pl_default = {
1666
1674
  "settings.webauthn.description": "",
1667
1675
  "settings.webauthn.info": "",
1668
1676
  "settings.webauthn.title": "",
1669
- "card.footer.select-another-method": ""
1677
+ "card.footer.select-another-method": "",
1678
+ "account-linking.title": ""
1670
1679
  };
1671
1680
 
1672
1681
  // src/locales/pt.json
@@ -1912,7 +1921,8 @@ var pt_default = {
1912
1921
  "settings.webauthn.description": "",
1913
1922
  "settings.webauthn.info": "",
1914
1923
  "settings.webauthn.title": "",
1915
- "card.footer.select-another-method": ""
1924
+ "card.footer.select-another-method": "",
1925
+ "account-linking.title": ""
1916
1926
  };
1917
1927
 
1918
1928
  // src/locales/sv.json
@@ -2158,7 +2168,8 @@ var sv_default = {
2158
2168
  "settings.webauthn.description": "Hantera inst\xE4llningarna f\xF6r din maskinvarutoken",
2159
2169
  "settings.webauthn.info": "H\xE5rdvarutokens anv\xE4nds f\xF6r andrafaktorsautentisering eller som f\xF6rstafaktor med l\xF6senordsnycklar",
2160
2170
  "settings.webauthn.title": "Hantera maskinvarutokens",
2161
- "card.footer.select-another-method": "V\xE4lj en annan metod"
2171
+ "card.footer.select-another-method": "V\xE4lj en annan metod",
2172
+ "account-linking.title": "L\xE4nka ditt konto"
2162
2173
  };
2163
2174
 
2164
2175
  // src/locales/index.ts
@@ -2296,16 +2307,34 @@ async function onSubmitRecovery({ config, flow }, {
2296
2307
  onRedirect(recoveryUrl(config), true);
2297
2308
  },
2298
2309
  onValidationError: (body2) => {
2299
- setFlowContainer({
2300
- flow: body2,
2301
- flowType: FlowType.Recovery,
2302
- config
2303
- });
2310
+ if ("error" in body2) {
2311
+ handleContinueWithRecoveryUIError(body2.error, config, onRedirect);
2312
+ return;
2313
+ } else {
2314
+ setFlowContainer({
2315
+ flow: body2,
2316
+ flowType: FlowType.Recovery,
2317
+ config
2318
+ });
2319
+ }
2304
2320
  },
2305
2321
  onRedirect
2306
2322
  })
2307
2323
  );
2308
2324
  }
2325
+ function handleContinueWithRecoveryUIError(error, config, onRedirect) {
2326
+ if ("continue_with" in error.details && Array.isArray(error.details.continue_with)) {
2327
+ const continueWithRecovery = error.details.continue_with.find(instanceOfContinueWithRecoveryUi);
2328
+ if ((continueWithRecovery == null ? void 0 : continueWithRecovery.action) === "show_recovery_ui") {
2329
+ onRedirect(
2330
+ config.project.recovery_ui_url + "?flow=" + (continueWithRecovery == null ? void 0 : continueWithRecovery.flow.id),
2331
+ false
2332
+ );
2333
+ return;
2334
+ }
2335
+ }
2336
+ onRedirect(recoveryUrl(config), true);
2337
+ }
2309
2338
  async function onSubmitRegistration({ config, flow }, {
2310
2339
  setFlowContainer,
2311
2340
  body,
@@ -2436,20 +2465,22 @@ function computeDefaultValues(nodes) {
2436
2465
  return nodes.reduce((acc, node) => {
2437
2466
  const attrs = node.attributes;
2438
2467
  if (isUiNodeInputAttributes(attrs)) {
2439
- if (attrs.name === "method" || attrs.type === "submit" || typeof attrs.value === "undefined")
2468
+ if (attrs.name === "method" || attrs.type === "submit" || typeof attrs.value === "undefined") {
2440
2469
  return acc;
2441
- const unrolled = unrollTrait({
2442
- name: attrs.name,
2443
- value: attrs.value
2444
- });
2445
- Object.assign(acc, unrolled != null ? unrolled : { [attrs.name]: attrs.value });
2470
+ }
2471
+ return unrollTrait(
2472
+ {
2473
+ name: attrs.name,
2474
+ value: attrs.value
2475
+ },
2476
+ acc
2477
+ );
2446
2478
  }
2447
2479
  return acc;
2448
2480
  }, {});
2449
2481
  }
2450
2482
  function unrollTrait(input, output = {}) {
2451
2483
  const keys = input.name.split(".");
2452
- if (!keys.length) return void 0;
2453
2484
  let current = output;
2454
2485
  keys.forEach((key, index) => {
2455
2486
  if (!key) return;
@@ -2545,8 +2576,10 @@ var NodeInput = ({
2545
2576
  //
2546
2577
  ...attrs
2547
2578
  } = attributes;
2579
+ const isResendNode = ((_a = node.meta.label) == null ? void 0 : _a.id) === 1070008;
2580
+ const isScreenSelectionNode = "name" in node.attributes && node.attributes.name === "screen";
2548
2581
  const setFormValue = () => {
2549
- if (attrs.value) {
2582
+ if (attrs.value && !(isResendNode || isScreenSelectionNode)) {
2550
2583
  setValue(attrs.name, attrs.value);
2551
2584
  }
2552
2585
  };
@@ -2571,8 +2604,6 @@ var NodeInput = ({
2571
2604
  };
2572
2605
  const isSocial = (attrs.name === "provider" || attrs.name === "link") && node.group === "oidc";
2573
2606
  const isPinCodeInput = attrs.name === "code" && node.group === "code" || attrs.name === "totp_code" && node.group === "totp";
2574
- const isResendNode = ((_a = node.meta.label) == null ? void 0 : _a.id) === 1070008;
2575
- const isScreenSelectionNode = "name" in node.attributes && node.attributes.name === "screen";
2576
2607
  switch (attributes.type) {
2577
2608
  case UiNodeInputAttributesTypeEnum.Submit:
2578
2609
  case UiNodeInputAttributesTypeEnum.Button:
@@ -2644,6 +2675,51 @@ function OryFormGroups({ children, groups }) {
2644
2675
  return /* @__PURE__ */ jsx(Node, { node }, k);
2645
2676
  }) });
2646
2677
  }
2678
+
2679
+ // src/components/form/form-resolver.ts
2680
+ function isCodeResendRequest(data) {
2681
+ var _a;
2682
+ return (_a = data.email) != null ? _a : data.resend;
2683
+ }
2684
+ function useOryFormResolver() {
2685
+ const flowContainer = useOryFlow();
2686
+ return (data) => {
2687
+ if (flowContainer.formState.current === "method_active") {
2688
+ if (data.method === "code" && !data.code && !isCodeResendRequest(data)) {
2689
+ return {
2690
+ values: data,
2691
+ errors: {
2692
+ code: {
2693
+ id: 4000002,
2694
+ context: {
2695
+ property: "code"
2696
+ },
2697
+ type: "error",
2698
+ text: "Property code is missing"
2699
+ }
2700
+ }
2701
+ };
2702
+ }
2703
+ }
2704
+ return {
2705
+ values: data,
2706
+ errors: {}
2707
+ };
2708
+ };
2709
+ }
2710
+ function OryFormProvider({
2711
+ children,
2712
+ nodes
2713
+ }) {
2714
+ const flowContainer = useOryFlow();
2715
+ const defaultNodes = nodes ? flowContainer.flow.ui.nodes.filter((node) => node.group === UiNodeGroupEnum.Default).concat(nodes) : flowContainer.flow.ui.nodes;
2716
+ const methods = useForm({
2717
+ // TODO: Generify this, so we have typesafety in the submit handler.
2718
+ defaultValues: computeDefaultValues(defaultNodes),
2719
+ resolver: useOryFormResolver()
2720
+ });
2721
+ return /* @__PURE__ */ jsx(FormProvider, { ...methods, children });
2722
+ }
2647
2723
  function OryFormOidcButtons({
2648
2724
  children,
2649
2725
  hideDivider
@@ -2689,7 +2765,7 @@ function OryFormSocialButtonsForm() {
2689
2765
  if (filteredNodes.length === 0) {
2690
2766
  return null;
2691
2767
  }
2692
- return /* @__PURE__ */ jsx(OryForm, { children: /* @__PURE__ */ jsx(OryFormOidcButtons, {}) });
2768
+ return /* @__PURE__ */ jsx(OryFormProvider, { children: /* @__PURE__ */ jsx(OryForm, { children: /* @__PURE__ */ jsx(OryFormOidcButtons, {}) }) });
2693
2769
  }
2694
2770
  function OryForm({ children, onAfterSubmit }) {
2695
2771
  var _a;
@@ -2839,7 +2915,7 @@ function OryForm({ children, onAfterSubmit }) {
2839
2915
  }
2840
2916
  );
2841
2917
  }
2842
- var messageIdsToHide = [1040009, 1060003, 1080003, 1010014, 1040005];
2918
+ var messageIdsToHide = [1040009, 1060003, 1080003, 1010014, 1040005, 1010016];
2843
2919
  function OryCardValidationMessages({ ...props }) {
2844
2920
  var _a;
2845
2921
  const { flow } = useOryFlow();
@@ -2852,18 +2928,6 @@ function OryCardValidationMessages({ ...props }) {
2852
2928
  }
2853
2929
  return /* @__PURE__ */ jsx(Message.Root, { ...props, children: messages == null ? void 0 : messages.map((message) => /* @__PURE__ */ jsx(Message.Content, { message }, message.id)) });
2854
2930
  }
2855
- function OryFormProvider({
2856
- children,
2857
- nodes
2858
- }) {
2859
- const flowContainer = useOryFlow();
2860
- const defaultNodes = nodes ? flowContainer.flow.ui.nodes.filter((node) => node.group === UiNodeGroupEnum.Default).concat(nodes) : flowContainer.flow.ui.nodes;
2861
- const methods = useForm({
2862
- // TODO: Generify this, so we have typesafety in the submit handler.
2863
- defaultValues: computeDefaultValues(defaultNodes)
2864
- });
2865
- return /* @__PURE__ */ jsx(FormProvider, { ...methods, children });
2866
- }
2867
2931
  function OryFormSection({ children, nodes }) {
2868
2932
  const { Card } = useComponents();
2869
2933
  return /* @__PURE__ */ jsx(OryFormProvider, { nodes, children: /* @__PURE__ */ jsx(OryForm, { children: /* @__PURE__ */ jsx(Card.SettingsSection, { children }) }) });