@leadping/consent 0.0.0-stage → 1.0.1

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/README.md CHANGED
@@ -1,3 +1,149 @@
1
- # Temporary Holding Version
1
+ # Leadping Consent SDK
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Record consent on your website and receive a certificate ID. The consent service stores the evidence; the consent portal shows the certificate and replay. This SDK does not create leads or call the main Leadping API.
4
+
5
+ ## Add one script to your form
6
+
7
+ Register your website's allowed origins with the consent service, then replace `YOUR_PUBLIC_DOMAIN_ID` below. This identifier is public, not an API key.
8
+
9
+ ```html
10
+ <form id="lead-form">
11
+ <label>Email <input name="email" type="email" required></label>
12
+ <label><input type="checkbox" data-leadping-consent required>
13
+ <span data-leadping-disclosure>I agree to the terms displayed on this page.</span>
14
+ </label>
15
+ <button type="submit">Submit</button>
16
+ </form>
17
+ <script
18
+ src="https://cdn.jsdelivr.net/npm/@leadping/consent@0.1.0/dist/leadping-consent.min.js"
19
+ data-domain-id="YOUR_PUBLIC_DOMAIN_ID"
20
+ defer>
21
+ </script>
22
+ ```
23
+
24
+ Use your actual disclosure text. The script records that text; it does not supply or approve it. It captures the current page URL automatically, including its query string and fragment. The recorder captures the whole document with unmasked input values.
25
+
26
+ On submission the script finalizes recording, obtains a certificate, and displays its ID and link at `https://certificate.leadping.ai/{id}`. No customer backend or source API key is required. The script owns form submission; remove competing submission handlers.
27
+
28
+ Pin the URL to a published npm version. Use the classic script at `dist/leadping-consent.min.js`, not the ES module under `dist/browser`.
29
+
30
+ ## Options and events
31
+
32
+ | Attribute | Purpose |
33
+ | --- | --- |
34
+ | `data-domain-id` | Required public website registration ID. |
35
+ | `data-form` | Form selector; defaults to `#lead-form`. |
36
+ | `data-api-url` | Consent API origin; defaults to `https://consent.leadping.ai`. The SDK appends `/api`. |
37
+ | `data-portal-url` | Certificate portal origin; defaults to `https://certificate.leadping.ai`. Using the local API automatically selects the local portal. |
38
+
39
+ Recipient inputs use `firstName`, `lastName`, `email`, and `phone`. Supply at least email or phone. The checkbox must start unchecked and the disclosure must stay unchanged during capture. Only one recorder runs per document.
40
+
41
+ ```js
42
+ document.querySelector('#lead-form').addEventListener('leadping:success', event => {
43
+ const { certificateId, certificateUrl } = event.detail;
44
+ console.log(certificateId, certificateUrl);
45
+ });
46
+ ```
47
+
48
+ `leadping:ready` signals that recording has started; `leadping:error` reports a failure. `window.LeadpingConsent` exposes `ConsentCapture` and `attach(scriptElement)` for advanced use. Do not attach twice when `data-domain-id` already starts the embed automatically.
49
+
50
+ ## Consent service setup
51
+
52
+ Leadping operates the API and portal; you do not deploy a backend. Ask Leadping to register your domain ID and exact website origins. For Leadping operators, `CONSENT_DOMAINS_JSON` has this format:
53
+
54
+ ```json
55
+ [{ "id": "demo-domain", "origins": ["https://example.com", "https://www.example.com"] }]
56
+ ```
57
+
58
+ The browser uses `POST /api/consent/domains/{id}/sessions`, uploads recording batches, then calls `POST /api/consent/certificates` with the session capability. No main Leadping source credentials are used.
59
+
60
+ Certificate URLs are shareable access links: anyone with the ID can view the certificate and recording. Treat those links as sensitive when recordings contain personal information.
61
+
62
+ ## Reference
63
+
64
+ <details>
65
+ <summary><strong>API reference, recording behavior, and evidence replay</strong></summary>
66
+
67
+ ## API reference
68
+
69
+ ### `new ConsentCapture(options)`
70
+
71
+ Recording begins immediately when construction succeeds.
72
+
73
+ | Option | Type | Description |
74
+ | --- | --- | --- |
75
+ | `apiUrl` | `string` | HTTPS capture-service origin, without credentials, a query string, or a fragment. |
76
+ | `session` | `CaptureSession` | Session supplied by the Leadping integration. |
77
+ | `form` | `HTMLFormElement` | Form containing the disclosure and checkbox. |
78
+ | `disclosure` | `HTMLElement` | Element whose `textContent` exactly matches `session.form.disclosure`. |
79
+ | `checkbox` | `HTMLInputElement` | Consent checkbox; both `checked` and `defaultChecked` must initially be false. |
80
+ | `onError` | `(error: Error) => void` | Reports terminal recording failures. Handle constructor exceptions and rejected method promises separately. |
81
+
82
+ Only one recorder may be active per document. The session must be unexpired and have no more than one hour remaining when recording starts. Do not rewrite the disclosure while recording.
83
+
84
+ ### Methods
85
+
86
+ | Method | Returns | Behavior |
87
+ | --- | --- | --- |
88
+ | `finish(recipient)` | `Promise<CaptureReference>` | Stops recording, awaits pending uploads, submits the checkbox state and recipient, then returns `{ sessionId, uploadToken }`. |
89
+ | `flush()` | `Promise<void>` | Uploads pending recording data without stopping capture. |
90
+ | `dispose()` | `void` | Stops recording and timers, removes listeners, and aborts transport requests. Does not finalize or flush the recording. |
91
+
92
+ `Recipient` accepts optional `firstName`, `lastName`, `email`, and `phone` strings. Your form and backend determine which fields are required.
93
+
94
+ `finish()` uses the first call's recipient and returns the same promise on later calls. A failed finalization cannot be restarted on that instance. It records the checkbox's current state, including `false`; use your form's validation rules when acceptance is required.
95
+
96
+ ### Recording behavior
97
+
98
+ The recorder operates on the **whole document**, not just the supplied form. It preserves text and input values without masking, so page content and entered values can become part of the evidence. Canvas and cross-origin iframe recording are disabled.
99
+
100
+ Pending data is flushed every three seconds, on a page visibility change to hidden, and as batches grow. Await `finish()` before navigation; background flushing is not a guarantee that uploads will complete during page unload.
101
+
102
+ Uploads use bounded retries for transient failures. Buffer, backlog, and session limits cause capture to fail explicitly rather than silently discard events. The SDK does not persist an offline recording queue across reloads.
103
+
104
+ </details>
105
+
106
+ <details>
107
+ <summary><strong>Building and publishing the SDK</strong></summary>
108
+
109
+ ## Build and distribution
110
+
111
+ Use Node.js 24, matching CI:
112
+
113
+ ```sh
114
+ npm ci
115
+ npm run build
116
+ npm test
117
+ ```
118
+
119
+ `npm run benchmark` runs the buffer benchmark. Edit `src/`, then regenerate `dist/`; generated output is ignored by Git and included in the npm package so jsDelivr can serve it.
120
+
121
+ | Output | Purpose |
122
+ | --- | --- |
123
+ | `dist/browser/leadping-consent.min.js` | Bundled browser capture SDK. |
124
+ | `dist/browser/*.map` | Browser source maps. |
125
+ | `dist/browser/*.LEGAL.txt` | Dependency license notices. |
126
+ | `dist/*.js` and `dist/*.d.ts` | ESM modules and TypeScript declarations for package consumers. |
127
+
128
+ The build also emits `dist/browser/index.js` for the consent service's existing SDK paths. This is bundled and minified as well.
129
+
130
+ ### Publishing workflow
131
+
132
+ - Pull requests build and test the SDK and upload artifacts.
133
+ - Pushes to `main` build and test the SDK and upload artifacts without committing generated files.
134
+ - A `v*` tag matching `package.json` publishes the tested npm tarball as `@leadping/consent` using trusted publishing, then publishes a GitHub Release containing browser files, source maps, license notices, checksums, a browser archive, and the typed npm tarball. Prerelease versions use the npm `next` tag; stable versions use `latest`.
135
+
136
+ To make a versioned jsDelivr URL available, push a release tag and wait for npm publishing to succeed. The package version must match the tag, for example `0.1.0` and `v0.1.0`. npm must trust `leadpingai/leadping-consent-typescript` and the workflow filename `publish.yml`. jsDelivr serves the files from the published npm package; `dist/` does not need to exist in Git.
137
+
138
+ </details>
139
+
140
+ ## Troubleshooting
141
+
142
+ | Problem | Check |
143
+ | --- | --- |
144
+ | Form rejected during initialization | Exact origin and disclosure text, unchecked checkbox defaults, and both elements inside the form. |
145
+ | Invalid or expired session | Obtain a fresh session from Leadping; check the expiry and client clock. |
146
+ | Only one recorder may run | Dispose the previous instance before starting another. |
147
+ | Capture upload rejected or never acknowledged | Capture-service URL, session token/expiry, allowed origin, network connectivity, and service response. |
148
+ | jsDelivr returns 404 | The requested npm version has been published and contains the file under `dist/`. |
149
+ | CDN files are not updated after pushing | Only release tags publish npm versions. Check the `build` and `publish-npm` jobs, then update your URL to the new version. |