@truzyx/consent-widget 0.2.0 → 0.2.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 +19 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @truzyx/consent-widget
|
|
2
2
|
|
|
3
|
-
Framework-agnostic consent + preferences widget for third-party sites. Opens the Truzyx consent gateway (consent
|
|
3
|
+
Framework-agnostic consent + preferences widget for third-party sites. Opens the Truzyx consent gateway (consent, preferences, or direct-consent dialog) in a modal iframe overlay. Zero runtime dependencies for the vanilla entry; the React entry needs only `react` (optional peer).
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -18,7 +18,8 @@ No bundler? Use the script-tag build served from your gateway host instead (glob
|
|
|
18
18
|
|
|
19
19
|
| Value | Where it comes from |
|
|
20
20
|
|-----------|---------------------|
|
|
21
|
-
| `baseUrl` | Your gateway origin
|
|
21
|
+
| `baseUrl` | Your gateway origin. Optional — precedence is: explicit `baseUrl` → `env` → `<script>` tag origin → current origin. |
|
|
22
|
+
| `env` | `"live"` (`https://ui.gateway.nodbook.in`) or `"sandbox"` (`https://sandbox-ui.gateway.nodbook.in`). Used only when `baseUrl` is omitted. |
|
|
22
23
|
| `token` | Principal JWT for the end user, issued by your backend. Sent to the gateway as `?auth_token=` and via `postMessage`. |
|
|
23
24
|
| `requestId` | Consent request id created via the gateway API. Required for the consent dialog only. |
|
|
24
25
|
|
|
@@ -39,6 +40,11 @@ ConsentWidget.openPreferences("<principal-jwt>", {
|
|
|
39
40
|
baseUrl: "https://consent.truzyx.com",
|
|
40
41
|
});
|
|
41
42
|
|
|
43
|
+
// Or direct-consent dialog for purpose(s)
|
|
44
|
+
ConsentWidget.openDirectConsent("purpose_123", "<principal-jwt>", {
|
|
45
|
+
env: "sandbox", // or live; ignored when baseUrl is set
|
|
46
|
+
});
|
|
47
|
+
|
|
42
48
|
// React to flow completion
|
|
43
49
|
const off = ConsentWidget.onCallback((event) => {
|
|
44
50
|
console.log(event.type, event);
|
|
@@ -89,7 +95,9 @@ The hook subscribes/unsubscribes the callback automatically and closes the dialo
|
|
|
89
95
|
|
|
90
96
|
## API reference
|
|
91
97
|
|
|
92
|
-
### Methods
|
|
98
|
+
### Methods
|
|
99
|
+
|
|
100
|
+
Vanilla singleton methods and hook return value are the same, except the hook additionally exposes `open(options)` (routes to consent when `requestId` is set, else preferences) and names the subscribe function `onEvent` instead of `onCallback`.
|
|
93
101
|
|
|
94
102
|
| Method | Signature | Description |
|
|
95
103
|
|--------|-----------|-------------|
|
|
@@ -107,7 +115,7 @@ The hook subscribes/unsubscribes the callback automatically and closes the dialo
|
|
|
107
115
|
|-------|------|---------|-------------|
|
|
108
116
|
| `token` | `string` | — (required) | Principal JWT. |
|
|
109
117
|
| `requestId` | `string` | — | Consent request id. Required for `mode: "consent"`. |
|
|
110
|
-
| `mode` | `"consent" \| "preferences"` | `"consent"` if `requestId` is set, else `"preferences"` | Which dialog to open. |
|
|
118
|
+
| `mode` | `"consent" \| "preferences" \| "direct_consent"` | `"consent"` if `requestId` is set, else `"preferences"` | Which dialog to open. Set implicitly by `openConsent` / `openPreferences` / `openDirectConsent`. |
|
|
111
119
|
| `baseUrl` | `string` | script-tag origin, else current origin | Gateway origin. Optional — when provided it wins and `env` is ignored. |
|
|
112
120
|
| `env` | `"live" \| "sandbox"` | — (no default) | Picks the gateway host when `baseUrl` is omitted: live → `https://ui.gateway.nodbook.in`, sandbox → `https://sandbox-ui.gateway.nodbook.in`. |
|
|
113
121
|
| `autoClose` | `boolean` | `true` | Auto-close on terminal events (`consent_accepted`, `consent_declined`, `already_resolved`, `redirecting`). |
|
|
@@ -118,17 +126,17 @@ The hook subscribes/unsubscribes the callback automatically and closes the dialo
|
|
|
118
126
|
|
|
119
127
|
| `type` | Extra fields | Meaning |
|
|
120
128
|
|--------|--------------|---------|
|
|
121
|
-
| `opened` | `requestId?` | Dialog opened. |
|
|
122
|
-
| `consent_accepted` | `requestId?` | User accepted (all or selected purposes). |
|
|
123
|
-
| `consent_declined` | `requestId?` | User declined/cancelled. |
|
|
129
|
+
| `opened` | `requestId?`, `data?` | Dialog opened (`data.purposeIds` for direct consent). |
|
|
130
|
+
| `consent_accepted` | `requestId?`, `data?` | User accepted (all or selected purposes). Direct consent includes `data.purposeIds`. |
|
|
131
|
+
| `consent_declined` | `requestId?`, `data?` | User declined/cancelled. Direct consent includes `data.purposeIds`. |
|
|
124
132
|
| `already_resolved` | `requestId?` | Request was already approved/declined. |
|
|
125
|
-
| `redirecting` | `requestId?`, `redirectUrl` | Gateway is redirecting (e.g. back to your site). |
|
|
126
|
-
| `error` | `requestId?`, `message?` | Load/submit failure. |
|
|
133
|
+
| `redirecting` | `requestId?`, `redirectUrl`, `data?` | Gateway is redirecting (e.g. back to your site). |
|
|
134
|
+
| `error` | `requestId?`, `message?`, `data?` | Load/submit failure. |
|
|
127
135
|
| `closed` | `requestId?` | Dialog closed (×, ESC, backdrop, or `close()`). |
|
|
128
136
|
|
|
129
137
|
## How it works
|
|
130
138
|
|
|
131
|
-
- The widget renders a modal overlay with an `<iframe>` pointing at `{baseUrl}/consent_manager/consent/{requestId}` or `{baseUrl}/consent_manager/
|
|
139
|
+
- The widget renders a modal overlay with an `<iframe>` pointing at `{baseUrl}/consent_manager/consent/{requestId}`, `{baseUrl}/consent_manager/preferences`, or `{baseUrl}/consent_manager/direct_consent`, with `?auth_token=<token>&embed=true&origin=<your-origin>` (plus `?purpose_id=`, `?org_id=`, `?locale=` for direct consent).
|
|
132
140
|
- The token is also delivered via `postMessage` (`PRINCIPAL_TOKEN`) when the iframe signals readiness.
|
|
133
141
|
- Flow completion is reported back as `CONSENT_WIDGET_EVENT` messages, validated against the gateway origin, and fanned out to your callbacks. In embed mode the gateway pages render chromeless (no extra card/background) so only the widget's single card is visible.
|
|
134
142
|
- Because the dialog is an iframe, there is no CSS leakage in either direction.
|
|
@@ -144,4 +152,4 @@ The gateway repo ships a dev harness at `/consent_manager/check` (query params `
|
|
|
144
152
|
| `.` | `dist/index.js` (ESM), `dist/index.cjs` (CJS), `dist/index.d.ts` | Any framework / plain JS. |
|
|
145
153
|
| `./react` | `dist/react.js`, `dist/react.cjs`, `dist/react.d.ts` | `useConsentWidget` hook (`react` stays external). |
|
|
146
154
|
|
|
147
|
-
Source of truth is `src/core/` (`widget.ts`, `types.ts`). Version: `0.
|
|
155
|
+
Source of truth is `src/core/` (`widget.ts`, `types.ts`). Version: `0.2.0`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@truzyx/consent-widget",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Framework-agnostic consent + preferences widget (iframe overlay) with React hook. Reuses the gateway embed core, zero runtime dependencies for the vanilla entry.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|