@deliverd/sdk 0.34.0 → 0.36.0

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/react.js ADDED
@@ -0,0 +1,73 @@
1
+ "use client";
2
+ /**
3
+ * `<DeliverdDecision>`: a decision session in a React page.
4
+ *
5
+ * A thin wrapper over Deliverd Elements (`@deliverd/sdk/elements`): it loads
6
+ * the script once, mounts the frame into a `<div>` it renders, passes your
7
+ * handlers through, and unmounts the frame when the component goes away or
8
+ * the secret changes. The frame is still served from Deliverd's origin, so
9
+ * your page cannot read it or press its buttons, and the approver still
10
+ * proves who they are before deciding.
11
+ *
12
+ * ```tsx
13
+ * import { DeliverdDecision } from "@deliverd/sdk/react";
14
+ *
15
+ * <DeliverdDecision
16
+ * clientSecret={clientSecret} // from your server
17
+ * onDecided={(event) => confirmOnServer(event.sessionId)}
18
+ * />
19
+ *
20
+ * // No account yet? See it with sample data, nothing recorded:
21
+ * <DeliverdDecision demo onDecided={(event) => console.log(event)} />
22
+ * ```
23
+ *
24
+ * React 18 or later. Written without JSX so the package needs no build step
25
+ * of its own for it; `react` is an optional peer dependency, needed only if
26
+ * you import this entry.
27
+ */
28
+ import { createElement, useEffect, useRef } from "react";
29
+ import { loadElements, mountWhenLoaded, } from "./elements.js";
30
+ export function DeliverdDecision(props) {
31
+ const host = useRef(null);
32
+ // Handlers read through a ref, so a new arrow function on every render does not remount the frame.
33
+ const latest = useRef(props);
34
+ latest.current = props;
35
+ const { clientSecret, demo, title, minHeight, autoResize, origin } = props;
36
+ useEffect(() => {
37
+ const el = host.current;
38
+ if (!el)
39
+ return;
40
+ let cancelled = false;
41
+ let mounted = null;
42
+ const relay = (name) => (event) => latest.current[name]?.(event);
43
+ mountWhenLoaded(el, {
44
+ clientSecret,
45
+ demo,
46
+ title,
47
+ minHeight,
48
+ autoResize,
49
+ onReady: relay("onReady"),
50
+ onVerified: relay("onVerified"),
51
+ onDecided: relay("onDecided"),
52
+ onExpired: relay("onExpired"),
53
+ }, () => loadElements({ origin }), () => cancelled)
54
+ .then((result) => {
55
+ if (cancelled)
56
+ result?.unmount();
57
+ else
58
+ mounted = result;
59
+ })
60
+ .catch((err) => {
61
+ const error = err instanceof Error ? err : new Error(String(err));
62
+ if (latest.current.onError)
63
+ latest.current.onError(error);
64
+ else
65
+ console.error(error);
66
+ });
67
+ return () => {
68
+ cancelled = true;
69
+ mounted?.unmount();
70
+ };
71
+ }, [clientSecret, demo, title, minHeight, autoResize, origin]);
72
+ return createElement("div", { ref: host, className: props.className, style: props.style, id: props.id });
73
+ }
@@ -43,7 +43,7 @@
43
43
  * **Add the version here when you publish it, not before.** An entry is a
44
44
  * claim that `npm install @deliverd/sdk@x` works today.
45
45
  */
46
- export declare const PUBLISHED_TO_NPM: readonly ["0.1.0", "0.2.0", "0.3.0", "0.4.0", "0.5.0", "0.6.0", "0.6.1", "0.6.2", "0.7.0", "0.7.1", "0.8.0", "0.8.1", "0.8.2", "0.9.0", "0.10.0", "0.11.0", "0.11.1", "0.12.0", "0.13.0", "0.14.0", "0.15.0", "0.16.0", "0.17.0", "0.18.0", "0.19.0", "0.20.0", "0.21.0", "0.22.0", "0.23.0", "0.24.0", "0.24.1", "0.25.0", "0.25.1", "0.26.0", "0.27.0", "0.28.0", "0.29.0", "0.30.0", "0.31.0", "0.32.0", "0.33.0"];
46
+ export declare const PUBLISHED_TO_NPM: readonly ["0.1.0", "0.2.0", "0.3.0", "0.4.0", "0.5.0", "0.6.0", "0.6.1", "0.6.2", "0.7.0", "0.7.1", "0.8.0", "0.8.1", "0.8.2", "0.9.0", "0.10.0", "0.11.0", "0.11.1", "0.12.0", "0.13.0", "0.14.0", "0.15.0", "0.16.0", "0.17.0", "0.18.0", "0.19.0", "0.20.0", "0.21.0", "0.22.0", "0.23.0", "0.24.0", "0.24.1", "0.25.0", "0.25.1", "0.26.0", "0.27.0", "0.28.0", "0.29.0", "0.30.0", "0.31.0", "0.32.0", "0.33.0", "0.34.0", "0.35.0"];
47
47
  /**
48
48
  * A fingerprint of what each *published* version recorded.
49
49
  *
@@ -1 +1 @@
1
- {"version":3,"file":"released.d.ts","sourceRoot":"","sources":["../src/released.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,gBAAgB,uZA0CnB,CAAC;AAEX;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAiHzC,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAmi+BtD,CAAC"}
1
+ {"version":3,"file":"released.d.ts","sourceRoot":"","sources":["../src/released.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,gBAAgB,2aA4CnB,CAAC;AAEX;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAqHzC,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAm9jCtD,CAAC"}