@worldcoin/idkit 4.0.9 → 4.0.10
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.cjs +60 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +62 -15
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -67,6 +67,7 @@ function toErrorCode(error) {
|
|
|
67
67
|
// src/hooks/useIDKitFlow.ts
|
|
68
68
|
var isDebug = () => typeof window !== "undefined" && window.IDKIT_DEBUG;
|
|
69
69
|
function useIDKitFlow(createFlowHandle, config) {
|
|
70
|
+
const isInWorldApp = react.useMemo(() => idkitCore.isInWorldApp(), []);
|
|
70
71
|
const [state, setState] = react.useState(
|
|
71
72
|
createInitialHookState
|
|
72
73
|
);
|
|
@@ -124,11 +125,12 @@ function useIDKitFlow(createFlowHandle, config) {
|
|
|
124
125
|
connectorURI: request.connectorURI,
|
|
125
126
|
requestId: request.requestId
|
|
126
127
|
});
|
|
128
|
+
const connectorURI = isInWorldApp ? null : request.connectorURI;
|
|
127
129
|
setState((prev) => {
|
|
128
|
-
if (prev.connectorURI ===
|
|
130
|
+
if (prev.connectorURI === connectorURI) {
|
|
129
131
|
return prev;
|
|
130
132
|
}
|
|
131
|
-
return { ...prev, connectorURI
|
|
133
|
+
return { ...prev, connectorURI };
|
|
132
134
|
});
|
|
133
135
|
const pollInterval = configRef.current.polling?.interval ?? 1e3;
|
|
134
136
|
const timeout = configRef.current.polling?.timeout ?? 3e5;
|
|
@@ -184,7 +186,7 @@ function useIDKitFlow(createFlowHandle, config) {
|
|
|
184
186
|
abortRef.current = null;
|
|
185
187
|
}
|
|
186
188
|
};
|
|
187
|
-
}, [state.isOpen, runId]);
|
|
189
|
+
}, [state.isOpen, runId, isInWorldApp]);
|
|
188
190
|
return {
|
|
189
191
|
open,
|
|
190
192
|
reset,
|
|
@@ -195,7 +197,8 @@ function useIDKitFlow(createFlowHandle, config) {
|
|
|
195
197
|
connectorURI: state.connectorURI,
|
|
196
198
|
result: state.result,
|
|
197
199
|
errorCode: state.errorCode,
|
|
198
|
-
isOpen: state.isOpen
|
|
200
|
+
isOpen: state.isOpen,
|
|
201
|
+
isInWorldApp
|
|
199
202
|
};
|
|
200
203
|
}
|
|
201
204
|
|
|
@@ -1640,7 +1643,8 @@ function getVisualStage(isSuccess, isError, isHostVerifying) {
|
|
|
1640
1643
|
if (isSuccess) return "success";
|
|
1641
1644
|
return "worldid";
|
|
1642
1645
|
}
|
|
1643
|
-
function
|
|
1646
|
+
function IDKitWidgetBase({
|
|
1647
|
+
flow,
|
|
1644
1648
|
open,
|
|
1645
1649
|
onOpenChange,
|
|
1646
1650
|
handleVerify,
|
|
@@ -1648,12 +1652,8 @@ function IDKitRequestWidget({
|
|
|
1648
1652
|
onError,
|
|
1649
1653
|
autoClose = true,
|
|
1650
1654
|
language,
|
|
1651
|
-
|
|
1655
|
+
showSimulatorCallout
|
|
1652
1656
|
}) {
|
|
1653
|
-
if (typeof onSuccess !== "function") {
|
|
1654
|
-
throw new Error("IDKitRequestWidget requires an onSuccess callback.");
|
|
1655
|
-
}
|
|
1656
|
-
const flow = useIDKitRequest(config);
|
|
1657
1657
|
const { open: openFlow, reset: resetFlow } = flow;
|
|
1658
1658
|
const [hostVerifyResult, setHostVerifyResult] = react.useState(null);
|
|
1659
1659
|
const lastResultRef = react.useRef(null);
|
|
@@ -1695,13 +1695,31 @@ function IDKitRequestWidget({
|
|
|
1695
1695
|
});
|
|
1696
1696
|
}, [effectiveErrorCode, onError]);
|
|
1697
1697
|
react.useEffect(() => {
|
|
1698
|
-
if (
|
|
1698
|
+
if (!flow.isInWorldApp || !isHostVerifying || !flow.result || !handleVerify) {
|
|
1699
|
+
return;
|
|
1700
|
+
}
|
|
1701
|
+
let cancelled = false;
|
|
1702
|
+
void Promise.resolve(handleVerify(flow.result)).then(() => {
|
|
1703
|
+
if (!cancelled) setHostVerifyResult("passed");
|
|
1704
|
+
}).catch(() => {
|
|
1705
|
+
if (!cancelled) setHostVerifyResult("failed");
|
|
1706
|
+
});
|
|
1707
|
+
return () => {
|
|
1708
|
+
cancelled = true;
|
|
1709
|
+
};
|
|
1710
|
+
}, [flow.isInWorldApp, isHostVerifying, flow.result, handleVerify]);
|
|
1711
|
+
react.useEffect(() => {
|
|
1712
|
+
if (flow.isInWorldApp && (isSuccess || isError)) {
|
|
1713
|
+
onOpenChange(false);
|
|
1714
|
+
} else if (isSuccess && autoClose) {
|
|
1699
1715
|
const timer = setTimeout(() => onOpenChange(false), 2500);
|
|
1700
1716
|
return () => clearTimeout(timer);
|
|
1701
1717
|
}
|
|
1702
|
-
}, [isSuccess, autoClose, onOpenChange]);
|
|
1718
|
+
}, [isSuccess, isError, autoClose, onOpenChange, flow.isInWorldApp]);
|
|
1719
|
+
if (flow.isInWorldApp) {
|
|
1720
|
+
return null;
|
|
1721
|
+
}
|
|
1703
1722
|
const stage = getVisualStage(isSuccess, isError, isHostVerifying);
|
|
1704
|
-
const showSimulatorCallout = config.environment === "staging";
|
|
1705
1723
|
return /* @__PURE__ */ jsxRuntime.jsxs(IDKitModal, { open, onOpenChange, children: [
|
|
1706
1724
|
stage === "worldid" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1707
1725
|
WorldIDState,
|
|
@@ -1735,6 +1753,35 @@ function IDKitRequestWidget({
|
|
|
1735
1753
|
)
|
|
1736
1754
|
] });
|
|
1737
1755
|
}
|
|
1756
|
+
function IDKitRequestWidget({
|
|
1757
|
+
open,
|
|
1758
|
+
onOpenChange,
|
|
1759
|
+
handleVerify,
|
|
1760
|
+
onSuccess,
|
|
1761
|
+
onError,
|
|
1762
|
+
autoClose,
|
|
1763
|
+
language,
|
|
1764
|
+
...config
|
|
1765
|
+
}) {
|
|
1766
|
+
if (typeof onSuccess !== "function") {
|
|
1767
|
+
throw new Error("IDKitRequestWidget requires an onSuccess callback.");
|
|
1768
|
+
}
|
|
1769
|
+
const flow = useIDKitRequest(config);
|
|
1770
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1771
|
+
IDKitWidgetBase,
|
|
1772
|
+
{
|
|
1773
|
+
flow,
|
|
1774
|
+
open,
|
|
1775
|
+
onOpenChange,
|
|
1776
|
+
handleVerify,
|
|
1777
|
+
onSuccess,
|
|
1778
|
+
onError,
|
|
1779
|
+
autoClose,
|
|
1780
|
+
language,
|
|
1781
|
+
showSimulatorCallout: config.environment === "staging"
|
|
1782
|
+
}
|
|
1783
|
+
);
|
|
1784
|
+
}
|
|
1738
1785
|
|
|
1739
1786
|
Object.defineProperty(exports, "IDKit", {
|
|
1740
1787
|
enumerable: true,
|