@ory/elements-react 1.0.0-rc.2 → 1.0.0-rc.3
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/CHANGELOG.md +17 -0
- package/dist/index.d.mts +71 -69
- package/dist/index.d.ts +71 -69
- package/dist/index.js +134 -72
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +135 -75
- package/dist/index.mjs.map +1 -1
- package/dist/theme/default/index.js +735 -659
- package/dist/theme/default/index.js.map +1 -1
- package/dist/theme/default/index.mjs +652 -567
- package/dist/theme/default/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { UiNodeGroupEnum, isUiNodeInputAttributes, isUiNodeAnchorAttributes, isUiNodeImageAttributes, isUiNodeScriptAttributes, FlowType, getNodeId, isUiNodeTextAttributes, UiNodeInputAttributesTypeEnum, handleContinueWith, handleFlowError, settingsUrl, isResponseError, loginUrl, recoveryUrl, verificationUrl, registrationUrl,
|
|
2
|
-
import { createContext, useContext, useState, useMemo, useReducer,
|
|
1
|
+
import { UiNodeGroupEnum, isUiNodeInputAttributes, isUiNodeAnchorAttributes, isUiNodeImageAttributes, isUiNodeScriptAttributes, FlowType, getNodeId, Configuration, FrontendApi, isUiNodeTextAttributes, UiNodeInputAttributesTypeEnum, handleContinueWith, handleFlowError, settingsUrl, isResponseError, loginUrl, recoveryUrl, verificationUrl, registrationUrl, instanceOfContinueWithRecoveryUi } from '@ory/client-fetch';
|
|
2
|
+
import { createContext, useContext, useRef, useState, useMemo, useReducer, 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
5
|
import { useFormContext, useForm, FormProvider } from 'react-hook-form';
|
|
@@ -406,6 +406,110 @@ function OryFlowProvider({
|
|
|
406
406
|
}
|
|
407
407
|
);
|
|
408
408
|
}
|
|
409
|
+
|
|
410
|
+
// src/client/config.ts
|
|
411
|
+
function isProduction() {
|
|
412
|
+
var _a, _b;
|
|
413
|
+
return ["production", "prod"].indexOf(
|
|
414
|
+
(_b = (_a = process.env.VERCEL_ENV) != null ? _a : process.env.NODE_ENV) != null ? _b : ""
|
|
415
|
+
) > -1;
|
|
416
|
+
}
|
|
417
|
+
function frontendClient(sdkUrl, opts = {}) {
|
|
418
|
+
const config = new Configuration({
|
|
419
|
+
...opts,
|
|
420
|
+
basePath: sdkUrl,
|
|
421
|
+
credentials: "include",
|
|
422
|
+
headers: {
|
|
423
|
+
Accept: "application/json",
|
|
424
|
+
...opts.headers
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
return new FrontendApi(config);
|
|
428
|
+
}
|
|
429
|
+
var defaultProject = {
|
|
430
|
+
name: "Ory",
|
|
431
|
+
registration_enabled: true,
|
|
432
|
+
verification_enabled: true,
|
|
433
|
+
recovery_enabled: true,
|
|
434
|
+
recovery_ui_url: "/ui/recovery",
|
|
435
|
+
registration_ui_url: "/ui/registration",
|
|
436
|
+
verification_ui_url: "/ui/verification",
|
|
437
|
+
login_ui_url: "/ui/login",
|
|
438
|
+
settings_ui_url: "/ui/settings",
|
|
439
|
+
default_redirect_url: "/ui/welcome",
|
|
440
|
+
error_ui_url: "/ui/error",
|
|
441
|
+
default_locale: "en",
|
|
442
|
+
locale_behavior: "force_default"
|
|
443
|
+
};
|
|
444
|
+
function useOryConfiguration() {
|
|
445
|
+
const configCtx = useContext(OryConfigurationContext);
|
|
446
|
+
return {
|
|
447
|
+
sdk: {
|
|
448
|
+
...configCtx.sdk,
|
|
449
|
+
frontend: frontendClient(configCtx.sdk.url, configCtx.sdk.options)
|
|
450
|
+
},
|
|
451
|
+
project: {
|
|
452
|
+
...configCtx.project
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
var OryConfigurationContext = createContext({
|
|
457
|
+
sdk: computeSdkConfig({}),
|
|
458
|
+
project: defaultProject
|
|
459
|
+
});
|
|
460
|
+
function OryConfigurationProvider({
|
|
461
|
+
children,
|
|
462
|
+
sdk: initialConfig,
|
|
463
|
+
project
|
|
464
|
+
}) {
|
|
465
|
+
const configRef = useRef({
|
|
466
|
+
sdk: computeSdkConfig(initialConfig),
|
|
467
|
+
project: {
|
|
468
|
+
...defaultProject,
|
|
469
|
+
...project
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
return /* @__PURE__ */ jsx(OryConfigurationContext.Provider, { value: configRef.current, children });
|
|
473
|
+
}
|
|
474
|
+
function computeSdkConfig(config) {
|
|
475
|
+
if ((config == null ? void 0 : config.url) && typeof config.url === "string") {
|
|
476
|
+
console.debug("Using sdk url from config");
|
|
477
|
+
return {
|
|
478
|
+
url: config.url.replace(/\/$/, ""),
|
|
479
|
+
options: config.options || {}
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
return {
|
|
483
|
+
url: getSDKUrl(),
|
|
484
|
+
options: (config == null ? void 0 : config.options) || {}
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
function getSDKUrl() {
|
|
488
|
+
var _a;
|
|
489
|
+
if (typeof process !== "undefined" && process.versions && process.versions.node) {
|
|
490
|
+
if (isProduction()) {
|
|
491
|
+
const sdkUrl = (_a = process.env["NEXT_PUBLIC_ORY_SDK_URL"]) != null ? _a : process.env["ORY_SDK_URL"];
|
|
492
|
+
if (!sdkUrl) {
|
|
493
|
+
throw new Error(
|
|
494
|
+
"Unable to determine SDK URL. Please set NEXT_PUBLIC_ORY_SDK_URL and/or ORY_SDK_URL in production environments."
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
return sdkUrl.replace(/\/$/, "");
|
|
498
|
+
} else {
|
|
499
|
+
if (process.env["__NEXT_PRIVATE_ORIGIN"]) {
|
|
500
|
+
return process.env["__NEXT_PRIVATE_ORIGIN"].replace(/\/$/, "");
|
|
501
|
+
} else if (process.env["VERCEL_URL"]) {
|
|
502
|
+
return `https://${process.env["VERCEL_URL"]}`.replace(/\/$/, "");
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
if (typeof window !== "undefined") {
|
|
507
|
+
return window.location.origin;
|
|
508
|
+
}
|
|
509
|
+
throw new Error(
|
|
510
|
+
"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."
|
|
511
|
+
);
|
|
512
|
+
}
|
|
409
513
|
function mergeTranslations(customTranslations) {
|
|
410
514
|
return Object.keys(customTranslations).reduce((acc, key) => {
|
|
411
515
|
acc[key] = { ...OryLocales[key], ...customTranslations[key] };
|
|
@@ -435,17 +539,18 @@ var IntlProvider = ({
|
|
|
435
539
|
function OryProvider({
|
|
436
540
|
children,
|
|
437
541
|
components: Components,
|
|
542
|
+
config,
|
|
438
543
|
...oryFlowProps
|
|
439
544
|
}) {
|
|
440
545
|
var _a, _b, _c;
|
|
441
|
-
return /* @__PURE__ */ jsx(
|
|
546
|
+
return /* @__PURE__ */ jsx(OryConfigurationProvider, { sdk: config.sdk, project: config.project, children: /* @__PURE__ */ jsx(
|
|
442
547
|
IntlProvider,
|
|
443
548
|
{
|
|
444
|
-
locale: (_b = (_a =
|
|
445
|
-
customTranslations: (_c =
|
|
549
|
+
locale: (_b = (_a = config.intl) == null ? void 0 : _a.locale) != null ? _b : "en",
|
|
550
|
+
customTranslations: (_c = config.intl) == null ? void 0 : _c.customTranslations,
|
|
446
551
|
children: /* @__PURE__ */ jsx(OryFlowProvider, { ...oryFlowProps, children: /* @__PURE__ */ jsx(OryComponentProvider, { components: Components, children }) })
|
|
447
552
|
}
|
|
448
|
-
);
|
|
553
|
+
) });
|
|
449
554
|
}
|
|
450
555
|
function OryCardHeader() {
|
|
451
556
|
const { Card } = useComponents();
|
|
@@ -564,18 +669,6 @@ function OryCardContent({ children }) {
|
|
|
564
669
|
const { Card } = useComponents();
|
|
565
670
|
return /* @__PURE__ */ jsx(Card.Content, { children });
|
|
566
671
|
}
|
|
567
|
-
function frontendClient(sdkUrl, opts = {}) {
|
|
568
|
-
const config = new Configuration({
|
|
569
|
-
...opts,
|
|
570
|
-
basePath: sdkUrl,
|
|
571
|
-
credentials: "include",
|
|
572
|
-
headers: {
|
|
573
|
-
Accept: "application/json",
|
|
574
|
-
...opts.headers
|
|
575
|
-
}
|
|
576
|
-
});
|
|
577
|
-
return new FrontendApi(config);
|
|
578
|
-
}
|
|
579
672
|
|
|
580
673
|
// src/util/internal.ts
|
|
581
674
|
function replaceWindowFlowId(flow) {
|
|
@@ -585,7 +678,7 @@ function replaceWindowFlowId(flow) {
|
|
|
585
678
|
}
|
|
586
679
|
|
|
587
680
|
// src/util/onSubmitLogin.ts
|
|
588
|
-
async function onSubmitLogin({
|
|
681
|
+
async function onSubmitLogin({ flow }, config, {
|
|
589
682
|
setFlowContainer,
|
|
590
683
|
body,
|
|
591
684
|
onRedirect
|
|
@@ -614,7 +707,6 @@ async function onSubmitLogin({ config, flow }, {
|
|
|
614
707
|
},
|
|
615
708
|
onValidationError: (body2) => {
|
|
616
709
|
setFlowContainer({
|
|
617
|
-
config,
|
|
618
710
|
flow: body2,
|
|
619
711
|
flowType: FlowType.Login
|
|
620
712
|
});
|
|
@@ -623,18 +715,12 @@ async function onSubmitLogin({ config, flow }, {
|
|
|
623
715
|
})
|
|
624
716
|
);
|
|
625
717
|
}
|
|
626
|
-
async function onSubmitRecovery({
|
|
718
|
+
async function onSubmitRecovery({ flow }, config, {
|
|
627
719
|
setFlowContainer,
|
|
628
720
|
body,
|
|
629
721
|
onRedirect
|
|
630
722
|
}) {
|
|
631
|
-
|
|
632
|
-
if (!config.sdk.url) {
|
|
633
|
-
throw new Error(
|
|
634
|
-
`Please supply your Ory Network SDK url to the Ory Elements configuration.`
|
|
635
|
-
);
|
|
636
|
-
}
|
|
637
|
-
await frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {}).updateRecoveryFlowRaw({
|
|
723
|
+
await config.sdk.frontend.updateRecoveryFlowRaw({
|
|
638
724
|
flow: flow.id,
|
|
639
725
|
updateRecoveryFlowBody: body
|
|
640
726
|
}).then(async (res) => {
|
|
@@ -647,8 +733,7 @@ async function onSubmitRecovery({ config, flow }, {
|
|
|
647
733
|
}
|
|
648
734
|
setFlowContainer({
|
|
649
735
|
flow: flow2,
|
|
650
|
-
flowType: FlowType.Recovery
|
|
651
|
-
config
|
|
736
|
+
flowType: FlowType.Recovery
|
|
652
737
|
});
|
|
653
738
|
}).catch(
|
|
654
739
|
handleFlowError({
|
|
@@ -666,8 +751,7 @@ async function onSubmitRecovery({ config, flow }, {
|
|
|
666
751
|
} else {
|
|
667
752
|
setFlowContainer({
|
|
668
753
|
flow: body2,
|
|
669
|
-
flowType: FlowType.Recovery
|
|
670
|
-
config
|
|
754
|
+
flowType: FlowType.Recovery
|
|
671
755
|
});
|
|
672
756
|
}
|
|
673
757
|
},
|
|
@@ -688,19 +772,12 @@ function handleContinueWithRecoveryUIError(error, config, onRedirect) {
|
|
|
688
772
|
}
|
|
689
773
|
onRedirect(recoveryUrl(config), true);
|
|
690
774
|
}
|
|
691
|
-
async function onSubmitRegistration({
|
|
775
|
+
async function onSubmitRegistration({ flow }, config, {
|
|
692
776
|
setFlowContainer,
|
|
693
777
|
body,
|
|
694
778
|
onRedirect
|
|
695
779
|
}) {
|
|
696
|
-
|
|
697
|
-
if (!config.sdk.url) {
|
|
698
|
-
throw new Error(
|
|
699
|
-
`Please supply your Ory Network SDK url to the Ory Elements configuration.`
|
|
700
|
-
);
|
|
701
|
-
}
|
|
702
|
-
const client = frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {});
|
|
703
|
-
await client.updateRegistrationFlowRaw({
|
|
780
|
+
await config.sdk.frontend.updateRegistrationFlowRaw({
|
|
704
781
|
flow: flow.id,
|
|
705
782
|
updateRegistrationFlowBody: body
|
|
706
783
|
}).then(async (res) => {
|
|
@@ -724,27 +801,19 @@ async function onSubmitRegistration({ config, flow }, {
|
|
|
724
801
|
onValidationError: (body2) => {
|
|
725
802
|
setFlowContainer({
|
|
726
803
|
flow: body2,
|
|
727
|
-
flowType: FlowType.Registration
|
|
728
|
-
config
|
|
804
|
+
flowType: FlowType.Registration
|
|
729
805
|
});
|
|
730
806
|
},
|
|
731
807
|
onRedirect
|
|
732
808
|
})
|
|
733
809
|
);
|
|
734
810
|
}
|
|
735
|
-
async function onSubmitSettings({
|
|
811
|
+
async function onSubmitSettings({ flow }, config, {
|
|
736
812
|
setFlowContainer,
|
|
737
813
|
body,
|
|
738
814
|
onRedirect
|
|
739
815
|
}) {
|
|
740
|
-
|
|
741
|
-
if (!config.sdk.url) {
|
|
742
|
-
throw new Error(
|
|
743
|
-
`Please supply your Ory Network SDK url to the Ory Elements configuration.`
|
|
744
|
-
);
|
|
745
|
-
}
|
|
746
|
-
const client = frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {});
|
|
747
|
-
await client.updateSettingsFlowRaw({
|
|
816
|
+
await config.sdk.frontend.updateSettingsFlowRaw({
|
|
748
817
|
flow: flow.id,
|
|
749
818
|
updateSettingsFlowBody: body
|
|
750
819
|
}).then(async (res) => {
|
|
@@ -757,8 +826,7 @@ async function onSubmitSettings({ config, flow }, {
|
|
|
757
826
|
}
|
|
758
827
|
setFlowContainer({
|
|
759
828
|
flow: body2,
|
|
760
|
-
flowType: FlowType.Settings
|
|
761
|
-
config
|
|
829
|
+
flowType: FlowType.Settings
|
|
762
830
|
});
|
|
763
831
|
}).catch(
|
|
764
832
|
handleFlowError({
|
|
@@ -772,8 +840,7 @@ async function onSubmitSettings({ config, flow }, {
|
|
|
772
840
|
onValidationError: (body2) => {
|
|
773
841
|
setFlowContainer({
|
|
774
842
|
flow: body2,
|
|
775
|
-
flowType: FlowType.Settings
|
|
776
|
-
config
|
|
843
|
+
flowType: FlowType.Settings
|
|
777
844
|
});
|
|
778
845
|
},
|
|
779
846
|
onRedirect
|
|
@@ -790,25 +857,18 @@ async function onSubmitSettings({ config, flow }, {
|
|
|
790
857
|
}
|
|
791
858
|
});
|
|
792
859
|
}
|
|
793
|
-
async function onSubmitVerification({
|
|
860
|
+
async function onSubmitVerification({ flow }, config, {
|
|
794
861
|
setFlowContainer,
|
|
795
862
|
body,
|
|
796
863
|
onRedirect
|
|
797
864
|
}) {
|
|
798
|
-
|
|
799
|
-
if (!config.sdk.url) {
|
|
800
|
-
throw new Error(
|
|
801
|
-
`Please supply your Ory Network SDK URL to the Ory Elements configuration.`
|
|
802
|
-
);
|
|
803
|
-
}
|
|
804
|
-
await frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {}).updateVerificationFlowRaw({
|
|
865
|
+
await config.sdk.frontend.updateVerificationFlowRaw({
|
|
805
866
|
flow: flow.id,
|
|
806
867
|
updateVerificationFlowBody: body
|
|
807
868
|
}).then(
|
|
808
869
|
async (res) => setFlowContainer({
|
|
809
870
|
flow: await res.value(),
|
|
810
|
-
flowType: FlowType.Verification
|
|
811
|
-
config
|
|
871
|
+
flowType: FlowType.Verification
|
|
812
872
|
})
|
|
813
873
|
).catch(
|
|
814
874
|
handleFlowError({
|
|
@@ -822,8 +882,7 @@ async function onSubmitVerification({ config, flow }, {
|
|
|
822
882
|
onValidationError: (body2) => {
|
|
823
883
|
setFlowContainer({
|
|
824
884
|
flow: body2,
|
|
825
|
-
flowType: FlowType.Verification
|
|
826
|
-
config
|
|
885
|
+
flowType: FlowType.Verification
|
|
827
886
|
});
|
|
828
887
|
},
|
|
829
888
|
onRedirect
|
|
@@ -836,6 +895,7 @@ var supportsSelectAccountPrompt = ["google", "github"];
|
|
|
836
895
|
function useOryFormSubmit(onAfterSubmit) {
|
|
837
896
|
const flowContainer = useOryFlow();
|
|
838
897
|
const methods = useFormContext();
|
|
898
|
+
const config = useOryConfiguration();
|
|
839
899
|
const handleSuccess = (flow) => {
|
|
840
900
|
flowContainer.setFlowContainer(flow);
|
|
841
901
|
methods.reset(computeDefaultValues(flow.flow.ui.nodes));
|
|
@@ -852,7 +912,7 @@ function useOryFormSubmit(onAfterSubmit) {
|
|
|
852
912
|
if (submitData.method === "code" && data.code) {
|
|
853
913
|
submitData.resend = "";
|
|
854
914
|
}
|
|
855
|
-
await onSubmitLogin(flowContainer, {
|
|
915
|
+
await onSubmitLogin(flowContainer, config, {
|
|
856
916
|
onRedirect,
|
|
857
917
|
setFlowContainer: handleSuccess,
|
|
858
918
|
body: submitData
|
|
@@ -866,7 +926,7 @@ function useOryFormSubmit(onAfterSubmit) {
|
|
|
866
926
|
if (submitData.method === "code" && submitData.code) {
|
|
867
927
|
submitData.resend = "";
|
|
868
928
|
}
|
|
869
|
-
await onSubmitRegistration(flowContainer, {
|
|
929
|
+
await onSubmitRegistration(flowContainer, config, {
|
|
870
930
|
onRedirect,
|
|
871
931
|
setFlowContainer: handleSuccess,
|
|
872
932
|
body: submitData
|
|
@@ -874,7 +934,7 @@ function useOryFormSubmit(onAfterSubmit) {
|
|
|
874
934
|
break;
|
|
875
935
|
}
|
|
876
936
|
case FlowType.Verification:
|
|
877
|
-
await onSubmitVerification(flowContainer, {
|
|
937
|
+
await onSubmitVerification(flowContainer, config, {
|
|
878
938
|
onRedirect,
|
|
879
939
|
setFlowContainer: handleSuccess,
|
|
880
940
|
body: data
|
|
@@ -887,7 +947,7 @@ function useOryFormSubmit(onAfterSubmit) {
|
|
|
887
947
|
if (data.code) {
|
|
888
948
|
submitData.email = "";
|
|
889
949
|
}
|
|
890
|
-
await onSubmitRecovery(flowContainer, {
|
|
950
|
+
await onSubmitRecovery(flowContainer, config, {
|
|
891
951
|
onRedirect,
|
|
892
952
|
setFlowContainer: handleSuccess,
|
|
893
953
|
body: submitData
|
|
@@ -915,7 +975,7 @@ function useOryFormSubmit(onAfterSubmit) {
|
|
|
915
975
|
if ("passkey_remove" in submitData) {
|
|
916
976
|
submitData.method = "passkey";
|
|
917
977
|
}
|
|
918
|
-
await onSubmitSettings(flowContainer, {
|
|
978
|
+
await onSubmitSettings(flowContainer, config, {
|
|
919
979
|
onRedirect,
|
|
920
980
|
setFlowContainer: handleSuccess,
|
|
921
981
|
body: submitData
|
|
@@ -1235,7 +1295,7 @@ function OryTwoStepCardStateMethodActive({
|
|
|
1235
1295
|
onAfterSubmit: handleAfterFormSubmit(dispatchFormState),
|
|
1236
1296
|
children: /* @__PURE__ */ jsxs(Form.Group, { children: [
|
|
1237
1297
|
ui.nodes.filter(
|
|
1238
|
-
(n) => isUiNodeScriptAttributes(n.attributes) || n.group === UiNodeGroupEnum.
|
|
1298
|
+
(n) => isUiNodeScriptAttributes(n.attributes) || n.group === UiNodeGroupEnum.Default || n.group === UiNodeGroupEnum.Profile
|
|
1239
1299
|
).map((node, k) => /* @__PURE__ */ jsx(Node, { node }, k)),
|
|
1240
1300
|
finalNodes.sort(sortNodes).map((node, k) => /* @__PURE__ */ jsx(Node, { node }, k))
|
|
1241
1301
|
] })
|
|
@@ -4304,6 +4364,6 @@ var OryLocales = {
|
|
|
4304
4364
|
sv: sv_default
|
|
4305
4365
|
};
|
|
4306
4366
|
|
|
4307
|
-
export { HeadlessPageHeader, OryCard, OryCardContent, OryCardFooter, OryCardHeader, OryCardValidationMessages, OryConsentCard, OryForm, OryFormGroupDivider, OryFormGroups, OryFormOidcButtons, OryFormSection, OryFormSocialButtonsForm, OryLocales, OryProvider, OrySettingsCard, OryTwoStepCard, messageTestId, uiTextToFormattedMessage, useComponents, useNodeSorter, useOryFlow };
|
|
4367
|
+
export { HeadlessPageHeader, OryCard, OryCardContent, OryCardFooter, OryCardHeader, OryCardValidationMessages, OryConfigurationProvider, OryConsentCard, OryForm, OryFormGroupDivider, OryFormGroups, OryFormOidcButtons, OryFormSection, OryFormSocialButtonsForm, OryLocales, OryProvider, OrySettingsCard, OryTwoStepCard, messageTestId, uiTextToFormattedMessage, useComponents, useNodeSorter, useOryConfiguration, useOryFlow };
|
|
4308
4368
|
//# sourceMappingURL=index.mjs.map
|
|
4309
4369
|
//# sourceMappingURL=index.mjs.map
|