@esigncomply/react 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +123 -2
- package/dist/index.d.ts +45 -0
- package/dist/index.js +5 -0
- package/package.json +43 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Esign Comply
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,124 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @esigncomply/react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
React hooks for the Esign Comply browser SDK. Hooks only, no visual components: you build the notice, the links, the checkbox and the button, and the hooks connect them to the ceremony.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @esigncomply/react @esigncomply/browser
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Peer dependencies: `react` 18 or later and `@esigncomply/browser`. The built file starts with `"use client"`.
|
|
10
|
+
|
|
11
|
+
## Hooks
|
|
12
|
+
|
|
13
|
+
### `useCeremony({ clientToken, apiUrl? })`
|
|
14
|
+
|
|
15
|
+
Attaches to the session in an effect, on the client, and follows it.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
const { ceremony, status, remainingSteps, findings, error, canComplete } = useCeremony({ clientToken, apiUrl });
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
| Field | Meaning |
|
|
22
|
+
|---|---|
|
|
23
|
+
| `ceremony` | The attached ceremony from `@esigncomply/browser`, or `null` until `status` is `ready`. |
|
|
24
|
+
| `status` | `idle` (no token yet), `attaching`, `ready`, `error`, `completed`. |
|
|
25
|
+
| `remainingSteps` | Steps still outstanding. It follows the page: unticking the box puts `intent.captured` back. |
|
|
26
|
+
| `findings` | Conformance findings that did not pass, the latest for each step. Each has `rule`, `status`, `message`, `fix`, `doc_url`. |
|
|
27
|
+
| `error` | The last `EsignComplyError`, with `code`, `rule` and `fix`. |
|
|
28
|
+
| `canComplete` | `true` when only the signing act is left. Use it to enable the button. |
|
|
29
|
+
|
|
30
|
+
The session is attached once per token. React strict mode runs effects twice in development; the hook still attaches once. The ceremony is destroyed when the last component that uses the token unmounts.
|
|
31
|
+
|
|
32
|
+
### `useDocument(ceremony, { versionId, mode })`
|
|
33
|
+
|
|
34
|
+
Presents one document version of the session.
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
const tos = useDocument<HTMLAnchorElement>(ceremony, { versionId, mode: "hyperlink" });
|
|
38
|
+
// tos.ref goes on the link (hyperlink) or on the element that holds the document text (inline, scrollbox)
|
|
39
|
+
// tos.presented is true once the API recorded the presentation; tos.error holds a failure
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Signup form
|
|
43
|
+
|
|
44
|
+
The server action creates the session with the secret key and returns `clientToken`, `apiUrl` and the pinned version IDs. The form does the rest.
|
|
45
|
+
|
|
46
|
+
```tsx
|
|
47
|
+
"use client";
|
|
48
|
+
import { useEffect, useRef, useState } from "react";
|
|
49
|
+
import { useCeremony, useDocument } from "@esigncomply/react";
|
|
50
|
+
|
|
51
|
+
export function SignupForm({ clientToken, apiUrl, tosVersionId, privacyVersionId }: Props) {
|
|
52
|
+
const { ceremony, status, findings, canComplete } = useCeremony({ clientToken, apiUrl });
|
|
53
|
+
const tos = useDocument<HTMLAnchorElement>(ceremony, { versionId: tosVersionId, mode: "hyperlink" });
|
|
54
|
+
const privacy = useDocument<HTMLAnchorElement>(ceremony, { versionId: privacyVersionId, mode: "hyperlink" });
|
|
55
|
+
|
|
56
|
+
const assentRef = useRef<HTMLDivElement>(null);
|
|
57
|
+
const checkboxRef = useRef<HTMLInputElement>(null);
|
|
58
|
+
const submitRef = useRef<HTMLButtonElement>(null);
|
|
59
|
+
const [message, setMessage] = useState("");
|
|
60
|
+
|
|
61
|
+
// Observe the assent controls once both documents are presented.
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (!ceremony || !tos.presented || !privacy.presented) return;
|
|
64
|
+
ceremony.observeAssent({
|
|
65
|
+
region: assentRef.current, // notice, links, checkbox, button
|
|
66
|
+
checkbox: checkboxRef.current,
|
|
67
|
+
submit: submitRef.current,
|
|
68
|
+
});
|
|
69
|
+
}, [ceremony, tos.presented, privacy.presented]);
|
|
70
|
+
|
|
71
|
+
// The signing act, from the signer's real click.
|
|
72
|
+
async function onSubmit(event: React.FormEvent<HTMLFormElement>) {
|
|
73
|
+
event.preventDefault();
|
|
74
|
+
if (!ceremony) return;
|
|
75
|
+
try {
|
|
76
|
+
const result = await ceremony.complete(); // { recordId, receipt, verifyUrl, status }
|
|
77
|
+
await finishSignup(new FormData(event.currentTarget), result.recordId); // server action: confirms the record, then creates the account
|
|
78
|
+
} catch (err) {
|
|
79
|
+
setMessage(err instanceof Error ? err.message : "We could not record your acceptance."); // not signed: do not create the account
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<form onSubmit={onSubmit}>
|
|
85
|
+
<input name="email" type="email" required />
|
|
86
|
+
|
|
87
|
+
<div ref={assentRef}>
|
|
88
|
+
<p>
|
|
89
|
+
By checking the box and clicking Create account, you agree to the{" "}
|
|
90
|
+
<a ref={tos.ref} href="/legal/terms">Terms of Service</a> and acknowledge the{" "}
|
|
91
|
+
<a ref={privacy.ref} href="/legal/privacy">Privacy Notice</a>.
|
|
92
|
+
</p>
|
|
93
|
+
<label>
|
|
94
|
+
<input ref={checkboxRef} type="checkbox" /> I agree to the Terms of Service and Privacy Notice
|
|
95
|
+
</label>
|
|
96
|
+
<button ref={submitRef} type="submit" disabled={!canComplete}>
|
|
97
|
+
Create account
|
|
98
|
+
</button>
|
|
99
|
+
</div>
|
|
100
|
+
|
|
101
|
+
{status === "error" && <p role="alert">We could not start the signing step. Reload the page to try again.</p>}
|
|
102
|
+
{message && <p role="alert">{message}</p>}
|
|
103
|
+
{process.env.NODE_ENV !== "production" && findings.map((f) => <p key={f.rule + f.event_type}>{f.rule}: {f.message} {f.fix}</p>)}
|
|
104
|
+
</form>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Points that matter:
|
|
110
|
+
|
|
111
|
+
- Render the checkbox **unchecked** and leave it uncontrolled, or control it with state that starts `false`. A pre-checked box is reported as pre-checked (rule CR-01).
|
|
112
|
+
- Keep the notice, the links, the checkbox and one primary button inside the element you pass as `region`.
|
|
113
|
+
- Give document links a colour that differs from the surrounding text by at least 3 to 1, and keep them underlined (rule CR-05). The browser's default blue on black text measures 2.23 to 1.
|
|
114
|
+
- Start the ceremony when the form mounts, not on submit.
|
|
115
|
+
- A resolved `complete()` is not proof. Your server confirms the record with `GET /v1/records/{id}` before it creates the account.
|
|
116
|
+
|
|
117
|
+
Everything else is on the ceremony itself: `ceremony.verify.start(...)`, `ceremony.reviewPresented(...)`, `ceremony.cancel()` and the rest are described in the `@esigncomply/browser` README.
|
|
118
|
+
|
|
119
|
+
## Development
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
node packages/react/build.mjs # dist/index.js and dist/index.d.ts (builds the browser SDK first if needed)
|
|
123
|
+
node packages/react/test/e2e/run.mjs # the form above inside <StrictMode>, in Chrome, against a local API
|
|
124
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { EsignComplyError } from "@esigncomply/browser";
|
|
2
|
+
import type { Ceremony, Finding, PresentationMode } from "@esigncomply/browser";
|
|
3
|
+
export type { Ceremony, CompleteResult, Finding, PresentationMode, StepResult } from "@esigncomply/browser";
|
|
4
|
+
export { EsignComplyError } from "@esigncomply/browser";
|
|
5
|
+
export type CeremonyStatus = "idle" | "attaching" | "ready" | "error" | "completed";
|
|
6
|
+
export interface UseCeremonyOptions {
|
|
7
|
+
/** The session client token from your server. While it is empty the hook stays `idle`. */
|
|
8
|
+
clientToken: string | null | undefined;
|
|
9
|
+
/** The `api_url` of the session your server created. */
|
|
10
|
+
apiUrl?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface UseCeremonyResult {
|
|
13
|
+
/** The attached ceremony, or `null` until it is ready. */
|
|
14
|
+
ceremony: Ceremony | null;
|
|
15
|
+
status: CeremonyStatus;
|
|
16
|
+
/** Steps still outstanding. */
|
|
17
|
+
remainingSteps: string[];
|
|
18
|
+
/** Conformance findings that did not pass, the latest for each step. */
|
|
19
|
+
findings: Finding[];
|
|
20
|
+
error: EsignComplyError | null;
|
|
21
|
+
/** True when only the signing act is left: enable the action control. */
|
|
22
|
+
canComplete: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Attaches to a session on the client and follows it.
|
|
26
|
+
*
|
|
27
|
+
* The attach runs in an effect, once per token, and is cleaned up on unmount. Under React strict
|
|
28
|
+
* mode the effect runs twice; the session is still attached once.
|
|
29
|
+
*/
|
|
30
|
+
export declare function useCeremony({ clientToken, apiUrl }: UseCeremonyOptions): UseCeremonyResult;
|
|
31
|
+
export interface UseDocumentOptions {
|
|
32
|
+
/** A document version pinned on the session. */
|
|
33
|
+
versionId: string | null | undefined;
|
|
34
|
+
/** `hyperlink`: put `ref` on the link. `inline` or `scrollbox`: put `ref` on the element that holds the document text. */
|
|
35
|
+
mode: PresentationMode;
|
|
36
|
+
}
|
|
37
|
+
export interface UseDocumentResult<T extends Element> {
|
|
38
|
+
/** Goes on the link or on the container. */
|
|
39
|
+
ref: (element: T | null) => void;
|
|
40
|
+
/** True once `document.presented` is recorded for this version. */
|
|
41
|
+
presented: boolean;
|
|
42
|
+
error: EsignComplyError | null;
|
|
43
|
+
}
|
|
44
|
+
/** Presents one document version of the session once the ceremony and the element exist. */
|
|
45
|
+
export declare function useDocument<T extends Element = HTMLElement>(ceremony: Ceremony | null | undefined, { versionId, mode }: UseDocumentOptions): UseDocumentResult<T>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
/*! @esigncomply/react 1.0.0 */
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
import{useCallback as T,useEffect as x,useMemo as D,useState as E}from"react";import{EsignComply as _,EsignComplyError as h}from"@esigncomply/browser";import{EsignComplyError as O}from"@esigncomply/browser";var d=new Map;function b(e,s,t){let o=d.get(e);if(!o){let u={promise:_.attach({clientToken:s,apiUrl:t}),users:0};o=u,d.set(e,u),u.promise.catch(()=>{d.get(e)===u&&d.delete(e)})}return clearTimeout(o.timer),o.users++,o}function w(e,s){s.users--,!(s.users>0)&&(s.timer=setTimeout(()=>{s.users>0||(d.get(e)===s&&d.delete(e),s.promise.then(t=>t.destroy(),()=>{}))},0))}var R=e=>e instanceof h?e:new h({code:"internal_error",type:"api_error",message:e instanceof Error?e.message:String(e)}),C=[],S=[];function v({clientToken:e,apiUrl:s}){let t=e?`${e}
|
|
5
|
+
${s??""}`:null,[o,u]=E(null);return x(()=>{if(!t||!e)return;let n=!0,m=[],p=b(t,e,s);return p.promise.then(r=>{if(!n)return;let l=new Map,f=(i,a)=>`${i??""}:${a??""}`,c=(i={})=>u(a=>{let y=a&&a.key===t?a:{key:t,ceremony:r,status:"ready",remainingSteps:C,findings:S,error:null},g=r.session.status==="completed"?"completed":i.status??y.status;return{...y,...i,ceremony:r,status:g,remainingSteps:r.remainingSteps(),findings:Array.from(l.values()).flat()}});m.push(r.on("change",()=>c()),r.on("finding",i=>{let a=f(i.event_type,i.version_id),y=g=>`${g.rule}:${String(g.measurement?.slot??"")}`;l.set(a,[...(l.get(a)??[]).filter(g=>y(g)!==y(i)),i]),c()}),r.on("stepRecorded",i=>{l.set(f(i.type,i.versionId),i.findings.filter(a=>a.status!=="pass")),c()}),r.on("error",i=>c({error:i})),r.on("expired",()=>c({status:"error",error:new h({code:"client_token_expired",type:"authentication_error",message:"This session has expired.",fix:"Create a new session on your server and pass its client token."})}))),c({status:"ready",error:null})},r=>{n&&u({key:t,ceremony:null,status:"error",remainingSteps:C,findings:S,error:R(r)})}),()=>{n=!1,m.forEach(r=>r()),w(t,p)}},[t,e,s]),D(()=>{let n=o&&o.key===t?o:null,m=n?n.status:t?"attaching":"idle",p=n?n.remainingSteps:C;return{ceremony:n?n.ceremony:null,status:m,remainingSteps:p,findings:n?n.findings:S,error:n?n.error:null,canComplete:m==="ready"&&p.length>0&&p.every(r=>r==="signature.applied")}},[o,t])}function A(e,{versionId:s,mode:t}){let[o,u]=E(null),[n,m]=E(null),p=T(l=>u(l),[]);x(()=>{if(!e||!o||!s)return;let l=!0,f={ceremony:e,element:o,versionId:s,mode:t};return e.presentDocument(t==="hyperlink"?{versionId:s,mode:t,link:o}:{versionId:s,mode:t,container:o}).then(()=>{l&&m({...f,presented:!0,error:null})},c=>{l&&m({...f,presented:!1,error:R(c)})}),()=>{l=!1}},[e,o,s,t]);let r=n&&n.ceremony===e&&n.element===o&&n.versionId===s&&n.mode===t?n:null;return{ref:p,presented:r?r.presented:!1,error:r?r.error:null}}export{O as EsignComplyError,v as useCeremony,A as useDocument};
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@esigncomply/react",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "React hooks for the Esign Comply browser SDK. Hooks only: you build every element the signer sees.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./package.json": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@esigncomply/browser": "^1.0.0",
|
|
25
|
+
"react": ">=18"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@esigncomply/browser": "^1.0.0"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"homepage": "https://esigncomply.com/docs",
|
|
35
|
+
"keywords": [
|
|
36
|
+
"esign",
|
|
37
|
+
"e-signature",
|
|
38
|
+
"clickwrap",
|
|
39
|
+
"esigncomply"
|
|
40
|
+
],
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "node build.mjs",
|
|
43
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
44
|
+
"test:e2e": "node test/e2e/run.mjs"
|
|
45
|
+
}
|
|
6
46
|
}
|