@worldcoin/idkit 4.0.0-dev.fe98789 → 4.0.1-dev.a1a85c4

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 } from '@worldcoin/idkit-core';
2
+ export { IDKit, IDKitErrorCodes, documentLegacy, orbLegacy, secureDocumentLegacy, 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';
@@ -108,8 +108,6 @@ function useIDKitFlow(createFlowHandle, config) {
108
108
  };
109
109
  void (async () => {
110
110
  try {
111
- await IDKit.init();
112
- ensureNotAborted(controller.signal);
113
111
  const request = await createFlowHandleRef.current();
114
112
  ensureNotAborted(controller.signal);
115
113
  setState((prev) => {
@@ -199,36 +197,6 @@ function useIDKitRequest(config) {
199
197
  config
200
198
  );
201
199
  }
202
- function assertSessionId(sessionId) {
203
- if (sessionId === void 0) {
204
- return void 0;
205
- }
206
- if (sessionId.trim().length === 0) {
207
- throw IDKitErrorCodes.MalformedRequest;
208
- }
209
- return sessionId;
210
- }
211
- function useIDKitSession(config) {
212
- return useIDKitFlow(() => {
213
- const existingSessionId = assertSessionId(config.existing_session_id);
214
- const builder = existingSessionId ? IDKit.proveSession(existingSessionId, {
215
- app_id: config.app_id,
216
- rp_context: config.rp_context,
217
- action_description: config.action_description,
218
- bridge_url: config.bridge_url,
219
- override_connect_base_url: config.override_connect_base_url,
220
- environment: config.environment
221
- }) : IDKit.createSession({
222
- app_id: config.app_id,
223
- rp_context: config.rp_context,
224
- action_description: config.action_description,
225
- bridge_url: config.bridge_url,
226
- override_connect_base_url: config.override_connect_base_url,
227
- environment: config.environment
228
- });
229
- return builder.preset(config.preset);
230
- }, config);
231
- }
232
200
 
233
201
  // src/styles/widgetStyles.ts
234
202
  var WIDGET_STYLES = `
@@ -525,6 +493,22 @@ var WIDGET_STYLES = `
525
493
  color: var(--idkit-text-secondary);
526
494
  }
527
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
+
528
512
  /* Mobile deep-link button */
529
513
  .idkit-deeplink-btn {
530
514
  display: flex;
@@ -1183,7 +1167,10 @@ function QRPlaceholderIcon(props) {
1183
1167
  }
1184
1168
  );
1185
1169
  }
1186
- function QRState({ qrData }) {
1170
+ function QRState({
1171
+ qrData,
1172
+ showSimulatorCallout
1173
+ }) {
1187
1174
  const media = useMedia();
1188
1175
  const [copiedLink, setCopiedLink] = useState(false);
1189
1176
  const copyLink = useCallback(() => {
@@ -1222,13 +1209,27 @@ function QRState({ qrData }) {
1222
1209
  style: { cursor: "pointer" },
1223
1210
  children: /* @__PURE__ */ jsx(QRCode, { data: qrData, size: media === "mobile" ? 160 : 200 })
1224
1211
  }
1225
- ) : /* @__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
+ ] })
1226
1226
  ] })
1227
1227
  ] });
1228
1228
  }
1229
1229
  function WorldIDState({
1230
1230
  connectorURI,
1231
- isAwaitingUserConfirmation
1231
+ isAwaitingUserConfirmation,
1232
+ showSimulatorCallout
1232
1233
  }) {
1233
1234
  const media = useMedia();
1234
1235
  return /* @__PURE__ */ jsxs(
@@ -1258,7 +1259,13 @@ function WorldIDState({
1258
1259
  "div",
1259
1260
  {
1260
1261
  className: `idkit-qr-blur ${isAwaitingUserConfirmation ? "blurred" : ""}`,
1261
- 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
+ ) })
1262
1269
  }
1263
1270
  )
1264
1271
  ] })
@@ -1619,90 +1626,14 @@ function IDKitRequestWidget({
1619
1626
  }
1620
1627
  }, [flow.isSuccess, autoClose, onOpenChange]);
1621
1628
  const stage = getVisualStage(flow.isSuccess, flow.isError);
1629
+ const showSimulatorCallout = config.environment === "staging";
1622
1630
  return /* @__PURE__ */ jsxs(IDKitModal, { open, onOpenChange, children: [
1623
1631
  stage === "worldid" && /* @__PURE__ */ jsx(
1624
1632
  WorldIDState,
1625
1633
  {
1626
1634
  connectorURI: flow.connectorURI,
1627
- isAwaitingUserConfirmation: flow.isAwaitingUserConfirmation
1628
- }
1629
- ),
1630
- stage === "success" && /* @__PURE__ */ jsx(SuccessState, {}),
1631
- stage === "error" && /* @__PURE__ */ jsx(
1632
- ErrorState,
1633
- {
1634
- errorCode: flow.errorCode,
1635
- onRetry: () => {
1636
- resetFlow();
1637
- openFlow();
1638
- }
1639
- }
1640
- )
1641
- ] });
1642
- }
1643
- function getVisualStage2(isSuccess, isError) {
1644
- if (isSuccess) {
1645
- return "success";
1646
- }
1647
- if (isError) {
1648
- return "error";
1649
- }
1650
- return "worldid";
1651
- }
1652
- function IDKitSessionWidget({
1653
- open,
1654
- onOpenChange,
1655
- onSuccess,
1656
- onError,
1657
- autoClose = true,
1658
- language,
1659
- ...config
1660
- }) {
1661
- const flow = useIDKitSession(config);
1662
- const { open: openFlow, reset: resetFlow } = flow;
1663
- const lastResultRef = useRef(null);
1664
- const lastErrorCodeRef = useRef(null);
1665
- useEffect(() => {
1666
- if (language) {
1667
- setLocalizationConfig({ language });
1668
- }
1669
- }, [language]);
1670
- useEffect(() => {
1671
- if (open) {
1672
- openFlow();
1673
- return;
1674
- }
1675
- resetFlow();
1676
- }, [open, openFlow, resetFlow]);
1677
- useEffect(() => {
1678
- if (!flow.result || flow.result === lastResultRef.current) {
1679
- return;
1680
- }
1681
- lastResultRef.current = flow.result;
1682
- void Promise.resolve(onSuccess?.(flow.result)).catch(() => {
1683
- });
1684
- }, [onSuccess, flow.result]);
1685
- useEffect(() => {
1686
- if (!flow.errorCode || flow.errorCode === lastErrorCodeRef.current) {
1687
- return;
1688
- }
1689
- lastErrorCodeRef.current = flow.errorCode;
1690
- void Promise.resolve(onError?.(flow.errorCode)).catch(() => {
1691
- });
1692
- }, [flow.errorCode, onError]);
1693
- useEffect(() => {
1694
- if (flow.isSuccess && autoClose) {
1695
- const timer = setTimeout(() => onOpenChange(false), 2500);
1696
- return () => clearTimeout(timer);
1697
- }
1698
- }, [flow.isSuccess, autoClose, onOpenChange]);
1699
- const stage = getVisualStage2(flow.isSuccess, flow.isError);
1700
- return /* @__PURE__ */ jsxs(IDKitModal, { open, onOpenChange, children: [
1701
- stage === "worldid" && /* @__PURE__ */ jsx(
1702
- WorldIDState,
1703
- {
1704
- connectorURI: flow.connectorURI,
1705
- isAwaitingUserConfirmation: flow.isAwaitingUserConfirmation
1635
+ isAwaitingUserConfirmation: flow.isAwaitingUserConfirmation,
1636
+ showSimulatorCallout
1706
1637
  }
1707
1638
  ),
1708
1639
  stage === "success" && /* @__PURE__ */ jsx(SuccessState, {}),
@@ -1719,6 +1650,6 @@ function IDKitSessionWidget({
1719
1650
  ] });
1720
1651
  }
1721
1652
 
1722
- export { IDKitRequestWidget, IDKitSessionWidget, useIDKitRequest, useIDKitSession };
1653
+ export { IDKitRequestWidget, useIDKitRequest };
1723
1654
  //# sourceMappingURL=index.js.map
1724
1655
  //# sourceMappingURL=index.js.map