@redacto.io/consent-sdk-js 1.0.0 → 1.2.0-beta.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.
@@ -1,24 +1,40 @@
1
1
  /**
2
2
  * Optional sandbox options shared by the SDK's public option shapes and the
3
3
  * internal API params. When `token` is set the call sends the single
4
- * `X-Consent-Token` header instead of `Authorization: Bearer`, injects the
5
- * subject into each request's own payload, and takes org/workspace from these
6
- * fields instead of decoding the JWT.
4
+ * `X-Consent-Token` header instead of `Authorization: Bearer`, carries every
5
+ * supplied identifier in each request's own payload, and takes org/workspace
6
+ * from these fields instead of decoding the JWT.
7
7
  */
8
8
  type SandboxOptions = {
9
9
  token?: string;
10
- /** UCIC — the client's own user id (`org_user_id`); takes precedence over the subject. */
10
+ /** UCIC — the client's own user id (`org_user_id`); takes precedence for the principal. */
11
11
  sandboxUcic?: string;
12
+ /** Email — carried on every request like a live JWT's `user_data.primary_email`. */
13
+ sandboxEmail?: string;
14
+ /** Mobile — carried on every request like a live JWT's `user_data.primary_mobile`. */
15
+ sandboxMobile?: string;
16
+ /**
17
+ * @deprecated Use `sandboxEmail` / `sandboxMobile` (and/or `email` / `mobile`)
18
+ * instead. Still accepted for backward compatibility: a value containing "@"
19
+ * is treated as the email, otherwise the mobile.
20
+ */
12
21
  sandboxSubject?: string;
13
22
  organisationUuid?: string;
14
23
  workspaceUuid?: string;
15
24
  };
25
+ type SelectionControlType = "checkbox" | "radio" | "dropdown";
16
26
  type Settings = {
17
27
  button: {
28
+ /** Styles the "accept selected" button. */
18
29
  accept: {
19
30
  backgroundColor: string;
20
31
  textColor: string;
21
32
  };
33
+ /** Optional: the accept-all shortcut falls back to `accept` when unset. */
34
+ acceptAll?: {
35
+ backgroundColor: string;
36
+ textColor: string;
37
+ };
22
38
  decline: {
23
39
  backgroundColor: string;
24
40
  textColor: string;
@@ -37,6 +53,8 @@ type Settings = {
37
53
  textColor?: string;
38
54
  borderColor?: string;
39
55
  font?: string;
56
+ selectionControl?: SelectionControlType;
57
+ confirmBeforeSubmit?: boolean;
40
58
  };
41
59
 
42
60
  type ModalOptions = SandboxOptions & {
@@ -73,6 +91,8 @@ type ModalOptions = SandboxOptions & {
73
91
  digilockerCallbackUrl?: string;
74
92
  includeFullyConsentedData?: boolean;
75
93
  reviewModeButtonText?: string;
94
+ defaultOpenProducts?: string[];
95
+ otpGate?: OtpGateOptions;
76
96
  };
77
97
  type InlineOptions = {
78
98
  target: string | HTMLElement;
@@ -98,6 +118,68 @@ type DigiLockerCallbackOptions = {
98
118
  onSuccess?: (verificationReference: string) => void;
99
119
  onError?: (error: Error, errorCode?: string) => void;
100
120
  };
121
+ type OtpVerifyResult = {
122
+ ok: boolean;
123
+ message?: string;
124
+ };
125
+ type OtpGateOptions = {
126
+ required: boolean;
127
+ onVerify: (code: string) => Promise<OtpVerifyResult>;
128
+ title?: string;
129
+ description?: string;
130
+ submitLabel?: string;
131
+ };
132
+
133
+ type AssistedOptions = {
134
+ organisationUuid: string;
135
+ workspaceUuid: string;
136
+ noticeUuid: string;
137
+ baseUrl?: string;
138
+ ledgerBaseUrl?: string;
139
+ onDecline?: () => void;
140
+ onComplete?: () => void;
141
+ onError?: (error: Error) => void;
142
+ };
143
+
144
+ type PrivacyCenterOptions = {
145
+ /** Element, or CSS selector for it, that the Privacy Center is mounted in. */
146
+ target: string | HTMLElement;
147
+ /** The organisation's Privacy Center slug. Required unless `url` is given. */
148
+ slug?: string;
149
+ /** Full URL of the hosted Privacy Center, e.g. on a custom domain. Wins over `slug`. */
150
+ url?: string;
151
+ /** Where the hosted Privacy Center lives. Defaults to Redacto's production console. */
152
+ origin?: string;
153
+ /** Language to open in (`en`, `hi`, …), sent as `?lang=`. */
154
+ language?: string;
155
+ /**
156
+ * A fixed height (`640` or `"80vh"`). Leave it out (or pass `"auto"`) to let
157
+ * the frame grow to fit the page, starting at 720px.
158
+ */
159
+ height?: number | string;
160
+ /** The frame's accessible title. Defaults to "Privacy Center". */
161
+ title?: string;
162
+ };
163
+ type PrivacyCenterHandle = {
164
+ iframe: HTMLIFrameElement;
165
+ /** Removes the frame and stops listening for its height. */
166
+ destroy: () => void;
167
+ };
168
+
169
+ type ApiErrorCode = "INVALID_TOKEN" | "TOKEN_TENANT_MISMATCH" | "UNAUTHORIZED" | "USER_NOT_FOUND" | "USER_EMAIL_MISMATCH" | "USER_MOBILE_MISMATCH" | "USER_CONTACT_MISMATCH" | "NO_IDENTIFIER_PROVIDED" | "INVALID_PAYLOAD" | "VALIDATION_ERROR" | "NOTICE_NOT_FOUND" | "NOTICE_CONFIGURATION_NOT_FOUND" | "NOTICE_STILL_IN_DRAFT" | "CONSENT_ALREADY_PROVIDED" | "PURPOSE_NOT_FOUND" | "INVALID_PURPOSE" | "INVALID_DATA_ELEMENTS" | "MISSING_PURPOSE" | "MISSING_DATA_ELEMENTS" | "REQUIRED_DATA_ELEMENT_NOT_ENABLED" | "AUDIO_NOT_FOUND" | "INVALID_LANGUAGE" | "VERIFICATION_FAILED" | "VERIFICATION_EXPIRED" | "GUARDIAN_INFO_NOT_FOUND" | "GUARDIAN_SESSION_INVALID" | "SESSION_EXPIRED" | "INTERNAL_ERROR";
170
+ type ApiErrorCodeLike = ApiErrorCode | (string & {});
171
+
172
+ declare class ApiError extends Error {
173
+ readonly status: number;
174
+ readonly code?: ApiErrorCodeLike;
175
+ readonly shouldRequestNew?: boolean;
176
+ constructor(opts: {
177
+ status: number;
178
+ code?: ApiErrorCodeLike;
179
+ message: string;
180
+ shouldRequestNew?: boolean;
181
+ });
182
+ }
101
183
 
102
184
  /**
103
185
  * Initialize a modal consent dialog.
@@ -109,6 +191,13 @@ declare function init(options: ModalOptions): void;
109
191
  * Renders consent purposes inside a target container element.
110
192
  */
111
193
  declare function inline(options: InlineOptions): void;
194
+ declare function updateToken(accessToken: string): void;
195
+ declare function assisted(options: AssistedOptions): void;
196
+ /**
197
+ * Mount the hosted Privacy Center in an iframe inside a target element.
198
+ * Returns a handle whose `destroy()` removes it.
199
+ */
200
+ declare function privacyCenter(options: PrivacyCenterOptions): PrivacyCenterHandle;
112
201
  /**
113
202
  * Destroy all active consent instances.
114
203
  */
@@ -121,9 +210,12 @@ declare function digilockerCallback(options: DigiLockerCallbackOptions): void;
121
210
  declare const RedactoConsent: {
122
211
  init: typeof init;
123
212
  inline: typeof inline;
213
+ assisted: typeof assisted;
214
+ privacyCenter: typeof privacyCenter;
124
215
  destroy: typeof destroy;
125
216
  digilockerCallback: typeof digilockerCallback;
217
+ updateToken: typeof updateToken;
126
218
  version: string;
127
219
  };
128
220
 
129
- export { type DigiLockerCallbackOptions, type InlineOptions, type ModalOptions, type Settings, RedactoConsent as default, destroy, digilockerCallback, init, inline };
221
+ export { ApiError, type ApiErrorCode, type AssistedOptions, type DigiLockerCallbackOptions, type InlineOptions, type ModalOptions, type OtpGateOptions, type OtpVerifyResult, type PrivacyCenterHandle, type PrivacyCenterOptions, type Settings, assisted, RedactoConsent as default, destroy, digilockerCallback, init, inline, privacyCenter, updateToken };
package/dist/redacto.d.ts CHANGED
@@ -1,24 +1,40 @@
1
1
  /**
2
2
  * Optional sandbox options shared by the SDK's public option shapes and the
3
3
  * internal API params. When `token` is set the call sends the single
4
- * `X-Consent-Token` header instead of `Authorization: Bearer`, injects the
5
- * subject into each request's own payload, and takes org/workspace from these
6
- * fields instead of decoding the JWT.
4
+ * `X-Consent-Token` header instead of `Authorization: Bearer`, carries every
5
+ * supplied identifier in each request's own payload, and takes org/workspace
6
+ * from these fields instead of decoding the JWT.
7
7
  */
8
8
  type SandboxOptions = {
9
9
  token?: string;
10
- /** UCIC — the client's own user id (`org_user_id`); takes precedence over the subject. */
10
+ /** UCIC — the client's own user id (`org_user_id`); takes precedence for the principal. */
11
11
  sandboxUcic?: string;
12
+ /** Email — carried on every request like a live JWT's `user_data.primary_email`. */
13
+ sandboxEmail?: string;
14
+ /** Mobile — carried on every request like a live JWT's `user_data.primary_mobile`. */
15
+ sandboxMobile?: string;
16
+ /**
17
+ * @deprecated Use `sandboxEmail` / `sandboxMobile` (and/or `email` / `mobile`)
18
+ * instead. Still accepted for backward compatibility: a value containing "@"
19
+ * is treated as the email, otherwise the mobile.
20
+ */
12
21
  sandboxSubject?: string;
13
22
  organisationUuid?: string;
14
23
  workspaceUuid?: string;
15
24
  };
25
+ type SelectionControlType = "checkbox" | "radio" | "dropdown";
16
26
  type Settings = {
17
27
  button: {
28
+ /** Styles the "accept selected" button. */
18
29
  accept: {
19
30
  backgroundColor: string;
20
31
  textColor: string;
21
32
  };
33
+ /** Optional: the accept-all shortcut falls back to `accept` when unset. */
34
+ acceptAll?: {
35
+ backgroundColor: string;
36
+ textColor: string;
37
+ };
22
38
  decline: {
23
39
  backgroundColor: string;
24
40
  textColor: string;
@@ -37,6 +53,8 @@ type Settings = {
37
53
  textColor?: string;
38
54
  borderColor?: string;
39
55
  font?: string;
56
+ selectionControl?: SelectionControlType;
57
+ confirmBeforeSubmit?: boolean;
40
58
  };
41
59
 
42
60
  type ModalOptions = SandboxOptions & {
@@ -73,6 +91,8 @@ type ModalOptions = SandboxOptions & {
73
91
  digilockerCallbackUrl?: string;
74
92
  includeFullyConsentedData?: boolean;
75
93
  reviewModeButtonText?: string;
94
+ defaultOpenProducts?: string[];
95
+ otpGate?: OtpGateOptions;
76
96
  };
77
97
  type InlineOptions = {
78
98
  target: string | HTMLElement;
@@ -98,6 +118,68 @@ type DigiLockerCallbackOptions = {
98
118
  onSuccess?: (verificationReference: string) => void;
99
119
  onError?: (error: Error, errorCode?: string) => void;
100
120
  };
121
+ type OtpVerifyResult = {
122
+ ok: boolean;
123
+ message?: string;
124
+ };
125
+ type OtpGateOptions = {
126
+ required: boolean;
127
+ onVerify: (code: string) => Promise<OtpVerifyResult>;
128
+ title?: string;
129
+ description?: string;
130
+ submitLabel?: string;
131
+ };
132
+
133
+ type AssistedOptions = {
134
+ organisationUuid: string;
135
+ workspaceUuid: string;
136
+ noticeUuid: string;
137
+ baseUrl?: string;
138
+ ledgerBaseUrl?: string;
139
+ onDecline?: () => void;
140
+ onComplete?: () => void;
141
+ onError?: (error: Error) => void;
142
+ };
143
+
144
+ type PrivacyCenterOptions = {
145
+ /** Element, or CSS selector for it, that the Privacy Center is mounted in. */
146
+ target: string | HTMLElement;
147
+ /** The organisation's Privacy Center slug. Required unless `url` is given. */
148
+ slug?: string;
149
+ /** Full URL of the hosted Privacy Center, e.g. on a custom domain. Wins over `slug`. */
150
+ url?: string;
151
+ /** Where the hosted Privacy Center lives. Defaults to Redacto's production console. */
152
+ origin?: string;
153
+ /** Language to open in (`en`, `hi`, …), sent as `?lang=`. */
154
+ language?: string;
155
+ /**
156
+ * A fixed height (`640` or `"80vh"`). Leave it out (or pass `"auto"`) to let
157
+ * the frame grow to fit the page, starting at 720px.
158
+ */
159
+ height?: number | string;
160
+ /** The frame's accessible title. Defaults to "Privacy Center". */
161
+ title?: string;
162
+ };
163
+ type PrivacyCenterHandle = {
164
+ iframe: HTMLIFrameElement;
165
+ /** Removes the frame and stops listening for its height. */
166
+ destroy: () => void;
167
+ };
168
+
169
+ type ApiErrorCode = "INVALID_TOKEN" | "TOKEN_TENANT_MISMATCH" | "UNAUTHORIZED" | "USER_NOT_FOUND" | "USER_EMAIL_MISMATCH" | "USER_MOBILE_MISMATCH" | "USER_CONTACT_MISMATCH" | "NO_IDENTIFIER_PROVIDED" | "INVALID_PAYLOAD" | "VALIDATION_ERROR" | "NOTICE_NOT_FOUND" | "NOTICE_CONFIGURATION_NOT_FOUND" | "NOTICE_STILL_IN_DRAFT" | "CONSENT_ALREADY_PROVIDED" | "PURPOSE_NOT_FOUND" | "INVALID_PURPOSE" | "INVALID_DATA_ELEMENTS" | "MISSING_PURPOSE" | "MISSING_DATA_ELEMENTS" | "REQUIRED_DATA_ELEMENT_NOT_ENABLED" | "AUDIO_NOT_FOUND" | "INVALID_LANGUAGE" | "VERIFICATION_FAILED" | "VERIFICATION_EXPIRED" | "GUARDIAN_INFO_NOT_FOUND" | "GUARDIAN_SESSION_INVALID" | "SESSION_EXPIRED" | "INTERNAL_ERROR";
170
+ type ApiErrorCodeLike = ApiErrorCode | (string & {});
171
+
172
+ declare class ApiError extends Error {
173
+ readonly status: number;
174
+ readonly code?: ApiErrorCodeLike;
175
+ readonly shouldRequestNew?: boolean;
176
+ constructor(opts: {
177
+ status: number;
178
+ code?: ApiErrorCodeLike;
179
+ message: string;
180
+ shouldRequestNew?: boolean;
181
+ });
182
+ }
101
183
 
102
184
  /**
103
185
  * Initialize a modal consent dialog.
@@ -109,6 +191,13 @@ declare function init(options: ModalOptions): void;
109
191
  * Renders consent purposes inside a target container element.
110
192
  */
111
193
  declare function inline(options: InlineOptions): void;
194
+ declare function updateToken(accessToken: string): void;
195
+ declare function assisted(options: AssistedOptions): void;
196
+ /**
197
+ * Mount the hosted Privacy Center in an iframe inside a target element.
198
+ * Returns a handle whose `destroy()` removes it.
199
+ */
200
+ declare function privacyCenter(options: PrivacyCenterOptions): PrivacyCenterHandle;
112
201
  /**
113
202
  * Destroy all active consent instances.
114
203
  */
@@ -121,9 +210,12 @@ declare function digilockerCallback(options: DigiLockerCallbackOptions): void;
121
210
  declare const RedactoConsent: {
122
211
  init: typeof init;
123
212
  inline: typeof inline;
213
+ assisted: typeof assisted;
214
+ privacyCenter: typeof privacyCenter;
124
215
  destroy: typeof destroy;
125
216
  digilockerCallback: typeof digilockerCallback;
217
+ updateToken: typeof updateToken;
126
218
  version: string;
127
219
  };
128
220
 
129
- export { type DigiLockerCallbackOptions, type InlineOptions, type ModalOptions, type Settings, RedactoConsent as default, destroy, digilockerCallback, init, inline };
221
+ export { ApiError, type ApiErrorCode, type AssistedOptions, type DigiLockerCallbackOptions, type InlineOptions, type ModalOptions, type OtpGateOptions, type OtpVerifyResult, type PrivacyCenterHandle, type PrivacyCenterOptions, type Settings, assisted, RedactoConsent as default, destroy, digilockerCallback, init, inline, privacyCenter, updateToken };