@ory/elements-react 0.0.0-pr.6ecad3e0 → 0.0.0-pr.75b46aac

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.js CHANGED
@@ -370,6 +370,11 @@ function useFormStateReducer(flow) {
370
370
  setSelectedMethod(action2.method);
371
371
  return { current: "method_active", method: action2.method };
372
372
  }
373
+ case "action_method_selector": {
374
+ return {
375
+ current: "select_method"
376
+ };
377
+ }
373
378
  }
374
379
  return state;
375
380
  };
@@ -408,6 +413,110 @@ function OryFlowProvider({
408
413
  }
409
414
  );
410
415
  }
416
+
417
+ // src/client/config.ts
418
+ function isProduction() {
419
+ var _a, _b;
420
+ return ["production", "prod"].indexOf(
421
+ (_b = (_a = process.env.VERCEL_ENV) != null ? _a : process.env.NODE_ENV) != null ? _b : ""
422
+ ) > -1;
423
+ }
424
+ function frontendClient(sdkUrl, opts = {}) {
425
+ const config = new clientFetch.Configuration({
426
+ ...opts,
427
+ basePath: sdkUrl,
428
+ credentials: "include",
429
+ headers: {
430
+ Accept: "application/json",
431
+ ...opts.headers
432
+ }
433
+ });
434
+ return new clientFetch.FrontendApi(config);
435
+ }
436
+ var defaultProject = {
437
+ name: "Ory",
438
+ registration_enabled: true,
439
+ verification_enabled: true,
440
+ recovery_enabled: true,
441
+ recovery_ui_url: "/ui/recovery",
442
+ registration_ui_url: "/ui/registration",
443
+ verification_ui_url: "/ui/verification",
444
+ login_ui_url: "/ui/login",
445
+ settings_ui_url: "/ui/settings",
446
+ default_redirect_url: "/ui/welcome",
447
+ error_ui_url: "/ui/error",
448
+ default_locale: "en",
449
+ locale_behavior: "force_default"
450
+ };
451
+ function useOryConfiguration() {
452
+ const configCtx = react.useContext(OryConfigurationContext);
453
+ return {
454
+ sdk: {
455
+ ...configCtx.sdk,
456
+ frontend: frontendClient(configCtx.sdk.url, configCtx.sdk.options)
457
+ },
458
+ project: {
459
+ ...configCtx.project
460
+ }
461
+ };
462
+ }
463
+ var OryConfigurationContext = react.createContext({
464
+ sdk: computeSdkConfig({}),
465
+ project: defaultProject
466
+ });
467
+ function OryConfigurationProvider({
468
+ children,
469
+ sdk: initialConfig,
470
+ project
471
+ }) {
472
+ const configRef = react.useRef({
473
+ sdk: computeSdkConfig(initialConfig),
474
+ project: {
475
+ ...defaultProject,
476
+ ...project
477
+ }
478
+ });
479
+ return /* @__PURE__ */ jsxRuntime.jsx(OryConfigurationContext.Provider, { value: configRef.current, children });
480
+ }
481
+ function computeSdkConfig(config) {
482
+ if ((config == null ? void 0 : config.url) && typeof config.url === "string") {
483
+ console.debug("Using sdk url from config");
484
+ return {
485
+ url: config.url.replace(/\/$/, ""),
486
+ options: config.options || {}
487
+ };
488
+ }
489
+ return {
490
+ url: getSDKUrl(),
491
+ options: (config == null ? void 0 : config.options) || {}
492
+ };
493
+ }
494
+ function getSDKUrl() {
495
+ var _a;
496
+ if (typeof process !== "undefined" && process.versions && process.versions.node) {
497
+ if (isProduction()) {
498
+ const sdkUrl = (_a = process.env["NEXT_PUBLIC_ORY_SDK_URL"]) != null ? _a : process.env["ORY_SDK_URL"];
499
+ if (!sdkUrl) {
500
+ throw new Error(
501
+ "Unable to determine SDK URL. Please set NEXT_PUBLIC_ORY_SDK_URL and/or ORY_SDK_URL in production environments."
502
+ );
503
+ }
504
+ return sdkUrl.replace(/\/$/, "");
505
+ } else {
506
+ if (process.env["__NEXT_PRIVATE_ORIGIN"]) {
507
+ return process.env["__NEXT_PRIVATE_ORIGIN"].replace(/\/$/, "");
508
+ } else if (process.env["VERCEL_URL"]) {
509
+ return `https://${process.env["VERCEL_URL"]}`.replace(/\/$/, "");
510
+ }
511
+ }
512
+ }
513
+ if (typeof window !== "undefined") {
514
+ return window.location.origin;
515
+ }
516
+ throw new Error(
517
+ "Unable to determine SDK URL. Please set NEXT_PUBLIC_ORY_SDK_URL and/or ORY_SDK_URL or supply the sdk.url parameter in the Ory configuration."
518
+ );
519
+ }
411
520
  function mergeTranslations(customTranslations) {
412
521
  return Object.keys(customTranslations).reduce((acc, key) => {
413
522
  acc[key] = { ...OryLocales[key], ...customTranslations[key] };
@@ -437,17 +546,18 @@ var IntlProvider = ({
437
546
  function OryProvider({
438
547
  children,
439
548
  components: Components,
549
+ config,
440
550
  ...oryFlowProps
441
551
  }) {
442
552
  var _a, _b, _c;
443
- return /* @__PURE__ */ jsxRuntime.jsx(
553
+ return /* @__PURE__ */ jsxRuntime.jsx(OryConfigurationProvider, { sdk: config.sdk, project: config.project, children: /* @__PURE__ */ jsxRuntime.jsx(
444
554
  IntlProvider,
445
555
  {
446
- locale: (_b = (_a = oryFlowProps.config.intl) == null ? void 0 : _a.locale) != null ? _b : "en",
447
- customTranslations: (_c = oryFlowProps.config.intl) == null ? void 0 : _c.customTranslations,
556
+ locale: (_b = (_a = config.intl) == null ? void 0 : _a.locale) != null ? _b : "en",
557
+ customTranslations: (_c = config.intl) == null ? void 0 : _c.customTranslations,
448
558
  children: /* @__PURE__ */ jsxRuntime.jsx(OryFlowProvider, { ...oryFlowProps, children: /* @__PURE__ */ jsxRuntime.jsx(OryComponentProvider, { components: Components, children }) })
449
559
  }
450
- );
560
+ ) });
451
561
  }
452
562
  function OryCardHeader() {
453
563
  const { Card } = useComponents();
@@ -566,18 +676,6 @@ function OryCardContent({ children }) {
566
676
  const { Card } = useComponents();
567
677
  return /* @__PURE__ */ jsxRuntime.jsx(Card.Content, { children });
568
678
  }
569
- function frontendClient(sdkUrl, opts = {}) {
570
- const config = new clientFetch.Configuration({
571
- ...opts,
572
- basePath: sdkUrl,
573
- credentials: "include",
574
- headers: {
575
- Accept: "application/json",
576
- ...opts.headers
577
- }
578
- });
579
- return new clientFetch.FrontendApi(config);
580
- }
581
679
 
582
680
  // src/util/internal.ts
583
681
  function replaceWindowFlowId(flow) {
@@ -587,7 +685,7 @@ function replaceWindowFlowId(flow) {
587
685
  }
588
686
 
589
687
  // src/util/onSubmitLogin.ts
590
- async function onSubmitLogin({ config, flow }, {
688
+ async function onSubmitLogin({ flow }, config, {
591
689
  setFlowContainer,
592
690
  body,
593
691
  onRedirect
@@ -616,7 +714,6 @@ async function onSubmitLogin({ config, flow }, {
616
714
  },
617
715
  onValidationError: (body2) => {
618
716
  setFlowContainer({
619
- config,
620
717
  flow: body2,
621
718
  flowType: clientFetch.FlowType.Login
622
719
  });
@@ -625,18 +722,12 @@ async function onSubmitLogin({ config, flow }, {
625
722
  })
626
723
  );
627
724
  }
628
- async function onSubmitRecovery({ config, flow }, {
725
+ async function onSubmitRecovery({ flow }, config, {
629
726
  setFlowContainer,
630
727
  body,
631
728
  onRedirect
632
729
  }) {
633
- var _a;
634
- if (!config.sdk.url) {
635
- throw new Error(
636
- `Please supply your Ory Network SDK url to the Ory Elements configuration.`
637
- );
638
- }
639
- await frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {}).updateRecoveryFlowRaw({
730
+ await config.sdk.frontend.updateRecoveryFlowRaw({
640
731
  flow: flow.id,
641
732
  updateRecoveryFlowBody: body
642
733
  }).then(async (res) => {
@@ -649,8 +740,7 @@ async function onSubmitRecovery({ config, flow }, {
649
740
  }
650
741
  setFlowContainer({
651
742
  flow: flow2,
652
- flowType: clientFetch.FlowType.Recovery,
653
- config
743
+ flowType: clientFetch.FlowType.Recovery
654
744
  });
655
745
  }).catch(
656
746
  clientFetch.handleFlowError({
@@ -668,8 +758,7 @@ async function onSubmitRecovery({ config, flow }, {
668
758
  } else {
669
759
  setFlowContainer({
670
760
  flow: body2,
671
- flowType: clientFetch.FlowType.Recovery,
672
- config
761
+ flowType: clientFetch.FlowType.Recovery
673
762
  });
674
763
  }
675
764
  },
@@ -690,19 +779,12 @@ function handleContinueWithRecoveryUIError(error, config, onRedirect) {
690
779
  }
691
780
  onRedirect(clientFetch.recoveryUrl(config), true);
692
781
  }
693
- async function onSubmitRegistration({ config, flow }, {
782
+ async function onSubmitRegistration({ flow }, config, {
694
783
  setFlowContainer,
695
784
  body,
696
785
  onRedirect
697
786
  }) {
698
- var _a;
699
- if (!config.sdk.url) {
700
- throw new Error(
701
- `Please supply your Ory Network SDK url to the Ory Elements configuration.`
702
- );
703
- }
704
- const client = frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {});
705
- await client.updateRegistrationFlowRaw({
787
+ await config.sdk.frontend.updateRegistrationFlowRaw({
706
788
  flow: flow.id,
707
789
  updateRegistrationFlowBody: body
708
790
  }).then(async (res) => {
@@ -726,27 +808,19 @@ async function onSubmitRegistration({ config, flow }, {
726
808
  onValidationError: (body2) => {
727
809
  setFlowContainer({
728
810
  flow: body2,
729
- flowType: clientFetch.FlowType.Registration,
730
- config
811
+ flowType: clientFetch.FlowType.Registration
731
812
  });
732
813
  },
733
814
  onRedirect
734
815
  })
735
816
  );
736
817
  }
737
- async function onSubmitSettings({ config, flow }, {
818
+ async function onSubmitSettings({ flow }, config, {
738
819
  setFlowContainer,
739
820
  body,
740
821
  onRedirect
741
822
  }) {
742
- var _a;
743
- if (!config.sdk.url) {
744
- throw new Error(
745
- `Please supply your Ory Network SDK url to the Ory Elements configuration.`
746
- );
747
- }
748
- const client = frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {});
749
- await client.updateSettingsFlowRaw({
823
+ await config.sdk.frontend.updateSettingsFlowRaw({
750
824
  flow: flow.id,
751
825
  updateSettingsFlowBody: body
752
826
  }).then(async (res) => {
@@ -759,8 +833,7 @@ async function onSubmitSettings({ config, flow }, {
759
833
  }
760
834
  setFlowContainer({
761
835
  flow: body2,
762
- flowType: clientFetch.FlowType.Settings,
763
- config
836
+ flowType: clientFetch.FlowType.Settings
764
837
  });
765
838
  }).catch(
766
839
  clientFetch.handleFlowError({
@@ -774,8 +847,7 @@ async function onSubmitSettings({ config, flow }, {
774
847
  onValidationError: (body2) => {
775
848
  setFlowContainer({
776
849
  flow: body2,
777
- flowType: clientFetch.FlowType.Settings,
778
- config
850
+ flowType: clientFetch.FlowType.Settings
779
851
  });
780
852
  },
781
853
  onRedirect
@@ -792,25 +864,18 @@ async function onSubmitSettings({ config, flow }, {
792
864
  }
793
865
  });
794
866
  }
795
- async function onSubmitVerification({ config, flow }, {
867
+ async function onSubmitVerification({ flow }, config, {
796
868
  setFlowContainer,
797
869
  body,
798
870
  onRedirect
799
871
  }) {
800
- var _a;
801
- if (!config.sdk.url) {
802
- throw new Error(
803
- `Please supply your Ory Network SDK URL to the Ory Elements configuration.`
804
- );
805
- }
806
- await frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {}).updateVerificationFlowRaw({
872
+ await config.sdk.frontend.updateVerificationFlowRaw({
807
873
  flow: flow.id,
808
874
  updateVerificationFlowBody: body
809
875
  }).then(
810
876
  async (res) => setFlowContainer({
811
877
  flow: await res.value(),
812
- flowType: clientFetch.FlowType.Verification,
813
- config
878
+ flowType: clientFetch.FlowType.Verification
814
879
  })
815
880
  ).catch(
816
881
  clientFetch.handleFlowError({
@@ -824,8 +889,7 @@ async function onSubmitVerification({ config, flow }, {
824
889
  onValidationError: (body2) => {
825
890
  setFlowContainer({
826
891
  flow: body2,
827
- flowType: clientFetch.FlowType.Verification,
828
- config
892
+ flowType: clientFetch.FlowType.Verification
829
893
  });
830
894
  },
831
895
  onRedirect
@@ -838,6 +902,7 @@ var supportsSelectAccountPrompt = ["google", "github"];
838
902
  function useOryFormSubmit(onAfterSubmit) {
839
903
  const flowContainer = useOryFlow();
840
904
  const methods = reactHookForm.useFormContext();
905
+ const config = useOryConfiguration();
841
906
  const handleSuccess = (flow) => {
842
907
  flowContainer.setFlowContainer(flow);
843
908
  methods.reset(computeDefaultValues(flow.flow.ui.nodes));
@@ -854,7 +919,7 @@ function useOryFormSubmit(onAfterSubmit) {
854
919
  if (submitData.method === "code" && data.code) {
855
920
  submitData.resend = "";
856
921
  }
857
- await onSubmitLogin(flowContainer, {
922
+ await onSubmitLogin(flowContainer, config, {
858
923
  onRedirect,
859
924
  setFlowContainer: handleSuccess,
860
925
  body: submitData
@@ -868,7 +933,7 @@ function useOryFormSubmit(onAfterSubmit) {
868
933
  if (submitData.method === "code" && submitData.code) {
869
934
  submitData.resend = "";
870
935
  }
871
- await onSubmitRegistration(flowContainer, {
936
+ await onSubmitRegistration(flowContainer, config, {
872
937
  onRedirect,
873
938
  setFlowContainer: handleSuccess,
874
939
  body: submitData
@@ -876,7 +941,7 @@ function useOryFormSubmit(onAfterSubmit) {
876
941
  break;
877
942
  }
878
943
  case clientFetch.FlowType.Verification:
879
- await onSubmitVerification(flowContainer, {
944
+ await onSubmitVerification(flowContainer, config, {
880
945
  onRedirect,
881
946
  setFlowContainer: handleSuccess,
882
947
  body: data
@@ -889,7 +954,7 @@ function useOryFormSubmit(onAfterSubmit) {
889
954
  if (data.code) {
890
955
  submitData.email = "";
891
956
  }
892
- await onSubmitRecovery(flowContainer, {
957
+ await onSubmitRecovery(flowContainer, config, {
893
958
  onRedirect,
894
959
  setFlowContainer: handleSuccess,
895
960
  body: submitData
@@ -917,7 +982,7 @@ function useOryFormSubmit(onAfterSubmit) {
917
982
  if ("passkey_remove" in submitData) {
918
983
  submitData.method = "passkey";
919
984
  }
920
- await onSubmitSettings(flowContainer, {
985
+ await onSubmitSettings(flowContainer, config, {
921
986
  onRedirect,
922
987
  setFlowContainer: handleSuccess,
923
988
  body: submitData
@@ -4312,6 +4377,7 @@ exports.OryCardContent = OryCardContent;
4312
4377
  exports.OryCardFooter = OryCardFooter;
4313
4378
  exports.OryCardHeader = OryCardHeader;
4314
4379
  exports.OryCardValidationMessages = OryCardValidationMessages;
4380
+ exports.OryConfigurationProvider = OryConfigurationProvider;
4315
4381
  exports.OryConsentCard = OryConsentCard;
4316
4382
  exports.OryForm = OryForm;
4317
4383
  exports.OryFormGroupDivider = OryFormGroupDivider;
@@ -4327,6 +4393,7 @@ exports.messageTestId = messageTestId;
4327
4393
  exports.uiTextToFormattedMessage = uiTextToFormattedMessage;
4328
4394
  exports.useComponents = useComponents;
4329
4395
  exports.useNodeSorter = useNodeSorter;
4396
+ exports.useOryConfiguration = useOryConfiguration;
4330
4397
  exports.useOryFlow = useOryFlow;
4331
4398
  //# sourceMappingURL=index.js.map
4332
4399
  //# sourceMappingURL=index.js.map