@worldcoin/idkit 4.0.1 → 4.0.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/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { IDKitErrorCodes, IDKit } from '@worldcoin/idkit-core';
2
- export { CredentialRequest, IDKit, IDKitErrorCodes, all, any, documentLegacy, orbLegacy, secureDocumentLegacy, signRequest } from '@worldcoin/idkit-core';
2
+ export { IDKit, IDKitErrorCodes, documentLegacy, orbLegacy, secureDocumentLegacy, selfieCheck, signRequest } from '@worldcoin/idkit-core';
3
3
  import { memo, useMemo, useRef, useEffect, useState, useCallback } from 'react';
4
4
  import { createPortal } from 'react-dom';
5
5
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
@@ -197,36 +197,6 @@ function useIDKitRequest(config) {
197
197
  config
198
198
  );
199
199
  }
200
- function assertSessionId(sessionId) {
201
- if (sessionId === void 0) {
202
- return void 0;
203
- }
204
- if (sessionId.trim().length === 0) {
205
- throw IDKitErrorCodes.MalformedRequest;
206
- }
207
- return sessionId;
208
- }
209
- function useIDKitSession(config) {
210
- return useIDKitFlow(() => {
211
- const existingSessionId = assertSessionId(config.existing_session_id);
212
- const builder = existingSessionId ? IDKit.proveSession(existingSessionId, {
213
- app_id: config.app_id,
214
- rp_context: config.rp_context,
215
- action_description: config.action_description,
216
- bridge_url: config.bridge_url,
217
- override_connect_base_url: config.override_connect_base_url,
218
- environment: config.environment
219
- }) : IDKit.createSession({
220
- app_id: config.app_id,
221
- rp_context: config.rp_context,
222
- action_description: config.action_description,
223
- bridge_url: config.bridge_url,
224
- override_connect_base_url: config.override_connect_base_url,
225
- environment: config.environment
226
- });
227
- return builder.preset(config.preset);
228
- }, config);
229
- }
230
200
 
231
201
  // src/styles/widgetStyles.ts
232
202
  var WIDGET_STYLES = `
@@ -523,6 +493,22 @@ var WIDGET_STYLES = `
523
493
  color: var(--idkit-text-secondary);
524
494
  }
525
495
 
496
+ /* Simulator callout (staging only) */
497
+ .idkit-simulator-callout {
498
+ margin: 12px 0 0;
499
+ font-size: 14px;
500
+ color: var(--idkit-text-secondary);
501
+ text-align: center;
502
+ }
503
+ .idkit-simulator-callout a {
504
+ color: var(--idkit-text-muted);
505
+ text-decoration: underline;
506
+ text-underline-offset: 2px;
507
+ }
508
+ .idkit-simulator-callout a:hover {
509
+ color: var(--idkit-text);
510
+ }
511
+
526
512
  /* Mobile deep-link button */
527
513
  .idkit-deeplink-btn {
528
514
  display: flex;
@@ -1181,7 +1167,10 @@ function QRPlaceholderIcon(props) {
1181
1167
  }
1182
1168
  );
1183
1169
  }
1184
- function QRState({ qrData }) {
1170
+ function QRState({
1171
+ qrData,
1172
+ showSimulatorCallout
1173
+ }) {
1185
1174
  const media = useMedia();
1186
1175
  const [copiedLink, setCopiedLink] = useState(false);
1187
1176
  const copyLink = useCallback(() => {
@@ -1220,13 +1209,27 @@ function QRState({ qrData }) {
1220
1209
  style: { cursor: "pointer" },
1221
1210
  children: /* @__PURE__ */ jsx(QRCode, { data: qrData, size: media === "mobile" ? 160 : 200 })
1222
1211
  }
1223
- ) : /* @__PURE__ */ jsx("div", { className: "idkit-qr-placeholder", children: /* @__PURE__ */ jsx(QRPlaceholderIcon, {}) }) }) })
1212
+ ) : /* @__PURE__ */ jsx("div", { className: "idkit-qr-placeholder", children: /* @__PURE__ */ jsx(QRPlaceholderIcon, {}) }) }) }),
1213
+ showSimulatorCallout && qrData && /* @__PURE__ */ jsxs("p", { className: "idkit-simulator-callout", children: [
1214
+ "Testing in staging?",
1215
+ " ",
1216
+ /* @__PURE__ */ jsx(
1217
+ "a",
1218
+ {
1219
+ href: `https://simulator.worldcoin.org?connect_url=${encodeURIComponent(qrData)}`,
1220
+ target: "_blank",
1221
+ rel: "noopener noreferrer",
1222
+ children: "Use the simulator"
1223
+ }
1224
+ )
1225
+ ] })
1224
1226
  ] })
1225
1227
  ] });
1226
1228
  }
1227
1229
  function WorldIDState({
1228
1230
  connectorURI,
1229
- isAwaitingUserConfirmation
1231
+ isAwaitingUserConfirmation,
1232
+ showSimulatorCallout
1230
1233
  }) {
1231
1234
  const media = useMedia();
1232
1235
  return /* @__PURE__ */ jsxs(
@@ -1256,7 +1259,13 @@ function WorldIDState({
1256
1259
  "div",
1257
1260
  {
1258
1261
  className: `idkit-qr-blur ${isAwaitingUserConfirmation ? "blurred" : ""}`,
1259
- children: /* @__PURE__ */ jsx("div", { style: { display: "flex", justifyContent: "center" }, children: /* @__PURE__ */ jsx(QRState, { qrData: connectorURI }) })
1262
+ children: /* @__PURE__ */ jsx("div", { style: { display: "flex", justifyContent: "center" }, children: /* @__PURE__ */ jsx(
1263
+ QRState,
1264
+ {
1265
+ qrData: connectorURI,
1266
+ showSimulatorCallout
1267
+ }
1268
+ ) })
1260
1269
  }
1261
1270
  )
1262
1271
  ] })
@@ -1617,90 +1626,14 @@ function IDKitRequestWidget({
1617
1626
  }
1618
1627
  }, [flow.isSuccess, autoClose, onOpenChange]);
1619
1628
  const stage = getVisualStage(flow.isSuccess, flow.isError);
1629
+ const showSimulatorCallout = config.environment === "staging";
1620
1630
  return /* @__PURE__ */ jsxs(IDKitModal, { open, onOpenChange, children: [
1621
1631
  stage === "worldid" && /* @__PURE__ */ jsx(
1622
1632
  WorldIDState,
1623
1633
  {
1624
1634
  connectorURI: flow.connectorURI,
1625
- isAwaitingUserConfirmation: flow.isAwaitingUserConfirmation
1626
- }
1627
- ),
1628
- stage === "success" && /* @__PURE__ */ jsx(SuccessState, {}),
1629
- stage === "error" && /* @__PURE__ */ jsx(
1630
- ErrorState,
1631
- {
1632
- errorCode: flow.errorCode,
1633
- onRetry: () => {
1634
- resetFlow();
1635
- openFlow();
1636
- }
1637
- }
1638
- )
1639
- ] });
1640
- }
1641
- function getVisualStage2(isSuccess, isError) {
1642
- if (isSuccess) {
1643
- return "success";
1644
- }
1645
- if (isError) {
1646
- return "error";
1647
- }
1648
- return "worldid";
1649
- }
1650
- function IDKitSessionWidget({
1651
- open,
1652
- onOpenChange,
1653
- onSuccess,
1654
- onError,
1655
- autoClose = true,
1656
- language,
1657
- ...config
1658
- }) {
1659
- const flow = useIDKitSession(config);
1660
- const { open: openFlow, reset: resetFlow } = flow;
1661
- const lastResultRef = useRef(null);
1662
- const lastErrorCodeRef = useRef(null);
1663
- useEffect(() => {
1664
- if (language) {
1665
- setLocalizationConfig({ language });
1666
- }
1667
- }, [language]);
1668
- useEffect(() => {
1669
- if (open) {
1670
- openFlow();
1671
- return;
1672
- }
1673
- resetFlow();
1674
- }, [open, openFlow, resetFlow]);
1675
- useEffect(() => {
1676
- if (!flow.result || flow.result === lastResultRef.current) {
1677
- return;
1678
- }
1679
- lastResultRef.current = flow.result;
1680
- void Promise.resolve(onSuccess?.(flow.result)).catch(() => {
1681
- });
1682
- }, [onSuccess, flow.result]);
1683
- useEffect(() => {
1684
- if (!flow.errorCode || flow.errorCode === lastErrorCodeRef.current) {
1685
- return;
1686
- }
1687
- lastErrorCodeRef.current = flow.errorCode;
1688
- void Promise.resolve(onError?.(flow.errorCode)).catch(() => {
1689
- });
1690
- }, [flow.errorCode, onError]);
1691
- useEffect(() => {
1692
- if (flow.isSuccess && autoClose) {
1693
- const timer = setTimeout(() => onOpenChange(false), 2500);
1694
- return () => clearTimeout(timer);
1695
- }
1696
- }, [flow.isSuccess, autoClose, onOpenChange]);
1697
- const stage = getVisualStage2(flow.isSuccess, flow.isError);
1698
- return /* @__PURE__ */ jsxs(IDKitModal, { open, onOpenChange, children: [
1699
- stage === "worldid" && /* @__PURE__ */ jsx(
1700
- WorldIDState,
1701
- {
1702
- connectorURI: flow.connectorURI,
1703
- isAwaitingUserConfirmation: flow.isAwaitingUserConfirmation
1635
+ isAwaitingUserConfirmation: flow.isAwaitingUserConfirmation,
1636
+ showSimulatorCallout
1704
1637
  }
1705
1638
  ),
1706
1639
  stage === "success" && /* @__PURE__ */ jsx(SuccessState, {}),
@@ -1717,6 +1650,6 @@ function IDKitSessionWidget({
1717
1650
  ] });
1718
1651
  }
1719
1652
 
1720
- export { IDKitRequestWidget, IDKitSessionWidget, useIDKitRequest, useIDKitSession };
1653
+ export { IDKitRequestWidget, useIDKitRequest };
1721
1654
  //# sourceMappingURL=index.js.map
1722
1655
  //# sourceMappingURL=index.js.map