@ory/elements-react 0.0.0-pr.3a98de9 → 0.0.0-pr.4a28a8f

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,8 +1,8 @@
1
- import { UiNodeGroupEnum, isUiNodeInputAttributes, FlowType, Configuration, FrontendApi, handleContinueWith, handleFlowError, settingsUrl, isResponseError, loginUrl, instanceOfContinueWithRecoveryUi, recoveryUrl, verificationUrl, registrationUrl, isUiNodeAnchorAttributes, isUiNodeImageAttributes, isUiNodeScriptAttributes, isUiNodeTextAttributes, UiNodeInputAttributesTypeEnum } from '@ory/client-fetch';
2
- import { createContext, useContext, useRef, useEffect, useState, useReducer, useMemo } from 'react';
1
+ import { UiNodeGroupEnum, isUiNodeInputAttributes, isUiNodeAnchorAttributes, isUiNodeImageAttributes, isUiNodeScriptAttributes, FlowType, UiNodeInputAttributesTypeEnum, isUiNodeTextAttributes, handleContinueWith, handleFlowError, settingsUrl, isResponseError, loginUrl, recoveryUrl, verificationUrl, registrationUrl, Configuration, FrontendApi, instanceOfContinueWithRecoveryUi } from '@ory/client-fetch';
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';
5
- import { useForm, FormProvider, useFormContext } from 'react-hook-form';
5
+ import { useFormContext, useForm, FormProvider } from 'react-hook-form';
6
6
 
7
7
  // src/context/component.tsx
8
8
  var ComponentContext = createContext({
@@ -34,6 +34,7 @@ function useGroupSorter() {
34
34
  }
35
35
  var defaultNodeOrder = [
36
36
  "oidc",
37
+ "saml",
37
38
  "identifier_first",
38
39
  "default",
39
40
  "profile",
@@ -98,8 +99,10 @@ function isChoosingMethod(flow) {
98
99
  (node) => node.group === UiNodeGroupEnum.IdentifierFirst && "name" in node.attributes && node.attributes.name === "identifier" && node.attributes.type === "hidden"
99
100
  ) || flow.flowType === FlowType.Login && flow.flow.requested_aal === "aal2";
100
101
  }
101
- function filterOidcOut(nodes) {
102
- return nodes.filter((node) => node.group !== UiNodeGroupEnum.Oidc);
102
+ function removeSsoNodes(nodes) {
103
+ return nodes.filter(
104
+ (node) => !(node.group === UiNodeGroupEnum.Oidc || node.group === UiNodeGroupEnum.Saml)
105
+ );
103
106
  }
104
107
  function getFinalNodes(uniqueGroups, selectedGroup) {
105
108
  var _a, _b, _c, _d;
@@ -232,7 +235,9 @@ function parseStateFromFlow(flow) {
232
235
  return { current: "method_active", method: "code" };
233
236
  } else if (methodWithMessage) {
234
237
  return { current: "method_active", method: methodWithMessage.group };
235
- } else if (flow.flow.active && !["default", "identifier_first", "oidc"].includes(flow.flow.active)) {
238
+ } else if (flow.flow.active && !["default", "identifier_first", "oidc", "saml"].includes(
239
+ flow.flow.active
240
+ )) {
236
241
  return { current: "method_active", method: flow.flow.active };
237
242
  } else if (isChoosingMethod(flow)) {
238
243
  const authMethods = nodesToAuthMethodGroups(flow.flow.ui.nodes);
@@ -262,17 +267,24 @@ function parseStateFromFlow(flow) {
262
267
  );
263
268
  throw new Error("Unknown form state");
264
269
  }
265
- function formStateReducer(state, action) {
266
- switch (action.type) {
267
- case "action_flow_update":
268
- return parseStateFromFlow(action.flow);
269
- case "action_select_method":
270
- return { current: "method_active", method: action.method };
271
- }
272
- return state;
273
- }
274
270
  function useFormStateReducer(flow) {
275
- return useReducer(formStateReducer, parseStateFromFlow(flow));
271
+ const action = parseStateFromFlow(flow);
272
+ const [selectedMethod, setSelectedMethod] = useState();
273
+ const formStateReducer = (state, action2) => {
274
+ switch (action2.type) {
275
+ case "action_flow_update": {
276
+ if (selectedMethod)
277
+ return { current: "method_active", method: selectedMethod };
278
+ return parseStateFromFlow(action2.flow);
279
+ }
280
+ case "action_select_method": {
281
+ setSelectedMethod(action2.method);
282
+ return { current: "method_active", method: action2.method };
283
+ }
284
+ }
285
+ return state;
286
+ };
287
+ return useReducer(formStateReducer, action);
276
288
  }
277
289
  function useOryFlow() {
278
290
  const ctx = useContext(OryFlowContext);
@@ -793,7 +805,7 @@ function useOryFormSubmit(onAfterSubmit) {
793
805
  if ("lookup_secret_confirm" in submitData || "lookup_secret_reveal" in submitData || "lookup_secret_regenerate" in submitData || "lookup_secret_disable" in submitData) {
794
806
  submitData.method = "lookup_secret";
795
807
  }
796
- if (submitData.method === "oidc" && submitData.link && supportsSelectAccountPrompt.includes(submitData.link)) {
808
+ if (submitData.method === UiNodeGroupEnum.Oidc && submitData.link && supportsSelectAccountPrompt.includes(submitData.link)) {
797
809
  submitData.upstream_parameters = {
798
810
  prompt: "select_account"
799
811
  };
@@ -934,7 +946,7 @@ var NodeInput = ({
934
946
  triggerToWindowCall(onclickTrigger);
935
947
  }
936
948
  };
937
- const isSocial = (attrs.name === "provider" || attrs.name === "link") && node.group === "oidc";
949
+ const isSocial = (attrs.name === "provider" || attrs.name === "link") && (node.group === UiNodeGroupEnum.Oidc || node.group === UiNodeGroupEnum.Saml);
938
950
  const isPinCodeInput = attrs.name === "code" && node.group === "code" || attrs.name === "totp_code" && node.group === "totp";
939
951
  switch (attributes.type) {
940
952
  case UiNodeInputAttributesTypeEnum.Submit:
@@ -1017,7 +1029,9 @@ function OryFormOidcButtons() {
1017
1029
  flow: { ui }
1018
1030
  } = useOryFlow();
1019
1031
  const { setValue } = useFormContext();
1020
- const filteredNodes = ui.nodes.filter((node) => node.group === "oidc");
1032
+ const filteredNodes = ui.nodes.filter(
1033
+ (node) => node.group === UiNodeGroupEnum.Oidc || node.group === UiNodeGroupEnum.Saml
1034
+ );
1021
1035
  const { Form, Node: Node2 } = useComponents();
1022
1036
  if (filteredNodes.length === 0) {
1023
1037
  return null;
@@ -1032,7 +1046,7 @@ function OryFormOidcButtons() {
1032
1046
  "provider",
1033
1047
  node.attributes.value
1034
1048
  );
1035
- setValue("method", "oidc");
1049
+ setValue("method", node.group);
1036
1050
  }
1037
1051
  },
1038
1052
  k
@@ -1042,7 +1056,7 @@ function OryFormSocialButtonsForm() {
1042
1056
  const {
1043
1057
  flow: { ui }
1044
1058
  } = useOryFlow();
1045
- const filteredNodes = ui.nodes.filter((node) => node.group === "oidc");
1059
+ const filteredNodes = ui.nodes.filter((node) => node.group === UiNodeGroupEnum.Saml || node.group === UiNodeGroupEnum.Oidc);
1046
1060
  if (filteredNodes.length === 0) {
1047
1061
  return null;
1048
1062
  }
@@ -1066,6 +1080,7 @@ function OryTwoStepCard() {
1066
1080
  }).filter(
1067
1081
  (group) => ![
1068
1082
  UiNodeGroupEnum.Oidc,
1083
+ UiNodeGroupEnum.Saml,
1069
1084
  UiNodeGroupEnum.Default,
1070
1085
  UiNodeGroupEnum.IdentifierFirst,
1071
1086
  UiNodeGroupEnum.Profile,
@@ -1093,7 +1108,7 @@ function OryTwoStepCard() {
1093
1108
  };
1094
1109
  }
1095
1110
  }
1096
- const nonOidcNodes = filterOidcOut(ui.nodes);
1111
+ const nonSsoNodes = removeSsoNodes(ui.nodes);
1097
1112
  const finalNodes = formState.current === "method_active" ? getFinalNodes(uniqueGroups.groups, formState.method) : [];
1098
1113
  const handleAfterFormSubmit = (method) => {
1099
1114
  if (typeof method !== "string" || !isUINodeGroupEnum(method)) {
@@ -1106,18 +1121,28 @@ function OryTwoStepCard() {
1106
1121
  });
1107
1122
  }
1108
1123
  };
1109
- const hasOidc = ui.nodes.some((node) => node.group === UiNodeGroupEnum.Oidc);
1110
- const showOidc = !(formState.current === "method_active" && formState.method !== "oidc");
1124
+ const hasSso = ui.nodes.some(
1125
+ (node) => node.group === UiNodeGroupEnum.Oidc || node.group === UiNodeGroupEnum.Saml
1126
+ );
1127
+ const showSso = !(formState.current === "method_active" && !(formState.method === UiNodeGroupEnum.Oidc || formState.method === UiNodeGroupEnum.Saml));
1128
+ const showSsoDivider = hasSso && nonSsoNodes.filter((n) => {
1129
+ if (isUiNodeInputAttributes(n.attributes)) {
1130
+ return n.attributes.type !== UiNodeInputAttributesTypeEnum.Hidden;
1131
+ } else if (isUiNodeScriptAttributes(n.attributes)) {
1132
+ return false;
1133
+ }
1134
+ return true;
1135
+ }).length > 0;
1111
1136
  return /* @__PURE__ */ jsxs(OryCard, { children: [
1112
1137
  /* @__PURE__ */ jsx(OryCardHeader, {}),
1113
1138
  /* @__PURE__ */ jsxs(OryCardContent, { children: [
1114
1139
  /* @__PURE__ */ jsx(OryCardValidationMessages, {}),
1115
- showOidc && /* @__PURE__ */ jsx(OryFormSocialButtonsForm, {}),
1140
+ showSso && /* @__PURE__ */ jsx(OryFormSocialButtonsForm, {}),
1116
1141
  /* @__PURE__ */ jsxs(OryForm, { onAfterSubmit: handleAfterFormSubmit, children: [
1117
1142
  /* @__PURE__ */ jsxs(Form.Group, { children: [
1118
1143
  formState.current === "provide_identifier" && /* @__PURE__ */ jsxs(Fragment, { children: [
1119
- hasOidc && /* @__PURE__ */ jsx(Card.Divider, {}),
1120
- nonOidcNodes.sort(sortNodes).map((node, k) => /* @__PURE__ */ jsx(Node, { node }, k))
1144
+ showSsoDivider && /* @__PURE__ */ jsx(Card.Divider, {}),
1145
+ nonSsoNodes.sort(sortNodes).map((node, k) => /* @__PURE__ */ jsx(Node, { node }, k))
1121
1146
  ] }),
1122
1147
  formState.current === "select_method" && /* @__PURE__ */ jsxs(Fragment, { children: [
1123
1148
  /* @__PURE__ */ jsx(Card.Divider, {}),
@@ -1210,9 +1235,11 @@ function OryFormGroupDivider() {
1210
1235
  const {
1211
1236
  flow: { ui }
1212
1237
  } = useOryFlow();
1213
- const filteredNodes = ui.nodes.filter((node) => node.group === "oidc");
1238
+ const filteredNodes = ui.nodes.filter(
1239
+ (node) => node.group === UiNodeGroupEnum.Oidc || node.group === UiNodeGroupEnum.Saml
1240
+ );
1214
1241
  const otherNodes = ui.nodes.filter(
1215
- (node) => node.group !== "oidc" && node.group !== "default"
1242
+ (node) => !(node.group === UiNodeGroupEnum.Oidc || node.group === UiNodeGroupEnum.Saml) && node.group !== "default"
1216
1243
  );
1217
1244
  if (filteredNodes.length > 0 && otherNodes.length > 0) {
1218
1245
  return /* @__PURE__ */ jsx(Card.Divider, {});
@@ -1238,7 +1265,7 @@ function OrySettingsOidc({ nodes }) {
1238
1265
  onClick: () => {
1239
1266
  if (node.attributes.node_type === "input") {
1240
1267
  setValue("link", node.attributes.value);
1241
- setValue("method", "oidc");
1268
+ setValue("method", node.group);
1242
1269
  }
1243
1270
  }
1244
1271
  }));
@@ -1247,7 +1274,7 @@ function OrySettingsOidc({ nodes }) {
1247
1274
  onClick: () => {
1248
1275
  if (node.attributes.node_type === "input") {
1249
1276
  setValue("unlink", node.attributes.value);
1250
- setValue("method", "oidc");
1277
+ setValue("method", node.group);
1251
1278
  }
1252
1279
  }
1253
1280
  }));
@@ -2001,7 +2028,13 @@ var en_default = {
2001
2028
  "property.phone": "phone",
2002
2029
  "property.username": "username",
2003
2030
  "property.identifier": "identifier",
2004
- "property.code": "code"
2031
+ "property.code": "code",
2032
+ "error.title.what-happened": "What happened?",
2033
+ "error.title.what-can-i-do": "What can I do?",
2034
+ "error.instructions": "Please try again in a few minutes or contact the website operator.",
2035
+ "error.footer.text": "When reporting this error, please include the following information:",
2036
+ "error.footer.copy": "Copy",
2037
+ "error.action.go-back": "Go back"
2005
2038
  };
2006
2039
 
2007
2040
  // src/locales/de.json
@@ -2266,7 +2299,13 @@ var de_default = {
2266
2299
  "property.password": "Passwort",
2267
2300
  "property.phone": "Telefon",
2268
2301
  "property.code": "Code",
2269
- "property.username": "Benutzername"
2302
+ "property.username": "Benutzername",
2303
+ "error.title.what-happened": "Was ist passiert?",
2304
+ "error.footer.copy": "Kopieren",
2305
+ "error.footer.text": "Bitte f\xFCgen Sie bei der Meldung dieses Fehlers die folgenden Informationen hinzu:",
2306
+ "error.instructions": "Bitte versuchen Sie es in wenigen Minuten erneut oder wenden Sie sich an den Website-Betreiber.",
2307
+ "error.title.what-can-i-do": "Was kann ich tun?",
2308
+ "error.action.go-back": "Zur\xFCck"
2270
2309
  };
2271
2310
 
2272
2311
  // src/locales/es.json
@@ -2282,7 +2321,7 @@ var es_default = {
2282
2321
  "error.back-button": "Regresar",
2283
2322
  "error.description": "Ocurri\xF3 un error con el siguiente mensaje:",
2284
2323
  "error.support-email-link": "Si el problema persiste, por favor contacte a <a>{contactSupportEmail}</a>",
2285
- "error.title": "Ocurri\xF3 un error",
2324
+ "error.title": "",
2286
2325
  "error.title-internal-server-error": "Error Interno del Servidor",
2287
2326
  "error.title-not-found": "404 - P\xE1gina no encontrada",
2288
2327
  "identities.messages.1010001": "Iniciar sesi\xF3n",
@@ -2531,7 +2570,13 @@ var es_default = {
2531
2570
  "property.identifier": "",
2532
2571
  "property.password": "",
2533
2572
  "property.phone": "",
2534
- "property.username": ""
2573
+ "property.username": "",
2574
+ "error.action.go-back": "",
2575
+ "error.footer.copy": "",
2576
+ "error.footer.text": "",
2577
+ "error.instructions": "",
2578
+ "error.title.what-can-i-do": "",
2579
+ "error.title.what-happened": ""
2535
2580
  };
2536
2581
 
2537
2582
  // src/locales/fr.json
@@ -2796,7 +2841,13 @@ var fr_default = {
2796
2841
  "property.identifier": "",
2797
2842
  "property.password": "",
2798
2843
  "property.phone": "",
2799
- "property.username": ""
2844
+ "property.username": "",
2845
+ "error.action.go-back": "",
2846
+ "error.footer.copy": "",
2847
+ "error.footer.text": "",
2848
+ "error.title.what-can-i-do": "",
2849
+ "error.title.what-happened": "",
2850
+ "error.instructions": ""
2800
2851
  };
2801
2852
 
2802
2853
  // src/locales/nl.json
@@ -3061,7 +3112,13 @@ var nl_default = {
3061
3112
  "property.identifier": "",
3062
3113
  "property.password": "",
3063
3114
  "property.phone": "",
3064
- "property.username": ""
3115
+ "property.username": "",
3116
+ "error.action.go-back": "",
3117
+ "error.footer.copy": "",
3118
+ "error.footer.text": "",
3119
+ "error.title.what-can-i-do": "",
3120
+ "error.title.what-happened": "",
3121
+ "error.instructions": ""
3065
3122
  };
3066
3123
 
3067
3124
  // src/locales/pl.json
@@ -3326,7 +3383,13 @@ var pl_default = {
3326
3383
  "property.password": "",
3327
3384
  "property.phone": "",
3328
3385
  "property.username": "",
3329
- "property.identifier": ""
3386
+ "property.identifier": "",
3387
+ "error.action.go-back": "",
3388
+ "error.footer.copy": "",
3389
+ "error.footer.text": "",
3390
+ "error.title.what-can-i-do": "",
3391
+ "error.title.what-happened": "",
3392
+ "error.instructions": ""
3330
3393
  };
3331
3394
 
3332
3395
  // src/locales/pt.json
@@ -3591,7 +3654,13 @@ var pt_default = {
3591
3654
  "property.identifier": "",
3592
3655
  "property.password": "",
3593
3656
  "property.phone": "",
3594
- "property.username": ""
3657
+ "property.username": "",
3658
+ "error.action.go-back": "",
3659
+ "error.footer.copy": "",
3660
+ "error.footer.text": "",
3661
+ "error.title.what-can-i-do": "",
3662
+ "error.title.what-happened": "",
3663
+ "error.instructions": ""
3595
3664
  };
3596
3665
 
3597
3666
  // src/locales/sv.json
@@ -3856,7 +3925,13 @@ var sv_default = {
3856
3925
  "property.phone": "telefon",
3857
3926
  "property.username": "anv\xE4ndarnamn",
3858
3927
  "property.identifier": "identifier",
3859
- "property.code": "kod"
3928
+ "property.code": "kod",
3929
+ "error.action.go-back": "",
3930
+ "error.footer.copy": "",
3931
+ "error.footer.text": "",
3932
+ "error.title.what-can-i-do": "",
3933
+ "error.title.what-happened": "",
3934
+ "error.instructions": ""
3860
3935
  };
3861
3936
 
3862
3937
  // src/locales/index.ts