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

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.
Files changed (61) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/api-report/elements-react-client.api.json +144 -16
  3. package/api-report/elements-react-client.api.md +19 -8
  4. package/api-report/elements-react-theme.api.json +47 -0
  5. package/api-report/elements-react-theme.api.md +5 -2
  6. package/api-report/elements-react.api.json +85 -23
  7. package/api-report/elements-react.api.md +37 -16
  8. package/api-report/temp/elements-react-client.api.md +19 -8
  9. package/api-report/temp/elements-react-theme.api.md +5 -2
  10. package/api-report/temp/elements-react.api.md +37 -16
  11. package/dist/client/config.d.mts +21 -0
  12. package/dist/client/config.d.ts +21 -0
  13. package/dist/client/config.js +77 -0
  14. package/dist/client/config.js.map +1 -0
  15. package/dist/client/config.mjs +51 -0
  16. package/dist/client/config.mjs.map +1 -0
  17. package/dist/client/frontendClient.d.mts +3 -1
  18. package/dist/client/frontendClient.d.ts +3 -1
  19. package/dist/client/frontendClient.js +14 -2
  20. package/dist/client/frontendClient.js.map +1 -1
  21. package/dist/client/frontendClient.mjs +14 -2
  22. package/dist/client/frontendClient.mjs.map +1 -1
  23. package/dist/client/index.d.mts +3 -1
  24. package/dist/client/index.d.ts +3 -1
  25. package/dist/client/index.js +4 -0
  26. package/dist/client/index.js.map +1 -1
  27. package/dist/client/index.mjs +5 -0
  28. package/dist/client/index.mjs.map +1 -1
  29. package/dist/client/session-provider.d.mts +62 -0
  30. package/dist/client/session-provider.d.ts +62 -0
  31. package/dist/client/session-provider.js +96 -0
  32. package/dist/client/session-provider.js.map +1 -0
  33. package/dist/client/session-provider.mjs +71 -0
  34. package/dist/client/session-provider.mjs.map +1 -0
  35. package/dist/client/useSession.d.mts +22 -31
  36. package/dist/client/useSession.d.ts +22 -31
  37. package/dist/client/useSession.js +7 -49
  38. package/dist/client/useSession.js.map +1 -1
  39. package/dist/client/useSession.mjs +8 -49
  40. package/dist/client/useSession.mjs.map +1 -1
  41. package/dist/index.d.mts +36 -19
  42. package/dist/index.d.ts +36 -19
  43. package/dist/index.js +583 -402
  44. package/dist/index.js.map +1 -1
  45. package/dist/index.mjs +586 -405
  46. package/dist/index.mjs.map +1 -1
  47. package/dist/theme/default/index.css +393 -259
  48. package/dist/theme/default/index.css.map +1 -1
  49. package/dist/theme/default/index.d.mts +4 -2
  50. package/dist/theme/default/index.d.ts +4 -2
  51. package/dist/theme/default/index.js +728 -588
  52. package/dist/theme/default/index.js.map +1 -1
  53. package/dist/theme/default/index.mjs +665 -526
  54. package/dist/theme/default/index.mjs.map +1 -1
  55. package/jest.config.ts +1 -1
  56. package/package.json +2 -1
  57. package/postcss.config.ts +1 -0
  58. package/tailwind.config.ts +14 -13
  59. package/tsconfig.json +4 -3
  60. package/variables-processed.json +385 -187
  61. package/.eslintrc.js +0 -63
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
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
- import { createContext, useContext, useState, useMemo, useReducer, useRef, useEffect } from 'react';
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';
3
3
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
4
4
  import { useIntl, IntlProvider as IntlProvider$1 } from 'react-intl';
5
- import { useFormContext, useForm, FormProvider } from 'react-hook-form';
5
+ import { useForm, FormProvider, useFormContext } from 'react-hook-form';
6
6
 
7
7
  // src/context/component.tsx
8
8
  var ComponentContext = createContext({
@@ -2228,266 +2228,6 @@ function OryCardHeader() {
2228
2228
  const { Card } = useComponents();
2229
2229
  return /* @__PURE__ */ jsx(Card.Header, {});
2230
2230
  }
2231
- function frontendClient(sdkUrl, opts = {}) {
2232
- const config = new Configuration({
2233
- ...opts,
2234
- basePath: sdkUrl,
2235
- headers: {
2236
- Accept: "application/json",
2237
- ...opts.headers
2238
- }
2239
- });
2240
- return new FrontendApi(config);
2241
- }
2242
-
2243
- // src/util/onSubmitLogin.ts
2244
- async function onSubmitLogin({ config, flow }, {
2245
- setFlowContainer,
2246
- body,
2247
- onRedirect
2248
- }) {
2249
- var _a;
2250
- if (!config.sdk.url) {
2251
- throw new Error(
2252
- `Please supply your Ory Network SDK url to the Ory Elements configuration.`
2253
- );
2254
- }
2255
- await frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {}).updateLoginFlowRaw({
2256
- flow: flow.id,
2257
- updateLoginFlowBody: body
2258
- }).then(() => {
2259
- var _a2;
2260
- window.location.href = (_a2 = flow.return_to) != null ? _a2 : config.sdk.url + "/self-service/login/browser";
2261
- }).catch(
2262
- handleFlowError({
2263
- onRestartFlow: () => {
2264
- onRedirect(loginUrl(config), true);
2265
- },
2266
- onValidationError: (body2) => {
2267
- setFlowContainer({
2268
- config,
2269
- flow: body2,
2270
- flowType: FlowType.Login
2271
- });
2272
- },
2273
- onRedirect
2274
- })
2275
- );
2276
- }
2277
- async function onSubmitRecovery({ config, flow }, {
2278
- setFlowContainer,
2279
- body,
2280
- onRedirect
2281
- }) {
2282
- var _a;
2283
- if (!config.sdk.url) {
2284
- throw new Error(
2285
- `Please supply your Ory Network SDK url to the Ory Elements configuration.`
2286
- );
2287
- }
2288
- await frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {}).updateRecoveryFlowRaw({
2289
- flow: flow.id,
2290
- updateRecoveryFlowBody: body
2291
- }).then(async (res) => {
2292
- const flow2 = await res.value();
2293
- const didContinueWith = handleContinueWith(flow2.continue_with, {
2294
- onRedirect
2295
- });
2296
- if (didContinueWith) {
2297
- return;
2298
- }
2299
- setFlowContainer({
2300
- flow: flow2,
2301
- flowType: FlowType.Recovery,
2302
- config
2303
- });
2304
- }).catch(
2305
- handleFlowError({
2306
- onRestartFlow: () => {
2307
- onRedirect(recoveryUrl(config), true);
2308
- },
2309
- onValidationError: (body2) => {
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
- }
2320
- },
2321
- onRedirect
2322
- })
2323
- );
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
- }
2338
- async function onSubmitRegistration({ config, flow }, {
2339
- setFlowContainer,
2340
- body,
2341
- onRedirect
2342
- }) {
2343
- var _a;
2344
- if (!config.sdk.url) {
2345
- throw new Error(
2346
- `Please supply your Ory Network SDK url to the Ory Elements configuration.`
2347
- );
2348
- }
2349
- const client = frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {});
2350
- await client.updateRegistrationFlowRaw({
2351
- flow: flow.id,
2352
- updateRegistrationFlowBody: body
2353
- }).then(async (res) => {
2354
- const body2 = await res.value();
2355
- const didContinueWith = handleContinueWith(body2.continue_with, {
2356
- onRedirect
2357
- });
2358
- if (didContinueWith) {
2359
- return;
2360
- }
2361
- onRedirect(registrationUrl(config), true);
2362
- }).catch(
2363
- handleFlowError({
2364
- onRestartFlow: () => {
2365
- onRedirect(registrationUrl(config), true);
2366
- },
2367
- onValidationError: (body2) => {
2368
- setFlowContainer({
2369
- flow: body2,
2370
- flowType: FlowType.Registration,
2371
- config
2372
- });
2373
- },
2374
- onRedirect
2375
- })
2376
- );
2377
- }
2378
- async function onSubmitSettings({ config, flow }, {
2379
- setFlowContainer,
2380
- body,
2381
- onRedirect
2382
- }) {
2383
- var _a;
2384
- if (!config.sdk.url) {
2385
- throw new Error(
2386
- `Please supply your Ory Network SDK url to the Ory Elements configuration.`
2387
- );
2388
- }
2389
- const client = frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {});
2390
- await client.updateSettingsFlowRaw({
2391
- flow: flow.id,
2392
- updateSettingsFlowBody: body
2393
- }).then(async (res) => {
2394
- const body2 = await res.value();
2395
- const didContinueWith = handleContinueWith(body2.continue_with, {
2396
- onRedirect
2397
- });
2398
- if (didContinueWith) {
2399
- return;
2400
- }
2401
- onRedirect(settingsUrl(config), true);
2402
- }).catch(
2403
- handleFlowError({
2404
- onRestartFlow: () => {
2405
- onRedirect(settingsUrl(config), true);
2406
- },
2407
- onValidationError: (body2) => {
2408
- setFlowContainer({
2409
- flow: body2,
2410
- flowType: FlowType.Settings,
2411
- config
2412
- });
2413
- },
2414
- onRedirect
2415
- })
2416
- ).catch((err) => {
2417
- if (isResponseError(err)) {
2418
- if (err.response.status === 401) {
2419
- return onRedirect(
2420
- loginUrl(config) + "?return_to=" + settingsUrl(config),
2421
- true
2422
- );
2423
- }
2424
- throw err;
2425
- }
2426
- });
2427
- }
2428
- async function onSubmitVerification({ config, flow }, {
2429
- setFlowContainer,
2430
- body,
2431
- onRedirect
2432
- }) {
2433
- var _a;
2434
- if (!config.sdk.url) {
2435
- throw new Error(
2436
- `Please supply your Ory Network SDK URL to the Ory Elements configuration.`
2437
- );
2438
- }
2439
- await frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {}).updateVerificationFlowRaw({
2440
- flow: flow.id,
2441
- updateVerificationFlowBody: body
2442
- }).then(
2443
- async (res) => setFlowContainer({
2444
- flow: await res.value(),
2445
- flowType: FlowType.Verification,
2446
- config
2447
- })
2448
- ).catch(
2449
- handleFlowError({
2450
- onRestartFlow: () => {
2451
- onRedirect(verificationUrl(config), true);
2452
- },
2453
- onValidationError: (body2) => {
2454
- setFlowContainer({
2455
- flow: body2,
2456
- flowType: FlowType.Verification,
2457
- config
2458
- });
2459
- },
2460
- onRedirect
2461
- })
2462
- );
2463
- }
2464
- function computeDefaultValues(nodes) {
2465
- return nodes.reduce((acc, node) => {
2466
- const attrs = node.attributes;
2467
- if (isUiNodeInputAttributes(attrs)) {
2468
- if (attrs.name === "method" || attrs.type === "submit" || typeof attrs.value === "undefined") {
2469
- return acc;
2470
- }
2471
- return unrollTrait(
2472
- {
2473
- name: attrs.name,
2474
- value: attrs.value
2475
- },
2476
- acc
2477
- );
2478
- }
2479
- return acc;
2480
- }, {});
2481
- }
2482
- function unrollTrait(input, output = {}) {
2483
- const keys = input.name.split(".");
2484
- let current = output;
2485
- keys.forEach((key, index) => {
2486
- if (!key) return;
2487
- current = current[key] = index === keys.length - 1 ? input.value : current[key] || {};
2488
- });
2489
- return output;
2490
- }
2491
2231
  function triggerToWindowCall(trigger) {
2492
2232
  if (!trigger) {
2493
2233
  return;
@@ -2517,19 +2257,19 @@ function triggerToWindowCall(trigger) {
2517
2257
  }
2518
2258
  function triggerToFunction(trigger) {
2519
2259
  if (typeof window === "undefined") {
2520
- console.error(
2260
+ console.debug(
2521
2261
  "The Ory SDK is missing a required function: window is undefined."
2522
2262
  );
2523
2263
  return void 0;
2524
2264
  }
2525
2265
  const typedWindow = window;
2526
2266
  if (!(trigger in typedWindow) || !typedWindow[trigger]) {
2527
- console.error(`The Ory SDK is missing a required function: ${trigger}.`);
2267
+ console.debug(`The Ory SDK is missing a required function: ${trigger}.`);
2528
2268
  return void 0;
2529
2269
  }
2530
2270
  const triggerFn = typedWindow[trigger];
2531
2271
  if (typeof triggerFn !== "function") {
2532
- console.error(
2272
+ console.debug(
2533
2273
  `The Ory SDK is missing a required function: ${trigger}. It is not a function.`
2534
2274
  );
2535
2275
  return void 0;
@@ -2675,6 +2415,36 @@ function OryFormGroups({ children, groups }) {
2675
2415
  return /* @__PURE__ */ jsx(Node, { node }, k);
2676
2416
  }) });
2677
2417
  }
2418
+ function computeDefaultValues(nodes) {
2419
+ return nodes.reduce((acc, node) => {
2420
+ const attrs = node.attributes;
2421
+ if (isUiNodeInputAttributes(attrs)) {
2422
+ if (attrs.type === "checkbox" && typeof attrs.value === "undefined") {
2423
+ attrs.value = false;
2424
+ }
2425
+ if (attrs.name === "method" || attrs.type === "submit" || typeof attrs.value === "undefined") {
2426
+ return acc;
2427
+ }
2428
+ return unrollTrait(
2429
+ {
2430
+ name: attrs.name,
2431
+ value: attrs.value
2432
+ },
2433
+ acc
2434
+ );
2435
+ }
2436
+ return acc;
2437
+ }, {});
2438
+ }
2439
+ function unrollTrait(input, output = {}) {
2440
+ const keys = input.name.split(".");
2441
+ let current = output;
2442
+ keys.forEach((key, index) => {
2443
+ if (!key) return;
2444
+ current = current[key] = index === keys.length - 1 ? input.value : current[key] || {};
2445
+ });
2446
+ return output;
2447
+ }
2678
2448
 
2679
2449
  // src/components/form/form-resolver.ts
2680
2450
  function isCodeResendRequest(data) {
@@ -2701,78 +2471,320 @@ function useOryFormResolver() {
2701
2471
  };
2702
2472
  }
2703
2473
  }
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()
2474
+ return {
2475
+ values: data,
2476
+ errors: {}
2477
+ };
2478
+ };
2479
+ }
2480
+ function OryFormProvider({
2481
+ children,
2482
+ nodes
2483
+ }) {
2484
+ const flowContainer = useOryFlow();
2485
+ const defaultNodes = nodes ? flowContainer.flow.ui.nodes.filter((node) => node.group === UiNodeGroupEnum.Default).concat(nodes) : flowContainer.flow.ui.nodes;
2486
+ const methods = useForm({
2487
+ // TODO: Generify this, so we have typesafety in the submit handler.
2488
+ defaultValues: computeDefaultValues(defaultNodes),
2489
+ resolver: useOryFormResolver()
2490
+ });
2491
+ return /* @__PURE__ */ jsx(FormProvider, { ...methods, children });
2492
+ }
2493
+ function OryFormOidcButtons({
2494
+ children,
2495
+ hideDivider
2496
+ }) {
2497
+ const {
2498
+ flow: { ui }
2499
+ } = useOryFlow();
2500
+ const { setValue } = useFormContext();
2501
+ const filteredNodes = ui.nodes.filter((node) => node.group === "oidc");
2502
+ const { Form, Card, Node: Node2 } = useComponents();
2503
+ if (filteredNodes.length === 0) {
2504
+ return null;
2505
+ }
2506
+ const otherNodes = ui.nodes.filter(
2507
+ (node) => node.group !== "oidc" && node.group !== "default"
2508
+ );
2509
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2510
+ /* @__PURE__ */ jsx(Form.OidcRoot, { nodes: filteredNodes, children: children != null ? children : filteredNodes.map((node, k) => {
2511
+ return /* @__PURE__ */ jsx(
2512
+ Node2.OidcButton,
2513
+ {
2514
+ node,
2515
+ attributes: node.attributes,
2516
+ onClick: () => {
2517
+ setValue(
2518
+ "provider",
2519
+ node.attributes.value
2520
+ );
2521
+ setValue("method", "oidc");
2522
+ }
2523
+ },
2524
+ k
2525
+ );
2526
+ }) }),
2527
+ !hideDivider && filteredNodes.length > 0 && otherNodes.length > 0 && /* @__PURE__ */ jsx(Card.Divider, {})
2528
+ ] });
2529
+ }
2530
+ function OryFormSocialButtonsForm() {
2531
+ const {
2532
+ flow: { ui }
2533
+ } = useOryFlow();
2534
+ const filteredNodes = ui.nodes.filter((node) => node.group === "oidc");
2535
+ if (filteredNodes.length === 0) {
2536
+ return null;
2537
+ }
2538
+ return /* @__PURE__ */ jsx(OryFormProvider, { children: /* @__PURE__ */ jsx(OryForm, { children: /* @__PURE__ */ jsx(OryFormOidcButtons, {}) }) });
2539
+ }
2540
+ function frontendClient(sdkUrl, opts = {}) {
2541
+ const config = new Configuration({
2542
+ ...opts,
2543
+ basePath: sdkUrl,
2544
+ headers: {
2545
+ Accept: "application/json",
2546
+ ...opts.headers
2547
+ }
2548
+ });
2549
+ return new FrontendApi(config);
2550
+ }
2551
+
2552
+ // src/util/onSubmitLogin.ts
2553
+ async function onSubmitLogin({ config, flow }, {
2554
+ setFlowContainer,
2555
+ body,
2556
+ onRedirect
2557
+ }) {
2558
+ var _a;
2559
+ if (!config.sdk.url) {
2560
+ throw new Error(
2561
+ `Please supply your Ory Network SDK url to the Ory Elements configuration.`
2562
+ );
2563
+ }
2564
+ await frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {}).updateLoginFlowRaw({
2565
+ flow: flow.id,
2566
+ updateLoginFlowBody: body
2567
+ }).then(() => {
2568
+ var _a2;
2569
+ window.location.href = // eslint-disable-next-line promise/always-return
2570
+ (_a2 = flow.return_to) != null ? _a2 : config.sdk.url + "/self-service/login/browser";
2571
+ }).catch(
2572
+ handleFlowError({
2573
+ onRestartFlow: () => {
2574
+ onRedirect(loginUrl(config), true);
2575
+ },
2576
+ onValidationError: (body2) => {
2577
+ setFlowContainer({
2578
+ config,
2579
+ flow: body2,
2580
+ flowType: FlowType.Login
2581
+ });
2582
+ },
2583
+ onRedirect
2584
+ })
2585
+ );
2586
+ }
2587
+ async function onSubmitRecovery({ config, flow }, {
2588
+ setFlowContainer,
2589
+ body,
2590
+ onRedirect
2591
+ }) {
2592
+ var _a;
2593
+ if (!config.sdk.url) {
2594
+ throw new Error(
2595
+ `Please supply your Ory Network SDK url to the Ory Elements configuration.`
2596
+ );
2597
+ }
2598
+ await frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {}).updateRecoveryFlowRaw({
2599
+ flow: flow.id,
2600
+ updateRecoveryFlowBody: body
2601
+ }).then(async (res) => {
2602
+ const flow2 = await res.value();
2603
+ const didContinueWith = handleContinueWith(flow2.continue_with, {
2604
+ onRedirect
2605
+ });
2606
+ if (didContinueWith) {
2607
+ return;
2608
+ }
2609
+ setFlowContainer({
2610
+ flow: flow2,
2611
+ flowType: FlowType.Recovery,
2612
+ config
2613
+ });
2614
+ }).catch(
2615
+ handleFlowError({
2616
+ onRestartFlow: () => {
2617
+ onRedirect(recoveryUrl(config), true);
2618
+ },
2619
+ onValidationError: (body2) => {
2620
+ if ("error" in body2) {
2621
+ handleContinueWithRecoveryUIError(body2.error, config, onRedirect);
2622
+ return;
2623
+ } else {
2624
+ setFlowContainer({
2625
+ flow: body2,
2626
+ flowType: FlowType.Recovery,
2627
+ config
2628
+ });
2629
+ }
2630
+ },
2631
+ onRedirect
2632
+ })
2633
+ );
2634
+ }
2635
+ function handleContinueWithRecoveryUIError(error, config, onRedirect) {
2636
+ if ("continue_with" in error.details && Array.isArray(error.details.continue_with)) {
2637
+ const continueWithRecovery = error.details.continue_with.find(instanceOfContinueWithRecoveryUi);
2638
+ if ((continueWithRecovery == null ? void 0 : continueWithRecovery.action) === "show_recovery_ui") {
2639
+ onRedirect(
2640
+ config.project.recovery_ui_url + "?flow=" + (continueWithRecovery == null ? void 0 : continueWithRecovery.flow.id),
2641
+ false
2642
+ );
2643
+ return;
2644
+ }
2645
+ }
2646
+ onRedirect(recoveryUrl(config), true);
2647
+ }
2648
+ async function onSubmitRegistration({ config, flow }, {
2649
+ setFlowContainer,
2650
+ body,
2651
+ onRedirect
2652
+ }) {
2653
+ var _a;
2654
+ if (!config.sdk.url) {
2655
+ throw new Error(
2656
+ `Please supply your Ory Network SDK url to the Ory Elements configuration.`
2657
+ );
2658
+ }
2659
+ const client = frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {});
2660
+ await client.updateRegistrationFlowRaw({
2661
+ flow: flow.id,
2662
+ updateRegistrationFlowBody: body
2663
+ }).then(async (res) => {
2664
+ const body2 = await res.value();
2665
+ const didContinueWith = handleContinueWith(body2.continue_with, {
2666
+ onRedirect
2667
+ });
2668
+ if (didContinueWith) {
2669
+ return;
2670
+ }
2671
+ onRedirect(registrationUrl(config), true);
2672
+ }).catch(
2673
+ handleFlowError({
2674
+ onRestartFlow: () => {
2675
+ onRedirect(registrationUrl(config), true);
2676
+ },
2677
+ onValidationError: (body2) => {
2678
+ setFlowContainer({
2679
+ flow: body2,
2680
+ flowType: FlowType.Registration,
2681
+ config
2682
+ });
2683
+ },
2684
+ onRedirect
2685
+ })
2686
+ );
2687
+ }
2688
+ async function onSubmitSettings({ config, flow }, {
2689
+ setFlowContainer,
2690
+ body,
2691
+ onRedirect
2692
+ }) {
2693
+ var _a;
2694
+ if (!config.sdk.url) {
2695
+ throw new Error(
2696
+ `Please supply your Ory Network SDK url to the Ory Elements configuration.`
2697
+ );
2698
+ }
2699
+ const client = frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {});
2700
+ await client.updateSettingsFlowRaw({
2701
+ flow: flow.id,
2702
+ updateSettingsFlowBody: body
2703
+ }).then(async (res) => {
2704
+ const body2 = await res.value();
2705
+ const didContinueWith = handleContinueWith(body2.continue_with, {
2706
+ onRedirect
2707
+ });
2708
+ if (didContinueWith) {
2709
+ return;
2710
+ }
2711
+ setFlowContainer({
2712
+ flow: body2,
2713
+ flowType: FlowType.Settings,
2714
+ config
2715
+ });
2716
+ }).catch(
2717
+ handleFlowError({
2718
+ onRestartFlow: () => {
2719
+ onRedirect(settingsUrl(config), true);
2720
+ },
2721
+ onValidationError: (body2) => {
2722
+ setFlowContainer({
2723
+ flow: body2,
2724
+ flowType: FlowType.Settings,
2725
+ config
2726
+ });
2727
+ },
2728
+ onRedirect
2729
+ })
2730
+ ).catch((err) => {
2731
+ if (isResponseError(err)) {
2732
+ if (err.response.status === 401) {
2733
+ return onRedirect(
2734
+ loginUrl(config) + "?return_to=" + settingsUrl(config),
2735
+ true
2736
+ );
2737
+ }
2738
+ throw err;
2739
+ }
2720
2740
  });
2721
- return /* @__PURE__ */ jsx(FormProvider, { ...methods, children });
2722
2741
  }
2723
- function OryFormOidcButtons({
2724
- children,
2725
- hideDivider
2742
+ async function onSubmitVerification({ config, flow }, {
2743
+ setFlowContainer,
2744
+ body,
2745
+ onRedirect
2726
2746
  }) {
2727
- const {
2728
- flow: { ui }
2729
- } = useOryFlow();
2730
- const { setValue } = useFormContext();
2731
- const filteredNodes = ui.nodes.filter((node) => node.group === "oidc");
2732
- const { Form, Card, Node: Node2 } = useComponents();
2733
- if (filteredNodes.length === 0) {
2734
- return null;
2747
+ var _a;
2748
+ if (!config.sdk.url) {
2749
+ throw new Error(
2750
+ `Please supply your Ory Network SDK URL to the Ory Elements configuration.`
2751
+ );
2735
2752
  }
2736
- const otherNodes = ui.nodes.filter(
2737
- (node) => node.group !== "oidc" && node.group !== "default"
2753
+ await frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {}).updateVerificationFlowRaw({
2754
+ flow: flow.id,
2755
+ updateVerificationFlowBody: body
2756
+ }).then(
2757
+ async (res) => setFlowContainer({
2758
+ flow: await res.value(),
2759
+ flowType: FlowType.Verification,
2760
+ config
2761
+ })
2762
+ ).catch(
2763
+ handleFlowError({
2764
+ onRestartFlow: () => {
2765
+ onRedirect(verificationUrl(config), true);
2766
+ },
2767
+ onValidationError: (body2) => {
2768
+ setFlowContainer({
2769
+ flow: body2,
2770
+ flowType: FlowType.Verification,
2771
+ config
2772
+ });
2773
+ },
2774
+ onRedirect
2775
+ })
2738
2776
  );
2739
- return /* @__PURE__ */ jsxs(Fragment, { children: [
2740
- /* @__PURE__ */ jsx(Form.OidcRoot, { nodes: filteredNodes, children: children != null ? children : filteredNodes.map((node, k) => {
2741
- return /* @__PURE__ */ jsx(
2742
- Node2.OidcButton,
2743
- {
2744
- node,
2745
- attributes: node.attributes,
2746
- onClick: () => {
2747
- setValue(
2748
- "provider",
2749
- node.attributes.value
2750
- );
2751
- setValue("method", "oidc");
2752
- }
2753
- },
2754
- k
2755
- );
2756
- }) }),
2757
- !hideDivider && filteredNodes.length > 0 && otherNodes.length > 0 && /* @__PURE__ */ jsx(Card.Divider, {})
2758
- ] });
2759
- }
2760
- function OryFormSocialButtonsForm() {
2761
- const {
2762
- flow: { ui }
2763
- } = useOryFlow();
2764
- const filteredNodes = ui.nodes.filter((node) => node.group === "oidc");
2765
- if (filteredNodes.length === 0) {
2766
- return null;
2767
- }
2768
- return /* @__PURE__ */ jsx(OryFormProvider, { children: /* @__PURE__ */ jsx(OryForm, { children: /* @__PURE__ */ jsx(OryFormOidcButtons, {}) }) });
2769
2777
  }
2770
- function OryForm({ children, onAfterSubmit }) {
2771
- var _a;
2772
- const { Form } = useComponents();
2778
+
2779
+ // src/components/form/useOryFormSubmit.ts
2780
+ var supportsSelectAccountPrompt = ["google", "github"];
2781
+ function useOryFormSubmit(onAfterSubmit) {
2773
2782
  const flowContainer = useOryFlow();
2774
2783
  const methods = useFormContext();
2775
- const intl = useIntl();
2784
+ const handleSuccess = (flow) => {
2785
+ flowContainer.setFlowContainer(flow);
2786
+ methods.reset(computeDefaultValues(flow.flow.ui.nodes));
2787
+ };
2776
2788
  const onRedirect = (url, external) => {
2777
2789
  if (external) {
2778
2790
  window.location.href = url;
@@ -2780,10 +2792,6 @@ function OryForm({ children, onAfterSubmit }) {
2780
2792
  }
2781
2793
  window.location.href = url;
2782
2794
  };
2783
- const handleSuccess = (flow) => {
2784
- flowContainer.setFlowContainer(flow);
2785
- methods.reset(computeDefaultValues(flow.flow.ui.nodes));
2786
- };
2787
2795
  const onSubmit = async (data) => {
2788
2796
  switch (flowContainer.flowType) {
2789
2797
  case FlowType.Login: {
@@ -2842,10 +2850,10 @@ function OryForm({ children, onAfterSubmit }) {
2842
2850
  if ("totp_unlink" in submitData) {
2843
2851
  submitData.method = "totp";
2844
2852
  }
2845
- if ("lookup_secret_confirm" in submitData || "lookup_secret_reveal" in submitData || "lookup_secret_regenerate" in submitData) {
2853
+ if ("lookup_secret_confirm" in submitData || "lookup_secret_reveal" in submitData || "lookup_secret_regenerate" in submitData || "lookup_secret_disable" in submitData) {
2846
2854
  submitData.method = "lookup_secret";
2847
2855
  }
2848
- if (submitData.method === "oidc") {
2856
+ if (submitData.method === "oidc" && submitData.link && supportsSelectAccountPrompt.includes(submitData.link)) {
2849
2857
  submitData.upstream_parameters = {
2850
2858
  prompt: "select_account"
2851
2859
  };
@@ -2870,8 +2878,20 @@ function OryForm({ children, onAfterSubmit }) {
2870
2878
  if ("code" in data) {
2871
2879
  methods.setValue("code", "");
2872
2880
  }
2881
+ if ("totp_code" in data) {
2882
+ methods.setValue("totp_code", "");
2883
+ }
2873
2884
  onAfterSubmit == null ? void 0 : onAfterSubmit(data.method);
2874
2885
  };
2886
+ return onSubmit;
2887
+ }
2888
+ function OryForm({ children, onAfterSubmit }) {
2889
+ var _a;
2890
+ const { Form } = useComponents();
2891
+ const flowContainer = useOryFlow();
2892
+ const methods = useFormContext();
2893
+ const intl = useIntl();
2894
+ const onSubmit = useOryFormSubmit(onAfterSubmit);
2875
2895
  const hasMethods = flowContainer.flow.ui.nodes.filter((node) => {
2876
2896
  if (isUiNodeInputAttributes(node.attributes)) {
2877
2897
  return node.attributes.name !== "csrf_token";
@@ -2928,9 +2948,31 @@ function OryCardValidationMessages({ ...props }) {
2928
2948
  }
2929
2949
  return /* @__PURE__ */ jsx(Message.Root, { ...props, children: messages == null ? void 0 : messages.map((message) => /* @__PURE__ */ jsx(Message.Content, { message }, message.id)) });
2930
2950
  }
2931
- function OryFormSection({ children, nodes }) {
2951
+ function OryFormSection({
2952
+ children,
2953
+ nodes,
2954
+ ...rest
2955
+ }) {
2956
+ return /* @__PURE__ */ jsx(OryFormProvider, { nodes, children: /* @__PURE__ */ jsx(OryFormSectionInner, { ...rest, children }) });
2957
+ }
2958
+ function OryFormSectionInner({
2959
+ children,
2960
+ ...rest
2961
+ }) {
2932
2962
  const { Card } = useComponents();
2933
- return /* @__PURE__ */ jsx(OryFormProvider, { nodes, children: /* @__PURE__ */ jsx(OryForm, { children: /* @__PURE__ */ jsx(Card.SettingsSection, { children }) }) });
2963
+ const flowContainer = useOryFlow();
2964
+ const onSubmit = useOryFormSubmit();
2965
+ const methods = useFormContext();
2966
+ return /* @__PURE__ */ jsx(
2967
+ Card.SettingsSection,
2968
+ {
2969
+ action: flowContainer.flow.ui.action,
2970
+ method: flowContainer.flow.ui.method,
2971
+ onSubmit: (e) => void methods.handleSubmit(onSubmit)(e),
2972
+ ...rest,
2973
+ children
2974
+ }
2975
+ );
2934
2976
  }
2935
2977
  function OryCardContent({ children }) {
2936
2978
  const { Card } = useComponents();
@@ -2984,7 +3026,7 @@ function OryTwoStepCard() {
2984
3026
  const {
2985
3027
  flow: { ui }
2986
3028
  } = useOryFlow();
2987
- const { Form } = useComponents();
3029
+ const { Form, Card } = useComponents();
2988
3030
  const { flowType, formState, dispatchFormState } = useOryFlow();
2989
3031
  const nodeSorter = useNodeSorter();
2990
3032
  const sortNodes = (a, b) => nodeSorter(a, b, { flowType });
@@ -3018,16 +3060,19 @@ function OryTwoStepCard() {
3018
3060
  children: [
3019
3061
  /* @__PURE__ */ jsxs(Form.Group, { children: [
3020
3062
  formState.current === "provide_identifier" && zeroStepGroups.sort(sortNodes).map((node, k) => /* @__PURE__ */ jsx(Node, { node }, k)),
3021
- formState.current === "select_method" && /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
3022
- AuthMethodList,
3023
- {
3024
- options,
3025
- setSelectedGroup: (group) => dispatchFormState({
3026
- type: "action_select_method",
3027
- method: group
3028
- })
3029
- }
3030
- ) }),
3063
+ formState.current === "select_method" && /* @__PURE__ */ jsxs(Fragment, { children: [
3064
+ /* @__PURE__ */ jsx(Card.Divider, {}),
3065
+ /* @__PURE__ */ jsx(
3066
+ AuthMethodList,
3067
+ {
3068
+ options,
3069
+ setSelectedGroup: (group) => dispatchFormState({
3070
+ type: "action_select_method",
3071
+ method: group
3072
+ })
3073
+ }
3074
+ )
3075
+ ] }),
3031
3076
  formState.current === "method_active" && /* @__PURE__ */ jsxs(Fragment, { children: [
3032
3077
  ui.nodes.filter((n) => n.type === "script").map((node, k) => /* @__PURE__ */ jsx(Node, { node }, k)),
3033
3078
  finalNodes.sort(sortNodes).map((node, k) => /* @__PURE__ */ jsx(Node, { node }, k))
@@ -3086,8 +3131,25 @@ var getUnlinkButtons = (nodes) => nodes.filter(
3086
3131
  function OrySettingsOidc({ nodes }) {
3087
3132
  const { Card, Form } = useComponents();
3088
3133
  const intl = useIntl();
3089
- const linkButtons = getLinkButtons(nodes);
3090
- const unlinkButtons = getUnlinkButtons(nodes);
3134
+ const { setValue } = useFormContext();
3135
+ const linkButtons = getLinkButtons(nodes).map((node) => ({
3136
+ ...node,
3137
+ onClick: () => {
3138
+ if (node.attributes.node_type === "input") {
3139
+ setValue("link", node.attributes.value);
3140
+ setValue("method", "oidc");
3141
+ }
3142
+ }
3143
+ }));
3144
+ const unlinkButtons = getUnlinkButtons(nodes).map((node) => ({
3145
+ ...node,
3146
+ onClick: () => {
3147
+ if (node.attributes.node_type === "input") {
3148
+ setValue("unlink", node.attributes.value);
3149
+ setValue("method", "oidc");
3150
+ }
3151
+ }
3152
+ }));
3091
3153
  return /* @__PURE__ */ jsxs(Fragment, { children: [
3092
3154
  /* @__PURE__ */ jsx(
3093
3155
  Card.SettingsSectionContent,
@@ -3103,7 +3165,12 @@ function OrySettingsOidc({ nodes }) {
3103
3165
  )
3104
3166
  }
3105
3167
  ),
3106
- /* @__PURE__ */ jsx(Card.SettingsSectionFooter, { children: /* @__PURE__ */ jsx("span", { children: intl.formatMessage({ id: "settings.oidc.info" }) }) })
3168
+ /* @__PURE__ */ jsx(
3169
+ Card.SettingsSectionFooter,
3170
+ {
3171
+ text: intl.formatMessage({ id: "settings.oidc.info" })
3172
+ }
3173
+ )
3107
3174
  ] });
3108
3175
  }
3109
3176
  var getTriggerNode = (nodes) => nodes.find(
@@ -3116,11 +3183,9 @@ var getRemoveNodes = (nodes) => nodes.filter(
3116
3183
  (node) => "name" in node.attributes && node.attributes.name === "passkey_remove"
3117
3184
  );
3118
3185
  function OrySettingsPasskey({ nodes }) {
3119
- var _a;
3120
3186
  const { Card, Form } = useComponents();
3121
3187
  const intl = useIntl();
3122
- const { flow } = useOryFlow();
3123
- const { groups } = useNodesGroups(flow.ui.nodes);
3188
+ const { setValue } = useFormContext();
3124
3189
  const triggerButton = getTriggerNode(nodes);
3125
3190
  const settingsNodes = getSettingsNodes(nodes);
3126
3191
  const removeNodes = getRemoveNodes(nodes);
@@ -3135,6 +3200,12 @@ function OrySettingsPasskey({ nodes }) {
3135
3200
  const onTriggerClick = () => {
3136
3201
  triggerToWindowCall(onclickTrigger);
3137
3202
  };
3203
+ const removePasskeyHandler = (value) => {
3204
+ return () => {
3205
+ setValue("passkey_remove", value);
3206
+ setValue("method", "passkey");
3207
+ };
3208
+ };
3138
3209
  return /* @__PURE__ */ jsxs(Fragment, { children: [
3139
3210
  /* @__PURE__ */ jsxs(
3140
3211
  Card.SettingsSectionContent,
@@ -3144,7 +3215,6 @@ function OrySettingsPasskey({ nodes }) {
3144
3215
  id: "settings.passkey.description"
3145
3216
  }),
3146
3217
  children: [
3147
- (_a = groups.default) == null ? void 0 : _a.map((node, i) => /* @__PURE__ */ jsx(Node, { node }, `passkey-default-nodes-${i}`)),
3148
3218
  settingsNodes.map((node, i) => /* @__PURE__ */ jsx(Node, { node }, `passkey-settings-nodes-${i}`)),
3149
3219
  /* @__PURE__ */ jsx(
3150
3220
  Form.PasskeySettings,
@@ -3154,13 +3224,22 @@ function OrySettingsPasskey({ nodes }) {
3154
3224
  attributes: triggerAttributes,
3155
3225
  onClick: onTriggerClick
3156
3226
  },
3157
- removeButtons: removeNodes
3227
+ removeButtons: removeNodes.map((node) => ({
3228
+ ...node,
3229
+ onClick: node.attributes.node_type === "input" ? removePasskeyHandler(node.attributes.value) : () => {
3230
+ }
3231
+ }))
3158
3232
  }
3159
3233
  )
3160
3234
  ]
3161
3235
  }
3162
3236
  ),
3163
- /* @__PURE__ */ jsx(Card.SettingsSectionFooter, { children: /* @__PURE__ */ jsx("span", { children: intl.formatMessage({ id: "settings.passkey.info" }) }) })
3237
+ /* @__PURE__ */ jsx(
3238
+ Card.SettingsSectionFooter,
3239
+ {
3240
+ text: intl.formatMessage({ id: "settings.passkey.info" })
3241
+ }
3242
+ )
3164
3243
  ] });
3165
3244
  }
3166
3245
  var getRegenerateNode = (nodes) => nodes.find(
@@ -3172,17 +3251,39 @@ var getRevealNode = (nodes) => nodes.find(
3172
3251
  var getRecoveryCodes = (nodes) => nodes.find(
3173
3252
  (node) => "id" in node.attributes && node.attributes.id === "lookup_secret_codes"
3174
3253
  );
3254
+ var getDisableNode = (nodes) => nodes.find(
3255
+ (node) => "name" in node.attributes && node.attributes.name === "lookup_secret_disable"
3256
+ );
3257
+ var getConfirmNode = (nodes) => nodes.find(
3258
+ (node) => "name" in node.attributes && node.attributes.name === "lookup_secret_confirm"
3259
+ );
3175
3260
  function OrySettingsRecoveryCodes({
3176
3261
  nodes
3177
3262
  }) {
3178
- var _a, _b;
3179
- const { Card, Form } = useComponents();
3263
+ var _a, _b, _c;
3264
+ const { Card, Form, Node: Node2 } = useComponents();
3180
3265
  const intl = useIntl();
3181
3266
  const codesNode = getRecoveryCodes(nodes);
3182
3267
  const revealNode = getRevealNode(nodes);
3183
3268
  const regenerateNode = getRegenerateNode(nodes);
3269
+ const disableNode = getDisableNode(nodes);
3270
+ const confirmNode = getConfirmNode(nodes);
3271
+ const { setValue } = useFormContext();
3184
3272
  const codesContext = (_b = (_a = codesNode == null ? void 0 : codesNode.attributes) == null ? void 0 : _a.text.context) != null ? _b : {};
3185
3273
  const secrets = codesContext.secrets ? codesContext.secrets.map((i) => i.text) : [];
3274
+ const onRegenerate = () => {
3275
+ if ((regenerateNode == null ? void 0 : regenerateNode.attributes.node_type) === "input") {
3276
+ setValue(regenerateNode == null ? void 0 : regenerateNode.attributes.name, "true");
3277
+ setValue("method", "lookup_secret");
3278
+ }
3279
+ };
3280
+ const onReveal = () => {
3281
+ if ((revealNode == null ? void 0 : revealNode.attributes.node_type) === "input") {
3282
+ setValue(revealNode == null ? void 0 : revealNode.attributes.name, "true");
3283
+ setValue("method", "lookup_secret");
3284
+ }
3285
+ };
3286
+ const footerNode = (_c = disableNode != null ? disableNode : regenerateNode) != null ? _c : confirmNode;
3186
3287
  return /* @__PURE__ */ jsxs(Fragment, { children: [
3187
3288
  /* @__PURE__ */ jsx(
3188
3289
  Card.SettingsSectionContent,
@@ -3196,14 +3297,20 @@ function OrySettingsRecoveryCodes({
3196
3297
  {
3197
3298
  codes: secrets,
3198
3299
  revealButton: revealNode,
3199
- regnerateButton: regenerateNode
3300
+ regnerateButton: regenerateNode,
3301
+ onRegenerate,
3302
+ onReveal
3200
3303
  }
3201
3304
  )
3202
3305
  }
3203
3306
  ),
3204
- /* @__PURE__ */ jsx(Card.SettingsSectionFooter, { children: nodes.filter(
3205
- (node) => "type" in node.attributes && node.attributes.type === "submit" && "name" in node.attributes && node.attributes.name !== "lookup_secret_reveal" && node.attributes.name !== "lookup_secret_regenerate"
3206
- ).map((node, k) => /* @__PURE__ */ jsx(Node, { node }, k)) })
3307
+ /* @__PURE__ */ jsx(Card.SettingsSectionFooter, { children: footerNode && /* @__PURE__ */ jsx(
3308
+ Node2.Button,
3309
+ {
3310
+ node: footerNode,
3311
+ attributes: footerNode.attributes
3312
+ }
3313
+ ) })
3207
3314
  ] });
3208
3315
  }
3209
3316
  var getQrCodeNode = (nodes) => nodes.find(
@@ -3224,37 +3331,49 @@ var getTotpLinkButton = (nodes) => nodes.find(
3224
3331
  function OrySettingsTotp({ nodes }) {
3225
3332
  const { Card, Form, Node: Node2 } = useComponents();
3226
3333
  const intl = useIntl();
3334
+ const { setValue } = useFormContext();
3227
3335
  const totpUnlink = getTotpUnlinkInput(nodes);
3228
3336
  const qrNode = getQrCodeNode(nodes);
3229
3337
  const secretNode = getTotpSecretNode(nodes);
3230
3338
  const totpCodeNode = getTotpInputNode(nodes);
3231
3339
  const totpLinkButton = getTotpLinkButton(nodes);
3232
- const props = {
3233
- totpImage: qrNode,
3234
- totpSecret: secretNode,
3235
- totpInput: totpCodeNode,
3236
- totpUnlink
3340
+ const handleUnlink = () => {
3341
+ if ((totpUnlink == null ? void 0 : totpUnlink.attributes.node_type) === "input") {
3342
+ setValue(totpUnlink.attributes.name, totpUnlink.attributes.value);
3343
+ setValue("method", "totp");
3344
+ }
3237
3345
  };
3238
- const content = /* @__PURE__ */ jsx(Form.TotpSettings, { ...props });
3239
3346
  return /* @__PURE__ */ jsxs(Fragment, { children: [
3240
3347
  /* @__PURE__ */ jsx(
3241
3348
  Card.SettingsSectionContent,
3242
3349
  {
3243
3350
  title: intl.formatMessage({ id: "settings.totp.title" }),
3244
3351
  description: intl.formatMessage({ id: "settings.totp.description" }),
3245
- children: content
3352
+ children: /* @__PURE__ */ jsx(
3353
+ Form.TotpSettings,
3354
+ {
3355
+ totpImage: qrNode,
3356
+ totpSecret: secretNode,
3357
+ totpInput: totpCodeNode,
3358
+ totpUnlink,
3359
+ onUnlink: handleUnlink
3360
+ }
3361
+ )
3246
3362
  }
3247
3363
  ),
3248
- /* @__PURE__ */ jsxs(Card.SettingsSectionFooter, { children: [
3249
- /* @__PURE__ */ jsx("span", { children: totpUnlink ? intl.formatMessage({ id: "settings.totp.info.linked" }) : intl.formatMessage({ id: "settings.totp.info.not-linked" }) }),
3250
- totpLinkButton && /* @__PURE__ */ jsx(
3251
- Node2.Button,
3252
- {
3253
- node: totpLinkButton,
3254
- attributes: totpLinkButton.attributes
3255
- }
3256
- )
3257
- ] })
3364
+ /* @__PURE__ */ jsx(
3365
+ Card.SettingsSectionFooter,
3366
+ {
3367
+ text: totpUnlink ? intl.formatMessage({ id: "settings.totp.info.linked" }) : intl.formatMessage({ id: "settings.totp.info.not-linked" }),
3368
+ children: totpLinkButton && /* @__PURE__ */ jsx(
3369
+ Node2.Button,
3370
+ {
3371
+ node: totpLinkButton,
3372
+ attributes: totpLinkButton.attributes
3373
+ }
3374
+ )
3375
+ }
3376
+ )
3258
3377
  ] });
3259
3378
  }
3260
3379
  var getInputNode = (nodes) => nodes.find(
@@ -3266,22 +3385,16 @@ var getTriggerNode2 = (nodes) => nodes.find(
3266
3385
  var getRemoveButtons = (nodes) => nodes.filter(
3267
3386
  (node) => "name" in node.attributes && node.attributes.name === "webauthn_remove"
3268
3387
  );
3269
- var getScriptNode = (nodes) => nodes.find(
3270
- (node) => "id" in node.attributes && node.attributes.id === "webauthn_script"
3271
- );
3272
3388
  var getRegisterNode = (nodes) => nodes.find(
3273
3389
  (node) => "name" in node.attributes && node.attributes.name === "webauthn_register"
3274
3390
  );
3275
3391
  function OrySettingsWebauthn({ nodes }) {
3276
- var _a;
3277
3392
  const { Card, Form } = useComponents();
3278
3393
  const intl = useIntl();
3279
- const { flow } = useOryFlow();
3280
- const { groups } = useNodesGroups(flow.ui.nodes);
3394
+ const { setValue } = useFormContext();
3281
3395
  const triggerButton = getTriggerNode2(nodes);
3282
3396
  const inputNode = getInputNode(nodes);
3283
3397
  const removeButtons = getRemoveButtons(nodes);
3284
- const scriptNode = getScriptNode(nodes);
3285
3398
  const registerNode = getRegisterNode(nodes);
3286
3399
  if (!inputNode || !triggerButton) {
3287
3400
  return null;
@@ -3294,6 +3407,12 @@ function OrySettingsWebauthn({ nodes }) {
3294
3407
  const onTriggerClick = () => {
3295
3408
  triggerToWindowCall(onclickTrigger);
3296
3409
  };
3410
+ const removeWebauthnKeyHandler = (value) => {
3411
+ return () => {
3412
+ setValue("webauthn_remove", value);
3413
+ setValue("method", "webauthn");
3414
+ };
3415
+ };
3297
3416
  return /* @__PURE__ */ jsxs(Fragment, { children: [
3298
3417
  /* @__PURE__ */ jsxs(
3299
3418
  Card.SettingsSectionContent,
@@ -3303,9 +3422,6 @@ function OrySettingsWebauthn({ nodes }) {
3303
3422
  id: "settings.webauthn.description"
3304
3423
  }),
3305
3424
  children: [
3306
- (_a = groups.default) == null ? void 0 : _a.map((node, i) => /* @__PURE__ */ jsx(Node, { node }, `webauthn-default-${i}`)),
3307
- scriptNode && /* @__PURE__ */ jsx(Node, { node: scriptNode }),
3308
- registerNode && /* @__PURE__ */ jsx(Node, { node: registerNode }),
3309
3425
  /* @__PURE__ */ jsx(
3310
3426
  Form.WebauthnSettings,
3311
3427
  {
@@ -3315,42 +3431,102 @@ function OrySettingsWebauthn({ nodes }) {
3315
3431
  attributes: triggerAttributes,
3316
3432
  onClick: onTriggerClick
3317
3433
  },
3318
- removeButtons
3434
+ removeButtons: removeButtons.map((node) => ({
3435
+ ...node,
3436
+ onClick: node.attributes.node_type === "input" ? removeWebauthnKeyHandler(node.attributes.value) : () => {
3437
+ }
3438
+ }))
3319
3439
  }
3320
- )
3440
+ ),
3441
+ registerNode && /* @__PURE__ */ jsx(Node, { node: registerNode })
3321
3442
  ]
3322
3443
  }
3323
3444
  ),
3324
- /* @__PURE__ */ jsx(Card.SettingsSectionFooter, { children: /* @__PURE__ */ jsx("span", { children: intl.formatMessage({ id: "settings.webauthn.info" }) }) })
3445
+ /* @__PURE__ */ jsx(
3446
+ Card.SettingsSectionFooter,
3447
+ {
3448
+ text: intl.formatMessage({ id: "settings.webauthn.info" })
3449
+ }
3450
+ )
3325
3451
  ] });
3326
3452
  }
3327
3453
  function SettingsSectionContent({ group, nodes }) {
3328
- var _a, _b, _c, _d, _e, _f;
3454
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
3329
3455
  const { Card } = useComponents();
3330
3456
  const intl = useIntl();
3331
3457
  const { flow } = useOryFlow();
3332
3458
  const uniqueGroups = useNodesGroups(flow.ui.nodes);
3333
3459
  if (group === UiNodeGroupEnum.Totp) {
3334
- return /* @__PURE__ */ jsx(OryFormSection, { nodes: uniqueGroups.groups.totp, children: /* @__PURE__ */ jsx(OrySettingsTotp, { nodes: (_a = uniqueGroups.groups.totp) != null ? _a : [] }) });
3460
+ return /* @__PURE__ */ jsxs(
3461
+ OryFormSection,
3462
+ {
3463
+ nodes: uniqueGroups.groups.totp,
3464
+ "data-testid": "totp-settings",
3465
+ children: [
3466
+ /* @__PURE__ */ jsx(OrySettingsTotp, { nodes: (_a = uniqueGroups.groups.totp) != null ? _a : [] }),
3467
+ (_b = uniqueGroups.groups.default) == null ? void 0 : _b.map((node, k) => /* @__PURE__ */ jsx(Node, { node }, k))
3468
+ ]
3469
+ }
3470
+ );
3335
3471
  }
3336
3472
  if (group === UiNodeGroupEnum.LookupSecret) {
3337
- return /* @__PURE__ */ jsx(OryFormSection, { nodes: uniqueGroups.groups.lookup_secret, children: /* @__PURE__ */ jsx(
3338
- OrySettingsRecoveryCodes,
3473
+ return /* @__PURE__ */ jsxs(
3474
+ OryFormSection,
3339
3475
  {
3340
- nodes: (_b = uniqueGroups.groups.lookup_secret) != null ? _b : []
3476
+ nodes: uniqueGroups.groups.lookup_secret,
3477
+ "data-testid": "recovery-codes-settings",
3478
+ children: [
3479
+ /* @__PURE__ */ jsx(
3480
+ OrySettingsRecoveryCodes,
3481
+ {
3482
+ nodes: (_c = uniqueGroups.groups.lookup_secret) != null ? _c : []
3483
+ }
3484
+ ),
3485
+ (_d = uniqueGroups.groups.default) == null ? void 0 : _d.map((node, k) => /* @__PURE__ */ jsx(Node, { node }, k))
3486
+ ]
3341
3487
  }
3342
- ) });
3488
+ );
3343
3489
  }
3344
3490
  if (group === UiNodeGroupEnum.Oidc) {
3345
- return /* @__PURE__ */ jsx(OryFormSection, { nodes: uniqueGroups.groups.oidc, children: /* @__PURE__ */ jsx(OrySettingsOidc, { nodes: (_c = uniqueGroups.groups.oidc) != null ? _c : [] }) });
3491
+ return /* @__PURE__ */ jsxs(
3492
+ OryFormSection,
3493
+ {
3494
+ nodes: uniqueGroups.groups.oidc,
3495
+ "data-testid": "oidc-settings",
3496
+ children: [
3497
+ /* @__PURE__ */ jsx(OrySettingsOidc, { nodes: (_e = uniqueGroups.groups.oidc) != null ? _e : [] }),
3498
+ (_f = uniqueGroups.groups.default) == null ? void 0 : _f.map((node, k) => /* @__PURE__ */ jsx(Node, { node }, k))
3499
+ ]
3500
+ }
3501
+ );
3346
3502
  }
3347
3503
  if (group === UiNodeGroupEnum.Webauthn) {
3348
- return /* @__PURE__ */ jsx(OryFormSection, { nodes: uniqueGroups.groups.webauthn, children: /* @__PURE__ */ jsx(OrySettingsWebauthn, { nodes: (_d = uniqueGroups.groups.webauthn) != null ? _d : [] }) });
3504
+ return /* @__PURE__ */ jsxs(
3505
+ OryFormSection,
3506
+ {
3507
+ nodes: uniqueGroups.groups.webauthn,
3508
+ "data-testid": "webauthn-settings",
3509
+ children: [
3510
+ /* @__PURE__ */ jsx(OrySettingsWebauthn, { nodes: (_g = uniqueGroups.groups.webauthn) != null ? _g : [] }),
3511
+ (_h = uniqueGroups.groups.default) == null ? void 0 : _h.map((node, k) => /* @__PURE__ */ jsx(Node, { node }, k))
3512
+ ]
3513
+ }
3514
+ );
3349
3515
  }
3350
3516
  if (group === UiNodeGroupEnum.Passkey) {
3351
- return /* @__PURE__ */ jsx(OryFormSection, { nodes: uniqueGroups.groups.passkey, children: /* @__PURE__ */ jsx(OrySettingsPasskey, { nodes: (_e = uniqueGroups.groups.passkey) != null ? _e : [] }) });
3517
+ return /* @__PURE__ */ jsxs(
3518
+ OryFormSection,
3519
+ {
3520
+ nodes: uniqueGroups.groups.passkey,
3521
+ "data-testid": "passkey-settings",
3522
+ children: [
3523
+ /* @__PURE__ */ jsx(OrySettingsPasskey, { nodes: (_i = uniqueGroups.groups.passkey) != null ? _i : [] }),
3524
+ (_j = uniqueGroups.groups.default) == null ? void 0 : _j.map((node, k) => /* @__PURE__ */ jsx(Node, { node }, k))
3525
+ ]
3526
+ }
3527
+ );
3352
3528
  }
3353
- return /* @__PURE__ */ jsxs(OryFormSection, { nodes, children: [
3529
+ return /* @__PURE__ */ jsxs(OryFormSection, { nodes, "data-testid": `${group}-settings`, children: [
3354
3530
  /* @__PURE__ */ jsxs(
3355
3531
  Card.SettingsSectionContent,
3356
3532
  {
@@ -3361,7 +3537,7 @@ function SettingsSectionContent({ group, nodes }) {
3361
3537
  id: `settings.${group}.description`
3362
3538
  }),
3363
3539
  children: [
3364
- (_f = uniqueGroups.groups.default) == null ? void 0 : _f.map((node, k) => /* @__PURE__ */ jsx(Node, { node }, k)),
3540
+ (_k = uniqueGroups.groups.default) == null ? void 0 : _k.map((node, k) => /* @__PURE__ */ jsx(Node, { node }, k)),
3365
3541
  nodes.filter(
3366
3542
  (node) => "type" in node.attributes && node.attributes.type !== "submit"
3367
3543
  ).map((node, k) => /* @__PURE__ */ jsx(Node, { node }, k))
@@ -3373,11 +3549,16 @@ function SettingsSectionContent({ group, nodes }) {
3373
3549
  ).map((node, k) => /* @__PURE__ */ jsx(Node, { node }, k)) })
3374
3550
  ] });
3375
3551
  }
3552
+ var getScriptNode = (nodes) => nodes.find(
3553
+ (node) => "id" in node.attributes && node.attributes.id === "webauthn_script"
3554
+ );
3376
3555
  function OrySettingsCard() {
3377
3556
  const { flow } = useOryFlow();
3378
3557
  const uniqueGroups = useNodesGroups(flow.ui.nodes);
3558
+ const scriptNode = getScriptNode(flow.ui.nodes);
3379
3559
  return /* @__PURE__ */ jsxs(Fragment, { children: [
3380
3560
  /* @__PURE__ */ jsx(OryCardValidationMessages, {}),
3561
+ scriptNode && /* @__PURE__ */ jsx(Node, { node: scriptNode }),
3381
3562
  uniqueGroups.entries.map(([group, nodes]) => {
3382
3563
  if (group === UiNodeGroupEnum.Default) {
3383
3564
  return null;