@snapkyc-ooru/consent-handoff-react 0.1.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/README.md +158 -0
- package/dist/index.cjs +1395 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +225 -0
- package/dist/index.d.ts +225 -0
- package/dist/index.js +1343 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +710 -0
- package/package.json +54 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
declare class SnapSdkHttpError extends Error {
|
|
5
|
+
readonly url: string;
|
|
6
|
+
readonly status: number;
|
|
7
|
+
readonly bodyText?: string | undefined;
|
|
8
|
+
readonly name = "SnapSdkHttpError";
|
|
9
|
+
constructor(url: string, status: number, message: string, bodyText?: string | undefined);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type IntentOs = "android" | "ios";
|
|
13
|
+
|
|
14
|
+
type DemographicData = {
|
|
15
|
+
resident_name?: string;
|
|
16
|
+
resident_name_local_language?: string;
|
|
17
|
+
date_of_birth?: string;
|
|
18
|
+
gender?: string;
|
|
19
|
+
care_of?: string;
|
|
20
|
+
full_address?: string;
|
|
21
|
+
regional_address?: string;
|
|
22
|
+
mobile_number?: string;
|
|
23
|
+
masked_mobile_number?: string;
|
|
24
|
+
email_address?: string;
|
|
25
|
+
masked_email_address?: string;
|
|
26
|
+
state?: string;
|
|
27
|
+
district?: string;
|
|
28
|
+
sub_district?: string;
|
|
29
|
+
village_town_city?: string;
|
|
30
|
+
postal_code?: string;
|
|
31
|
+
resident_image?: string;
|
|
32
|
+
[key: string]: unknown;
|
|
33
|
+
};
|
|
34
|
+
type TxnStatusEvidence = {
|
|
35
|
+
aadhaar_uuid?: string;
|
|
36
|
+
sd_jwt?: string;
|
|
37
|
+
disclosures?: unknown[];
|
|
38
|
+
demographic_data?: DemographicData;
|
|
39
|
+
[key: string]: unknown;
|
|
40
|
+
};
|
|
41
|
+
type TxnStatusData = {
|
|
42
|
+
txn_id: string;
|
|
43
|
+
status: string;
|
|
44
|
+
created_at?: string;
|
|
45
|
+
purposes?: {
|
|
46
|
+
id: string;
|
|
47
|
+
name: string;
|
|
48
|
+
}[];
|
|
49
|
+
evidence?: TxnStatusEvidence;
|
|
50
|
+
};
|
|
51
|
+
type TxnStatusResponse = TxnStatusData & {
|
|
52
|
+
/** passthrough unknown fields returned with SUCCESS payloads */
|
|
53
|
+
[key: string]: unknown;
|
|
54
|
+
};
|
|
55
|
+
/** Optional overrides for `POST /api/integrations/generate-qr` (txn_id is set by the SDK). */
|
|
56
|
+
type QrRequestOverrides = {
|
|
57
|
+
size?: number;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Resolved visual tokens for the consent handoff UI.
|
|
62
|
+
* Pass a partial object via `theme` on `SnapConsentHandoffFlow` to override defaults.
|
|
63
|
+
*/
|
|
64
|
+
type SnapConsentHandoffTheme = {
|
|
65
|
+
fontFamily: string;
|
|
66
|
+
/** Primary brand color (buttons, selected states, accents). */
|
|
67
|
+
primary: string;
|
|
68
|
+
/** Text/icon color on top of primary (typically white). */
|
|
69
|
+
onPrimary: string;
|
|
70
|
+
/** Sheet / panel background (e.g. warm light gray). */
|
|
71
|
+
canvas: string;
|
|
72
|
+
/** Default “card” surface (e.g. unselected purpose rows). */
|
|
73
|
+
surface: string;
|
|
74
|
+
/** Muted surface (agreement notice, selected purpose row). */
|
|
75
|
+
surfaceMuted: string;
|
|
76
|
+
text: string;
|
|
77
|
+
textMuted: string;
|
|
78
|
+
border: string;
|
|
79
|
+
/** Strong border for selected / emphasized controls. */
|
|
80
|
+
borderActive: string;
|
|
81
|
+
modalOverlay: string;
|
|
82
|
+
danger: string;
|
|
83
|
+
/** Corner radius for cards, rows, and buttons (e.g. `12px`). */
|
|
84
|
+
radius: string;
|
|
85
|
+
gap: string;
|
|
86
|
+
maxWidth: string;
|
|
87
|
+
modalZ: string;
|
|
88
|
+
/** Success state (shield, status checkmarks). */
|
|
89
|
+
success: string;
|
|
90
|
+
/** Success screen status summary card background. */
|
|
91
|
+
successStatusSurface: string;
|
|
92
|
+
/** Success screen confirmed-purposes panel background. */
|
|
93
|
+
successPurposesSurface: string;
|
|
94
|
+
/** Accordion borders on the success demographic panel. */
|
|
95
|
+
successAccordionBorder: string;
|
|
96
|
+
};
|
|
97
|
+
declare const DEFAULT_SNAP_CONSENT_THEME: SnapConsentHandoffTheme;
|
|
98
|
+
declare function resolveSnapConsentTheme(partial?: Partial<SnapConsentHandoffTheme>): SnapConsentHandoffTheme;
|
|
99
|
+
/**
|
|
100
|
+
* Maps resolved theme tokens to CSS custom properties on `.snap-consent-handoff`.
|
|
101
|
+
*/
|
|
102
|
+
declare function themeToCssProperties(theme: SnapConsentHandoffTheme): CSSProperties;
|
|
103
|
+
|
|
104
|
+
type HandoffMode = "qr" | "intent";
|
|
105
|
+
type IntentDetectionMeta = {
|
|
106
|
+
kind: "resolved";
|
|
107
|
+
platform: IntentOs;
|
|
108
|
+
} | {
|
|
109
|
+
kind: "ambiguous-choice";
|
|
110
|
+
chosen?: IntentOs;
|
|
111
|
+
} | {
|
|
112
|
+
kind: "forced";
|
|
113
|
+
platform: IntentOs;
|
|
114
|
+
};
|
|
115
|
+
type FlowPhase = "agreement-loading" | "agreement-ready" | "txn-initiating" | "txn-created" | "handoff-loading" | "handoff-ready" | "polling" | "completed" | "failed" | "cancelled";
|
|
116
|
+
type FlowEvent = {
|
|
117
|
+
phase: Exclude<FlowPhase, "failed">;
|
|
118
|
+
txnId?: string;
|
|
119
|
+
meta?: IntentDetectionMeta;
|
|
120
|
+
error?: never;
|
|
121
|
+
} | {
|
|
122
|
+
phase: "failed";
|
|
123
|
+
txnId?: string;
|
|
124
|
+
meta?: IntentDetectionMeta;
|
|
125
|
+
error: unknown;
|
|
126
|
+
};
|
|
127
|
+
type CompletionResult = {
|
|
128
|
+
txn_id?: string;
|
|
129
|
+
status: unknown;
|
|
130
|
+
raw: TxnStatusResponse;
|
|
131
|
+
};
|
|
132
|
+
type RpContext = {
|
|
133
|
+
reference_id: string;
|
|
134
|
+
session_id?: string;
|
|
135
|
+
};
|
|
136
|
+
type SnapConsentHandoffPublicProps = {
|
|
137
|
+
integrationToken: string;
|
|
138
|
+
rpContext: RpContext;
|
|
139
|
+
agreementId?: string;
|
|
140
|
+
acceptLanguage?: string;
|
|
141
|
+
handoffMode: HandoffMode;
|
|
142
|
+
qrRequestBody?: QrRequestOverrides;
|
|
143
|
+
pollIntervalMs?: number;
|
|
144
|
+
pollDeadlineMs?: number;
|
|
145
|
+
intentPlatformOverride?: IntentOs | undefined;
|
|
146
|
+
/** @deprecated prefer `_dangerouslyForceIntentPlatform` */
|
|
147
|
+
dangerousForceIntentPlatform?: IntentOs;
|
|
148
|
+
/** QA escape hatch ONLY — not suggested for production RP integrations */
|
|
149
|
+
_dangerouslyForceIntentPlatform?: IntentOs;
|
|
150
|
+
/** Optional UA override for SSR/tests */
|
|
151
|
+
userAgent?: string;
|
|
152
|
+
onFlowEvent?: (evt: FlowEvent) => void;
|
|
153
|
+
onSuccess?: (result: CompletionResult) => void;
|
|
154
|
+
onError?: (err: unknown) => void;
|
|
155
|
+
onRequestClose?: () => void;
|
|
156
|
+
displayMode?: "modal" | "inline";
|
|
157
|
+
title?: string;
|
|
158
|
+
/** Optional palette and layout tokens; merged with built-in defaults. */
|
|
159
|
+
theme?: Partial<SnapConsentHandoffTheme>;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
type DemographicField = {
|
|
163
|
+
/** Original API field name (snake_case). */
|
|
164
|
+
key: string;
|
|
165
|
+
label: string;
|
|
166
|
+
value: string;
|
|
167
|
+
};
|
|
168
|
+
type DemographicAccordionSection = {
|
|
169
|
+
id: string;
|
|
170
|
+
title: string;
|
|
171
|
+
fields: DemographicField[];
|
|
172
|
+
/** When true, render resident photo in this section (Personal Details only). */
|
|
173
|
+
includePhoto: boolean;
|
|
174
|
+
};
|
|
175
|
+
declare function extractDemographicData(status: TxnStatusResponse | null | undefined): DemographicData | null;
|
|
176
|
+
declare function hasDisplayableDemographics(status: TxnStatusResponse | null | undefined): boolean;
|
|
177
|
+
declare function formatDisplayValue(value: unknown): string;
|
|
178
|
+
/** All demographic_data fields; empty / object values render as `null`. */
|
|
179
|
+
declare function demographicFieldsForDisplay(data: DemographicData): DemographicField[];
|
|
180
|
+
/**
|
|
181
|
+
* Groups demographic fields into accordion sections (Personal, Contact, Address, Additional).
|
|
182
|
+
* Personal Details may include a photo slot when `includePhoto` is true.
|
|
183
|
+
*/
|
|
184
|
+
declare function demographicAccordionSections(data: DemographicData, options: {
|
|
185
|
+
includePhoto: boolean;
|
|
186
|
+
}): DemographicAccordionSection[];
|
|
187
|
+
declare function formatPurposeLabel(name: unknown): string;
|
|
188
|
+
|
|
189
|
+
declare function parseDemographicPayload(raw: unknown): DemographicData | null;
|
|
190
|
+
/**
|
|
191
|
+
* Normalizes status payloads from GET …/transactions/{id}/status into a stable shape
|
|
192
|
+
* for UI + onSuccess, even if the host accidentally passes the full API envelope.
|
|
193
|
+
*/
|
|
194
|
+
declare function normalizeTxnStatusPayload(input: unknown): TxnStatusResponse;
|
|
195
|
+
|
|
196
|
+
declare function SnapConsentHandoffFlow(props: SnapConsentHandoffPublicProps): react_jsx_runtime.JSX.Element | null;
|
|
197
|
+
|
|
198
|
+
type OpenSnapConsentHandoffOptions = Omit<SnapConsentHandoffPublicProps, "displayMode" | "onRequestClose"> & Partial<Pick<SnapConsentHandoffPublicProps, "displayMode">> & {
|
|
199
|
+
/**
|
|
200
|
+
* Render in StrictMode — mostly useful during development.
|
|
201
|
+
* Default false to avoid duplicated effects/timeouts surprises in overlays.
|
|
202
|
+
*/
|
|
203
|
+
strict?: boolean;
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* Opens a modal consent + handoff flow mounted on `document.body`.
|
|
207
|
+
*
|
|
208
|
+
* Important: callers should keep the returned `{ dispose }` and invoke it when navigating away so
|
|
209
|
+
* polling aborts cleanly and blob/object URLs revoke via component unmount.
|
|
210
|
+
*/
|
|
211
|
+
declare function openSnapConsentHandoffFlow(options: OpenSnapConsentHandoffOptions): {
|
|
212
|
+
dispose(): void;
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* Deprecated alias kept for docs that referenced a QR-specific opener name.
|
|
216
|
+
*/
|
|
217
|
+
declare const openSnapConsentQrFlow: typeof openSnapConsentHandoffFlow;
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* API origin bundled with the SDK. Replace at publish-time (staging/prod) via your build pipeline
|
|
221
|
+
* or bump this constant per release artefact — hosts cannot override `baseUrl` at runtime.
|
|
222
|
+
*/
|
|
223
|
+
declare const API_ORIGIN = "https://staging-api.snapkyc.com/";
|
|
224
|
+
|
|
225
|
+
export { API_ORIGIN, type CompletionResult, DEFAULT_SNAP_CONSENT_THEME, type DemographicAccordionSection, type DemographicData, type DemographicField, type FlowEvent, type FlowPhase, type HandoffMode, type OpenSnapConsentHandoffOptions, type RpContext, SnapConsentHandoffFlow, type SnapConsentHandoffPublicProps, type SnapConsentHandoffTheme, SnapSdkHttpError, type TxnStatusEvidence, type TxnStatusResponse, demographicAccordionSections, demographicFieldsForDisplay, extractDemographicData, formatDisplayValue, formatPurposeLabel, hasDisplayableDemographics, normalizeTxnStatusPayload, openSnapConsentHandoffFlow, openSnapConsentQrFlow, parseDemographicPayload, resolveSnapConsentTheme, themeToCssProperties };
|