@encatch/web-sdk 1.3.0 → 1.4.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,474 +1,629 @@
1
- /**
2
- * Encatch Web SDK Type Definitions
3
- */
4
- /**
5
- * User traits for identifying users
6
- * Supports nested operations: $set, $setOnce, $increment, $decrement, $unset
7
- */
8
- export interface UserTraits {
9
- /** Set user attributes (overwrites existing values) */
10
- $set?: Record<string, any>;
11
- /** Set user attributes only if they don't already exist */
12
- $setOnce?: Record<string, any>;
13
- /** Increment numeric user attributes */
14
- $increment?: Record<string, number>;
15
- /** Decrement numeric user attributes */
16
- $decrement?: Record<string, number>;
17
- /** Remove user attributes */
18
- $unset?: string[];
19
- }
20
- /**
21
- * Secure options for user identification
22
- */
23
- export interface SecureOptions {
24
- /** User signature (required when secure is set) */
25
- signature: string;
26
- /** Optional datetime in UTC when the signature was generated */
27
- generatedDateTimeinUTC?: string;
28
- }
29
- /**
30
- * Options for the identifyUser method
31
- */
32
- export interface IdentifyOptions {
33
- /** User's preferred locale (ISO 639-1 codes, comma-separated) */
34
- locale?: string;
35
- /** User's country (ISO 3166 country code) */
36
- country?: string;
37
- /** Secure identification options with signature */
38
- secure?: SecureOptions;
39
- }
40
- /**
41
- * Options for the startSession method
42
- */
43
- export interface StartSessionOptions {
44
- /** When true, do not call the immediate ping (30s ping interval still runs) */
45
- skipImmediatePing?: boolean;
46
- /**
47
- * When true, do not send the initial trackScreen for the current URL
48
- * (URL change listeners still run). Defaults to true.
49
- */
50
- skipImmediateTrackScreen?: boolean;
51
- }
52
- /**
53
- * Theme options
54
- */
55
- export type Theme = 'light' | 'dark' | 'system';
56
- /**
57
- * Configuration options for the SDK
58
- */
59
- export interface EncatchConfig {
60
- /** Override the default web host for loading the SDK script */
61
- webHost?: string;
62
- /** Theme setting - defaults to 'system' */
63
- theme?: Theme;
64
- /** API base URL - defaults to 'https://app.encatch.com' */
65
- apiBaseUrl?: string;
66
- /** When true, displays the form inline at full height without modal overlay */
67
- isFullScreen?: boolean;
68
- /**
69
- * Optional interceptor called before any form is shown (manual or automatic).
70
- * Receives the form configuration payload. If it returns false (or Promise<false>),
71
- * the SDK will not display its built-in iframe form; the app can instead render a
72
- * custom UI and use submitForm / emitEvent / refineText to complete the flow.
73
- * Pending responses from addToResponse() are cleared when false is returned.
74
- */
75
- onBeforeShowForm?: (payload: ShowFormInterceptorPayload) => boolean | Promise<boolean>;
76
- }
77
- /**
78
- * Payload passed to the onBeforeShowForm interceptor.
79
- * Contains the full form configuration returned by the server along with
80
- * context values the SDK resolved at call time.
81
- */
82
- export interface ShowFormInterceptorPayload {
83
- /** The form slug or ID that was requested */
84
- formId: string;
85
- /** Raw form configuration returned by the show-form API */
86
- formConfig: Record<string, unknown>;
87
- /** Reset mode in effect for this show call */
88
- resetMode: ResetMode;
89
- /** Whether the form was triggered automatically (server-side) or manually (developer call) */
90
- triggerType: 'automatic' | 'manual';
91
- /** Pre-filled responses staged via addToResponse() */
92
- prefillResponses: Record<string, unknown>;
93
- /** Active locale, if set */
94
- locale?: string;
95
- /** Active theme */
96
- theme?: Theme;
97
- /** Serialized context values (Dates already converted to ISO strings) */
98
- context?: Record<string, string | number | boolean>;
99
- }
100
- /**
101
- * An individual question answer within a form submission
102
- */
103
- export interface QuestionAnswer {
104
- nps?: number;
105
- csat?: number;
106
- /** Star-rating / rating scale answer (schema field: `rating`) */
107
- rating?: number;
108
- singleChoice?: string;
109
- singleChoiceOther?: string;
110
- multipleChoiceMultiple?: string[];
111
- /** Free-text "Other" answer for multiple-choice-multiple questions (schema field: `multipleChoiceOther`) */
112
- multipleChoiceOther?: string;
113
- nestedSelection?: string[];
114
- shortAnswer?: string;
115
- longText?: string;
116
- }
117
- /**
118
- * A single question response within a form submission
119
- */
120
- export interface QuestionResponse {
121
- questionId: string;
122
- type?: string;
123
- answer?: QuestionAnswer;
124
- /** Present on engine-built submits: whether this question was on the respondent's path */
125
- isOnPath?: boolean;
126
- }
127
- /**
128
- * Form details for a manual form submission
129
- */
130
- export interface FormDetails {
131
- /** The server-issued configuration ID for this form */
132
- formConfigurationId: string;
133
- /** When true, marks this as a partial (mid-journey) submission */
134
- isPartialSubmit?: boolean;
135
- feedbackIdentifier?: string;
136
- responseLanguageCode?: string;
137
- response?: {
138
- questions?: QuestionResponse[];
139
- };
140
- completionTimeInSeconds?: number;
141
- /** Caller-provided metadata attached to this submission (Dates already serialized to ISO strings) */
142
- context?: Record<string, string | number | boolean>;
143
- /** IDs of questions the user actually visited, in order */
144
- visitedQuestionIds?: string[];
145
- }
146
- /**
147
- * Parameters for manually submitting a form (used with onBeforeShowForm interceptor)
148
- */
149
- export interface SubmitFormRequest {
150
- triggerType?: 'automatic' | 'manual';
151
- formDetails: FormDetails;
152
- }
153
- /**
154
- * Parameters for the refineText AI enhancement endpoint
155
- */
156
- export interface RefineTextRequest {
157
- questionId: string;
158
- feedbackConfigurationId: string;
159
- userText: string;
160
- }
161
- /**
162
- * Response from the refineText endpoint
163
- */
164
- export interface RefineTextResponse {
165
- message?: string;
166
- refinedText?: string;
167
- status?: number;
168
- error?: string;
169
- code?: string;
170
- }
171
- /**
172
- * A single turn in a Q&A with AI conversation
173
- */
174
- export interface QnaWithAiConversationTurn {
175
- /** The question asked by the respondent */
176
- question: string;
177
- /** The AI's answer; empty string for the current unanswered turn */
178
- answer: string;
179
- }
180
- /**
181
- * Parameters for the qnaWithAi endpoint
182
- */
183
- export interface QnaWithAiRequest {
184
- feedbackConfigurationId: string;
185
- questionId: string;
186
- /** Full conversation including the current unanswered turn as the last entry */
187
- conversation: QnaWithAiConversationTurn[];
188
- }
189
- /**
190
- * Response from the qnaWithAi endpoint
191
- */
192
- export interface QnaWithAiResponse {
193
- answer: string;
194
- }
195
- /**
196
- * Parameters for the uploadFile method
197
- */
198
- export interface UploadFileRequest {
199
- /** The form's server-issued configuration ID */
200
- feedbackConfigurationId: string;
201
- /** The question ID the file belongs to */
202
- questionId: string;
203
- /** The file or blob to upload */
204
- file: File | Blob;
205
- /**
206
- * File name to send to the server (e.g. "signature.png").
207
- * Defaults to "upload" when omitted.
208
- */
209
- fileName?: string;
210
- /**
211
- * Optional progress callback — receives upload percentage (0–100).
212
- * Useful for driving a progress bar in custom UIs.
213
- */
214
- onProgress?: (percent: number) => void;
215
- }
216
- /**
217
- * Response from the uploadFile endpoint
218
- */
219
- export interface UploadFileResponse {
220
- /** Permanent URL of the uploaded file */
221
- fileUrl: string;
222
- }
223
- /**
224
- * Reset mode for form data when showing a form
225
- * - 'always': Clear form data every time showForm is called (default)
226
- * - 'on-complete': Clear form data only if form was previously completed
227
- * - 'never': Never clear form data (preserve user's previous answers)
228
- */
229
- export type ResetMode = 'always' | 'on-complete' | 'never';
230
- /**
231
- * Context values that can be attached to a form submission.
232
- * Date values are automatically serialized to ISO strings before being sent.
233
- */
234
- export type ContextValue = string | number | Date | boolean;
235
- /**
236
- * Options for the showForm method
237
- */
238
- export interface ShowFormOptions {
239
- /**
240
- * Controls when form data should be cleared
241
- * @default 'always'
242
- */
243
- reset?: ResetMode;
244
- /**
245
- * Arbitrary key-value pairs attached to the form submission.
246
- * Useful for passing caller-side metadata (e.g. plan tier, feature flag states).
247
- * Date values are automatically serialized to ISO 8601 strings.
248
- */
249
- context?: Record<string, ContextValue>;
250
- }
251
- /**
252
- * Event types that can be subscribed to
253
- */
254
- export type EventType = 'form:show' | 'form:started' | 'form:submit'
255
- /**
256
- * For `exit_form` with `autoTriggerDelayMs`, the SDK may close the form on this event
257
- * and fire `form:ctaTriggered` after the delay from the parent window (not the iframe).
258
- * Host apps do not schedule timers — this is SDK-internal.
259
- */
260
- | 'form:complete' | 'form:close' | 'form:dismissed' | 'form:error' | 'form:section:change' | 'form:answered' | 'form:remindmelater'
261
- /**
262
- * Fired when a completionCta action fires on a thank_you or exit_form screen.
263
- * payload.data: { action, route?, url?, surface, trigger }
264
- *
265
- * - action "app_navigate": host navigates to data.route in _encatch.on(); the SDK
266
- * closes the form iframe automatically after emitting this event.
267
- * - action "redirect_internal": the SDK navigates the parent page to data.url (same tab);
268
- * the form is already closing.
269
- * - action "redirect_external": the SDK opens data.url in a new tab; the form is already closing.
270
- */
271
- | 'form:ctaTriggered';
272
- /**
273
- * Event callback function type
274
- * Receives all form events with the event type and payload
275
- */
276
- export type EventCallback = (eventType: EventType, payload: EventPayload) => void;
277
- /**
278
- * Event payload structure
279
- */
280
- export interface EventPayload {
281
- /** The form ID related to the event */
282
- formId?: string;
283
- /** Timestamp of the event */
284
- timestamp: number;
285
- /** Additional event-specific data */
286
- data?: Record<string, unknown>;
287
- }
288
- /**
289
- * Internal command tuple type for the queue
290
- */
291
- export type Command = [string, ...unknown[]];
292
- /**
293
- * The Encatch SDK interface
294
- */
295
- export interface EncatchSDK {
296
- /**
297
- * Initialize the SDK with an API key
298
- * This triggers the loading of the remote implementation script
299
- * @param apiKey - Your Encatch API key
300
- * @param config - Optional configuration options
301
- */
302
- init(apiKey: string, config?: EncatchConfig): void;
303
- /**
304
- * Identify the current user
305
- * @param userName - User name or unique identifier (e.g. username, email) (required)
306
- * @param traits - Optional user traits with nested operations ($set, $setOnce, $increment, $decrement, $unset)
307
- * @param options - Optional settings like locale, country, and secure signature
308
- */
309
- identifyUser(userName: string, traits?: UserTraits, options?: IdentifyOptions): void;
310
- /**
311
- * Set the user's preferred locale
312
- * @param locale - Comma-separated ISO 639-1 language codes (e.g., 'fr,en,es')
313
- */
314
- setLocale(locale: string): void;
315
- /**
316
- * Set the user's country
317
- * @param country - ISO 3166 country code (e.g., 'US', 'FR')
318
- */
319
- setCountry(country: string): void;
320
- /**
321
- * Set the theme
322
- * @param theme - Theme value ('light', 'dark', or 'system')
323
- */
324
- setTheme(theme: Theme): void;
325
- /**
326
- * Track a custom event
327
- * @param eventName - Name of the event to track
328
- */
329
- trackEvent(eventName: string): void;
330
- /**
331
- * Track a screen view
332
- * @param screenName - Name of the screen to track
333
- */
334
- trackScreen(screenName: string): void;
335
- /**
336
- * Manually start a new session
337
- * Useful after user login to reset session timing
338
- * @param options - Optional flags to skip immediate ping and/or immediate trackScreen
339
- */
340
- startSession(options?: StartSessionOptions): void;
341
- /**
342
- * Temporarily stops the automatic background ping without affecting open forms,
343
- * URL change listeners, or user identity. Reversed by resumeSession().
344
- * Not persisted — clears automatically on page reload.
345
- */
346
- pauseSession(): void;
347
- /**
348
- * Restarts the background ping interval after a pauseSession() call.
349
- * No-op if the session was not paused.
350
- */
351
- resumeSession(): void;
352
- /**
353
- * Fully suspends all SDK activity — stops the ping interval, URL change
354
- * tracking, and closes any open forms. User identity is preserved.
355
- * Persists across page reloads via localStorage. Re-enable with startSession().
356
- */
357
- stopSession(): void;
358
- /**
359
- * Reset the current user (logout)
360
- * Reverts the SDK to anonymous mode
361
- */
362
- resetUser(): void;
363
- /**
364
- * Show a specific form by ID
365
- * @param formId - The ID of the form to display
366
- * @param options - Optional settings for form display behavior
367
- */
368
- showForm(formId: string, options?: ShowFormOptions): void;
369
- /**
370
- * Dismiss a form and report to the server
371
- * Closes the iframe if open and calls the dismiss-form endpoint
372
- * @param formConfigurationId - The form configuration ID to dismiss (required for API call)
373
- */
374
- dismissForm(formConfigurationId?: string): void;
375
- /**
376
- * Prepopulate a form response.
377
- * @param questionId - The ID or slug of the question to prepopulate. When a slug
378
- * is provided the form engine resolves it to the matching question ID automatically.
379
- * @param value - The value to set
380
- */
381
- addToResponse(questionId: string, value: unknown): void;
382
- /**
383
- * Manually submit a form to the Encatch API.
384
- * Use this when onBeforeShowForm returns false and you render a custom UI —
385
- * call submitForm once the user completes your custom form.
386
- * @param params - Submission details including formConfigurationId and question responses
387
- */
388
- submitForm(params: SubmitFormRequest): void;
389
- /**
390
- * Emit a form lifecycle event to all on() subscribers.
391
- * Use this when onBeforeShowForm returns false to mirror the events that the
392
- * built-in iframe form would normally fire (e.g. form:show, form:started,
393
- * form:answered, form:submit, form:complete, form:close).
394
- * @param eventType - The event type to emit
395
- * @param payload - Event payload (timestamp is added automatically)
396
- */
397
- emitEvent(eventType: EventType, payload: Omit<EventPayload, 'timestamp'>): void;
398
- /**
399
- * Request AI text refinement for a long-text answer.
400
- * Use this when onBeforeShowForm returns false and your custom UI includes
401
- * an AI-enhance feature.
402
- * @param params - The question ID, form configuration ID, and user text to refine
403
- * @returns Promise resolving to the refined text response
404
- */
405
- refineText(params: RefineTextRequest): Promise<RefineTextResponse>;
406
- /**
407
- * Call the Q&A with AI endpoint for a qna_with_ai question.
408
- * Sends the full conversation history (including the current unanswered turn) and
409
- * returns the AI-generated answer.
410
- * @param params - feedbackConfigurationId, questionId, and full conversation array
411
- * @returns Promise resolving to { answer: string }
412
- */
413
- qnaWithAi(params: QnaWithAiRequest): Promise<QnaWithAiResponse>;
414
- /**
415
- * Streaming variant of qnaWithAi.
416
- * Calls onChunk for each partial delta as the AI generates the answer,
417
- * and onDone with the final authoritative answer when complete.
418
- * @param params - feedbackConfigurationId, questionId, and full conversation array
419
- * @param callbacks.onChunk - Called for each partial text delta
420
- * @param callbacks.onDone - Called once with the complete final answer
421
- * @returns Promise that resolves when the stream is complete
422
- */
423
- streamQnaWithAi(params: QnaWithAiRequest, callbacks: {
424
- onChunk: (delta: string) => void;
425
- onDone: (answer: string) => void;
426
- }): Promise<void>;
427
- /**
428
- * Upload a file to the Encatch file storage.
429
- * Use this when onBeforeShowForm returns false and your custom UI contains a
430
- * file, image, signature, or media question — call uploadFile for each selected
431
- * file and store the returned fileUrl in your answer payload.
432
- * @param params - feedbackConfigurationId, questionId, file, optional fileName and onProgress
433
- * @returns Promise resolving to { fileUrl: string }
434
- */
435
- uploadFile(params: UploadFileRequest): Promise<UploadFileResponse>;
436
- /**
437
- * Subscribe to all form events
438
- * The callback receives all form events (show, submit, close, complete, error)
439
- * @param callback - Function to call when any form event occurs
440
- * @returns Unsubscribe function
441
- */
442
- on(callback: EventCallback): () => void;
443
- /**
444
- * Clear all SDK state and stored data, reverting to a brand-new visitor state.
445
- * Stops the ping interval and URL change listeners, clears all localStorage and
446
- * IndexedDB data written by the SDK, and resets all in-memory identity state.
447
- * showForm() and submitForm() continue to work after this call (with NIL UUIDs),
448
- * but no tracking fires until startSession() or identifyUser() is called again.
449
- * Use this to implement a "forget me" / consent withdrawal flow.
450
- */
451
- clearAll(): void;
452
- /**
453
- * Merge additional source tracking key-value pairs into the SDK's in-memory
454
- * source tracking store. These values are combined with auto-parsed URL params
455
- * whenever showForm() is called. Values set here take precedence over URL params
456
- * on key collision. Persists in memory for the lifetime of the page session.
457
- * Supported on the web SDK only.
458
- * @param values - Key-value pairs to merge into the source tracking store
459
- */
460
- addSourceTracking(values: Record<string, string>): void;
461
- /** Internal: Command queue for calls made before script loads */
462
- _q: Command[];
463
- /** Internal: Event callbacks */
464
- _eventCallbacks: EventCallback[];
465
- /** Internal: Whether the SDK has been initialized */
466
- _initialized: boolean;
467
- /** Internal: The API key */
468
- _apiKey: string | null;
469
- /** Internal: Configuration */
470
- _config: EncatchConfig;
471
- }
1
+ /** Answer for an address question. */
2
+ declare interface AddressAnswer {
3
+ addressLine1?: string;
4
+ addressLine2?: string;
5
+ city?: string;
6
+ stateProvince?: string;
7
+ postalCode?: string;
8
+ country?: string;
9
+ }
10
+
11
+ /** Annotation answer containing file metadata and markers. */
12
+ declare interface Annotation {
13
+ fileType: string;
14
+ fileName: string;
15
+ markers: AnnotationMarker[];
16
+ }
17
+
18
+ /** A single annotation marker placed on a file. */
19
+ declare interface AnnotationMarker {
20
+ markerNo: string;
21
+ timeline: string;
22
+ comment: string;
23
+ }
24
+
25
+ /** Flexible answer item supporting every question type. */
26
+ declare interface AnswerItem {
27
+ nps?: number;
28
+ nestedSelection?: string[];
29
+ longText?: string;
30
+ shortAnswer?: string;
31
+ singleChoice?: string;
32
+ rating?: number;
33
+ yesNo?: boolean;
34
+ consent?: boolean;
35
+ multipleChoiceMultiple?: string[];
36
+ singleChoiceOther?: string;
37
+ multipleChoiceOther?: string;
38
+ annotation?: Annotation;
39
+ ratingMatrix?: Record<string, number | string>;
40
+ matrixSingleChoice?: Record<string, string>;
41
+ matrixMultipleChoice?: Record<string, string[]>;
42
+ others?: string;
43
+ date?: string;
44
+ csat?: number;
45
+ opinionScale?: number;
46
+ ranking?: string[];
47
+ pictureChoice?: string[];
48
+ pictureChoiceOther?: string;
49
+ signature?: SignatureAnswer;
50
+ fileUpload?: FileUploadAnswer;
51
+ email?: string;
52
+ number?: string;
53
+ website?: string;
54
+ phoneNumber?: PhoneNumberAnswer;
55
+ address?: AddressAnswer;
56
+ videoAudio?: VideoAudioAnswer;
57
+ scheduler?: SchedulerAnswer;
58
+ qnaWithAi?: QnaWithAiAnswer;
59
+ paymentsUpi?: PaymentsUpiAnswer;
60
+ }
61
+
62
+ /**
63
+ * Internal command tuple type for the queue
64
+ */
65
+ declare type Command = [string, ...unknown[]];
66
+
67
+ /**
68
+ * Context values that can be attached to a form submission.
69
+ * Date values are automatically serialized to ISO strings before being sent.
70
+ */
71
+ declare type ContextValue = string | number | Date | boolean;
72
+
73
+ declare const _encatch: EncatchSDK;
74
+ export { _encatch }
75
+ export default _encatch;
76
+
77
+ /**
78
+ * Configuration options for the SDK
79
+ */
80
+ export declare interface EncatchConfig {
81
+ /** Override the default web host for loading the SDK script */
82
+ webHost?: string;
83
+ /** Theme setting - defaults to 'system' */
84
+ theme?: Theme;
85
+ /** API base URL - defaults to 'https://app.encatch.com' */
86
+ apiBaseUrl?: string;
87
+ /** When true, displays the form inline at full height without modal overlay */
88
+ isFullScreen?: boolean;
89
+ /**
90
+ * Optional interceptor called before any form is shown (manual or automatic).
91
+ * Receives the form configuration payload. If it returns false (or Promise<false>),
92
+ * the SDK will not display its built-in iframe form; the app can instead render a
93
+ * custom UI and use submitForm / emitEvent / refineText to complete the flow.
94
+ * Pending responses from addToResponse() are cleared when false is returned.
95
+ */
96
+ onBeforeShowForm?: (payload: ShowFormInterceptorPayload) => boolean | Promise<boolean>;
97
+ }
98
+
99
+ /**
100
+ * The Encatch SDK interface
101
+ */
102
+ export declare interface EncatchSDK {
103
+ /**
104
+ * Initialize the SDK with an API key
105
+ * This triggers the loading of the remote implementation script
106
+ * @param apiKey - Your Encatch API key
107
+ * @param config - Optional configuration options
108
+ */
109
+ init(apiKey: string, config?: EncatchConfig): void;
110
+ /**
111
+ * Identify the current user
112
+ * @param userName - User name or unique identifier (e.g. username, email) (required)
113
+ * @param traits - Optional user traits with nested operations ($set, $setOnce, $increment, $decrement, $unset)
114
+ * @param options - Optional settings like locale, country, and secure signature
115
+ */
116
+ identifyUser(userName: string, traits?: UserTraits, options?: IdentifyOptions): void;
117
+ /**
118
+ * Set the user's preferred locale
119
+ * @param locale - Comma-separated ISO 639-1 language codes (e.g., 'fr,en,es')
120
+ */
121
+ setLocale(locale: string): void;
122
+ /**
123
+ * Set the user's country
124
+ * @param country - ISO 3166 country code (e.g., 'US', 'FR')
125
+ */
126
+ setCountry(country: string): void;
127
+ /**
128
+ * Set the theme
129
+ * @param theme - Theme value ('light', 'dark', or 'system')
130
+ */
131
+ setTheme(theme: Theme): void;
132
+ /**
133
+ * Track a custom event
134
+ * @param eventName - Name of the event to track
135
+ */
136
+ trackEvent(eventName: string): void;
137
+ /**
138
+ * Track a screen view
139
+ * @param screenName - Name of the screen to track
140
+ */
141
+ trackScreen(screenName: string): void;
142
+ /**
143
+ * Manually start a new session
144
+ * Useful after user login to reset session timing
145
+ * @param options - Optional flags to skip immediate ping and/or immediate trackScreen
146
+ */
147
+ startSession(options?: StartSessionOptions): void;
148
+ /**
149
+ * Temporarily stops the automatic background ping without affecting open forms,
150
+ * URL change listeners, or user identity. Reversed by resumeSession().
151
+ * Not persisted — clears automatically on page reload.
152
+ */
153
+ pauseSession(): void;
154
+ /**
155
+ * Restarts the background ping interval after a pauseSession() call.
156
+ * No-op if the session was not paused.
157
+ */
158
+ resumeSession(): void;
159
+ /**
160
+ * Fully suspends all SDK activity — stops the ping interval, URL change
161
+ * tracking, and closes any open forms. User identity is preserved.
162
+ * Persists across page reloads via localStorage. Re-enable with startSession().
163
+ */
164
+ stopSession(): void;
165
+ /**
166
+ * Reset the current user (logout)
167
+ * Reverts the SDK to anonymous mode
168
+ */
169
+ resetUser(): void;
170
+ /**
171
+ * Show a specific form by ID
172
+ * @param formId - The ID of the form to display
173
+ * @param options - Optional settings for form display behavior
174
+ */
175
+ showForm(formId: string, options?: ShowFormOptions): void;
176
+ /**
177
+ * Dismiss a form and report to the server
178
+ * Closes the iframe if open and calls the dismiss-form endpoint
179
+ * @param formConfigurationId - The form configuration ID to dismiss (required for API call)
180
+ */
181
+ dismissForm(formConfigurationId?: string): void;
182
+ /**
183
+ * Prepopulate a form response.
184
+ * @param questionId - The ID or slug of the question to prepopulate. When a slug
185
+ * is provided the form engine resolves it to the matching question ID automatically.
186
+ * @param value - The value to set
187
+ */
188
+ addToResponse(questionId: string, value: unknown): void;
189
+ /**
190
+ * Manually submit a form to the Encatch API.
191
+ * Use this when onBeforeShowForm returns false and you render a custom UI —
192
+ * call submitForm once the user completes your custom form.
193
+ * @param params - Submission details including formConfigurationId and question responses
194
+ */
195
+ submitForm(params: SubmitFormRequest): void;
196
+ /**
197
+ * Emit a form lifecycle event to all on() subscribers.
198
+ * Use this when onBeforeShowForm returns false to mirror the events that the
199
+ * built-in iframe form would normally fire (e.g. form:show, form:started,
200
+ * form:answered, form:submit, form:complete, form:close).
201
+ * @param eventType - The event type to emit
202
+ * @param payload - Event payload (timestamp is added automatically)
203
+ */
204
+ emitEvent(eventType: EventType, payload: Omit<EventPayload, 'timestamp'>): void;
205
+ /**
206
+ * Request AI text refinement for a long-text answer.
207
+ * Use this when onBeforeShowForm returns false and your custom UI includes
208
+ * an AI-enhance feature.
209
+ * @param params - The question ID, form configuration ID, and user text to refine
210
+ * @returns Promise resolving to the refined text response
211
+ */
212
+ refineText(params: RefineTextRequest): Promise<RefineTextResponse>;
213
+ /**
214
+ * Call the Q&A with AI endpoint for a qna_with_ai question.
215
+ * Sends the full conversation history (including the current unanswered turn) and
216
+ * returns the AI-generated answer.
217
+ * @param params - feedbackConfigurationId, questionId, and full conversation array
218
+ * @returns Promise resolving to { answer: string }
219
+ */
220
+ qnaWithAi(params: QnaWithAiRequest): Promise<QnaWithAiResponse>;
221
+ /**
222
+ * Streaming variant of qnaWithAi.
223
+ * Calls onChunk for each partial delta as the AI generates the answer,
224
+ * and onDone with the final authoritative answer when complete.
225
+ * @param params - feedbackConfigurationId, questionId, and full conversation array
226
+ * @param callbacks.onChunk - Called for each partial text delta
227
+ * @param callbacks.onDone - Called once with the complete final answer
228
+ * @returns Promise that resolves when the stream is complete
229
+ */
230
+ streamQnaWithAi(params: QnaWithAiRequest, callbacks: {
231
+ onChunk: (delta: string) => void;
232
+ onDone: (answer: string) => void;
233
+ }): Promise<void>;
234
+ /**
235
+ * Upload a file to the Encatch file storage.
236
+ * Use this when onBeforeShowForm returns false and your custom UI contains a
237
+ * file, image, signature, or media question — call uploadFile for each selected
238
+ * file and store the returned fileUrl in your answer payload.
239
+ * @param params - feedbackConfigurationId, questionId, file, optional fileName and onProgress
240
+ * @returns Promise resolving to { fileUrl: string }
241
+ */
242
+ uploadFile(params: UploadFileRequest): Promise<UploadFileResponse>;
243
+ /**
244
+ * Subscribe to all form events
245
+ * The callback receives all form events (show, submit, close, complete, error)
246
+ * @param callback - Function to call when any form event occurs
247
+ * @returns Unsubscribe function
248
+ */
249
+ on(callback: EventCallback): () => void;
250
+ /**
251
+ * Clear all SDK state and stored data, reverting to a brand-new visitor state.
252
+ * Stops the ping interval and URL change listeners, clears all localStorage and
253
+ * IndexedDB data written by the SDK, and resets all in-memory identity state.
254
+ * showForm() and submitForm() continue to work after this call (with NIL UUIDs),
255
+ * but no tracking fires until startSession() or identifyUser() is called again.
256
+ * Use this to implement a "forget me" / consent withdrawal flow.
257
+ */
258
+ clearAll(): void;
259
+ /**
260
+ * Merge additional source tracking key-value pairs into the SDK's in-memory
261
+ * source tracking store. These values are combined with auto-parsed URL params
262
+ * whenever showForm() is called. Values set here take precedence over URL params
263
+ * on key collision. Persists in memory for the lifetime of the page session.
264
+ * Supported on the web SDK only.
265
+ * @param values - Key-value pairs to merge into the source tracking store
266
+ */
267
+ addSourceTracking(values: Record<string, string>): void;
268
+ /** Internal: Command queue for calls made before script loads */
269
+ _q: Command[];
270
+ /** Internal: Event callbacks */
271
+ _eventCallbacks: EventCallback[];
272
+ /** Internal: Whether the SDK has been initialized */
273
+ _initialized: boolean;
274
+ /** Internal: The API key */
275
+ _apiKey: string | null;
276
+ /** Internal: Configuration */
277
+ _config: EncatchConfig;
278
+ }
279
+
280
+ /**
281
+ * Event callback function type
282
+ * Receives all form events with the event type and payload
283
+ */
284
+ export declare type EventCallback = (eventType: EventType, payload: EventPayload) => void;
285
+
286
+ /**
287
+ * Event payload structure
288
+ */
289
+ export declare interface EventPayload {
290
+ /** The form ID related to the event */
291
+ formId?: string;
292
+ /** Timestamp of the event */
293
+ timestamp: number;
294
+ /** Additional event-specific data */
295
+ data?: Record<string, unknown>;
296
+ }
297
+
298
+ /**
299
+ * Event types that can be subscribed to
300
+ */
301
+ export declare type EventType = 'form:show' | 'form:started' | 'form:submit'
302
+ /**
303
+ * For `exit_form` with `autoTriggerDelayMs`, the SDK may close the form on this event
304
+ * and fire `form:ctaTriggered` after the delay from the parent window (not the iframe).
305
+ * Host apps do not schedule timers this is SDK-internal.
306
+ */
307
+ | 'form:complete' | 'form:close' | 'form:dismissed' | 'form:error' | 'form:section:change' | 'form:answered' | 'form:remindmelater'
308
+ /**
309
+ * Fired when a completionCta action fires on a thank_you or exit_form screen.
310
+ * payload.data: { action, route?, url?, surface, trigger }
311
+ *
312
+ * - action "app_navigate": host navigates to data.route in _encatch.on(); the SDK
313
+ * closes the form iframe automatically after emitting this event.
314
+ * - action "redirect_internal": the SDK navigates the parent page to data.url (same tab);
315
+ * the form is already closing.
316
+ * - action "redirect_external": the SDK opens data.url in a new tab; the form is already closing.
317
+ */
318
+ | 'form:ctaTriggered';
319
+
320
+ /** Answer for a file upload question; array supports single and multiple uploads. */
321
+ declare type FileUploadAnswer = FileUploadAnswerItem[];
322
+
323
+ /** Metadata for a single uploaded file. */
324
+ declare interface FileUploadAnswerItem {
325
+ fileUrl: string;
326
+ fileName: string;
327
+ fileSizeMb: number;
328
+ mimeType?: string;
329
+ }
330
+
331
+ /** Form details for an SDK-style submit-form request. */
332
+ export declare interface FormDetails {
333
+ formConfigurationId: string;
334
+ feedbackIdentifier?: string;
335
+ responseLanguageCode?: string;
336
+ isPartialSubmit?: boolean;
337
+ completionTimeInSeconds?: number;
338
+ response?: FormDetailsResponse;
339
+ visitedQuestionIds?: string[];
340
+ context?: Record<string, string | number | boolean>;
341
+ }
342
+
343
+ /** User responses nested inside an SDK-style submit-form request. */
344
+ declare interface FormDetailsResponse {
345
+ questions?: QuestionResponse[];
346
+ context?: Record<string, unknown>;
347
+ contact?: Record<string, unknown>;
348
+ sourceTrackingFieldValues?: Record<string, string>;
349
+ }
350
+
351
+ /**
352
+ * Options for the identifyUser method
353
+ */
354
+ export declare interface IdentifyOptions {
355
+ /** User's preferred locale (ISO 639-1 codes, comma-separated) */
356
+ locale?: string;
357
+ /** User's country (ISO 3166 country code) */
358
+ country?: string;
359
+ /** Secure identification options with signature */
360
+ secure?: SecureOptions;
361
+ }
362
+
363
+ /** Answer for a payments_upi question; self-reported UPI transaction reference. */
364
+ declare interface PaymentsUpiAnswer {
365
+ transactionId: string;
366
+ encatchPaymentReference: string;
367
+ amount: string;
368
+ currency: "INR";
369
+ payeeVpa: string;
370
+ payeeName?: string;
371
+ sourceEmail?: string;
372
+ upiIntentUri?: string;
373
+ selfReported: true;
374
+ }
375
+
376
+ /** Answer for a phone number question. */
377
+ declare interface PhoneNumberAnswer {
378
+ countryCode: string;
379
+ number: string;
380
+ e164?: string;
381
+ }
382
+
383
+ /** Answer for a qna_with_ai question; ordered transcript of Q&A pairs. */
384
+ declare type QnaWithAiAnswer = QnaWithAiPair[];
385
+
386
+ /**
387
+ * A single turn in a Q&A with AI conversation
388
+ */
389
+ export declare interface QnaWithAiConversationTurn {
390
+ /** The question asked by the respondent */
391
+ question: string;
392
+ /** The AI's answer; empty string for the current unanswered turn */
393
+ answer: string;
394
+ }
395
+
396
+ /** A single Q&A exchange between the respondent and the AI. */
397
+ declare interface QnaWithAiPair {
398
+ question: string;
399
+ answer: string;
400
+ }
401
+
402
+ /**
403
+ * Parameters for the qnaWithAi endpoint
404
+ */
405
+ export declare interface QnaWithAiRequest {
406
+ feedbackConfigurationId: string;
407
+ questionId: string;
408
+ /** Full conversation including the current unanswered turn as the last entry */
409
+ conversation: QnaWithAiConversationTurn[];
410
+ }
411
+
412
+ /**
413
+ * Response from the qnaWithAi endpoint
414
+ */
415
+ export declare interface QnaWithAiResponse {
416
+ answer: string;
417
+ }
418
+
419
+ /** All supported question answer shapes. */
420
+ export declare type QuestionAnswer = AnswerItem;
421
+
422
+ /** Response to a specific question in the feedback form. */
423
+ export declare interface QuestionResponse {
424
+ questionId: string;
425
+ /**
426
+ * The answer provided for this question; null for display-only types
427
+ * (thank_you, welcome, exit_form) or unanswered questions on the path.
428
+ */
429
+ answer?: QuestionAnswer | null;
430
+ type?: string;
431
+ error?: string;
432
+ isOnPath?: boolean;
433
+ timeSpentMs?: number;
434
+ isPathTraversed?: boolean;
435
+ }
436
+
437
+ /**
438
+ * Parameters for the refineText AI enhancement endpoint
439
+ */
440
+ export declare interface RefineTextRequest {
441
+ questionId: string;
442
+ feedbackConfigurationId: string;
443
+ userText: string;
444
+ }
445
+
446
+ /**
447
+ * Response from the refineText endpoint
448
+ */
449
+ export declare interface RefineTextResponse {
450
+ message?: string;
451
+ refinedText?: string;
452
+ status?: number;
453
+ error?: string;
454
+ code?: string;
455
+ }
456
+
457
+ /**
458
+ * Reset mode for form data when showing a form
459
+ * - 'always': Clear form data every time showForm is called (default)
460
+ * - 'on-complete': Clear form data only if form was previously completed
461
+ * - 'never': Never clear form data (preserve user's previous answers)
462
+ */
463
+ export declare type ResetMode = 'always' | 'on-complete' | 'never';
464
+
465
+ /** Answer for a scheduler question; shape depends on the calendar provider. */
466
+ declare type SchedulerAnswer = {
467
+ provider: "google_calendar";
468
+ bookedAt: string;
469
+ } | {
470
+ provider: "calendly";
471
+ slotStart: string;
472
+ slotEnd: string;
473
+ eventId?: string;
474
+ bookedAt: string;
475
+ };
476
+
477
+ /**
478
+ * Secure options for user identification
479
+ */
480
+ declare interface SecureOptions {
481
+ /** User signature (required when secure is set) */
482
+ signature: string;
483
+ /** Optional datetime in UTC when the signature was generated */
484
+ generatedDateTimeinUTC?: string;
485
+ }
486
+
487
+ /**
488
+ * Payload passed to the onBeforeShowForm interceptor.
489
+ * Contains the full form configuration returned by the server along with
490
+ * context values the SDK resolved at call time.
491
+ */
492
+ export declare interface ShowFormInterceptorPayload {
493
+ /** The form slug or ID that was requested */
494
+ formId: string;
495
+ /** Raw form configuration returned by the show-form API */
496
+ formConfig: Record<string, unknown>;
497
+ /** Reset mode in effect for this show call */
498
+ resetMode: ResetMode;
499
+ /** Whether the form was triggered automatically (server-side) or manually (developer call) */
500
+ triggerType: 'automatic' | 'manual';
501
+ /** Pre-filled responses staged via addToResponse() */
502
+ prefillResponses: Record<string, unknown>;
503
+ /** Active locale, if set */
504
+ locale?: string;
505
+ /** Active theme */
506
+ theme?: Theme;
507
+ /** Serialized context values (Dates already converted to ISO strings) */
508
+ context?: Record<string, string | number | boolean>;
509
+ }
510
+
511
+ /**
512
+ * Options for the showForm method
513
+ */
514
+ export declare interface ShowFormOptions {
515
+ /**
516
+ * Controls when form data should be cleared
517
+ * @default 'always'
518
+ */
519
+ reset?: ResetMode;
520
+ /**
521
+ * Arbitrary key-value pairs attached to the form submission.
522
+ * Useful for passing caller-side metadata (e.g. plan tier, feature flag states).
523
+ * Date values are automatically serialized to ISO 8601 strings.
524
+ */
525
+ context?: Record<string, ContextValue>;
526
+ /**
527
+ * CSS selector for a host element to render the form inline into (highest-priority
528
+ * placement). If the selector matches an element, the form mounts there; if it
529
+ * doesn't match (or is invalid), placement falls back to the `#encatch` rules
530
+ * (a `<div id="encatch">`, optionally bound to a form via `data-encatch-form-id`)
531
+ * and then to the default modal. Example: `showForm('id', { selector: '#feedback-slot' })`.
532
+ */
533
+ selector?: string;
534
+ }
535
+
536
+ /** Answer for a signature question. */
537
+ declare interface SignatureAnswer {
538
+ mode: "type" | "draw" | "upload";
539
+ fileUrl?: string;
540
+ typedName?: string;
541
+ }
542
+
543
+ /**
544
+ * Options for the startSession method
545
+ */
546
+ export declare interface StartSessionOptions {
547
+ /** When true, do not call the immediate ping (30s ping interval still runs) */
548
+ skipImmediatePing?: boolean;
549
+ /**
550
+ * When true, do not send the initial trackScreen for the current URL
551
+ * (URL change listeners still run). Defaults to true.
552
+ */
553
+ skipImmediateTrackScreen?: boolean;
554
+ }
555
+
556
+ /** Complete submit-form request envelope (SDK-facing contract). */
557
+ export declare interface SubmitFormRequest {
558
+ triggerType?: "automatic" | "manual";
559
+ formDetails: FormDetails;
560
+ $deviceInfo?: Record<string, unknown>;
561
+ }
562
+
563
+ /**
564
+ * Theme options
565
+ */
566
+ export declare type Theme = 'light' | 'dark' | 'system';
567
+
568
+ /**
569
+ * Parameters for the uploadFile method
570
+ */
571
+ export declare interface UploadFileRequest {
572
+ /** The form's server-issued configuration ID */
573
+ feedbackConfigurationId: string;
574
+ /** The question ID the file belongs to */
575
+ questionId: string;
576
+ /** The file or blob to upload */
577
+ file: File | Blob;
578
+ /**
579
+ * File name to send to the server (e.g. "signature.png").
580
+ * Defaults to "upload" when omitted.
581
+ */
582
+ fileName?: string;
583
+ /**
584
+ * Optional progress callback — receives upload percentage (0–100).
585
+ * Useful for driving a progress bar in custom UIs.
586
+ */
587
+ onProgress?: (percent: number) => void;
588
+ }
589
+
590
+ /**
591
+ * Response from the uploadFile endpoint
592
+ */
593
+ export declare interface UploadFileResponse {
594
+ /** Permanent URL of the uploaded file */
595
+ fileUrl: string;
596
+ }
597
+
598
+ /**
599
+ * User traits for identifying users
600
+ * Supports nested operations: $set, $setOnce, $increment, $decrement, $unset
601
+ */
602
+ export declare interface UserTraits {
603
+ /** Set user attributes (overwrites existing values) */
604
+ $set?: Record<string, any>;
605
+ /** Set user attributes only if they don't already exist */
606
+ $setOnce?: Record<string, any>;
607
+ /** Increment numeric user attributes */
608
+ $increment?: Record<string, number>;
609
+ /** Decrement numeric user attributes */
610
+ $decrement?: Record<string, number>;
611
+ /** Remove user attributes */
612
+ $unset?: string[];
613
+ }
614
+
615
+ /** Answer for a video / audio / photo / text question. */
616
+ declare interface VideoAudioAnswer {
617
+ mode: "video" | "audio" | "photo" | "text";
618
+ fileUrl?: string;
619
+ text?: string;
620
+ durationSeconds?: number;
621
+ transcriptText?: string;
622
+ }
623
+
624
+ export { }
625
+
626
+
472
627
  /**
473
628
  * Global window augmentation for TypeScript
474
629
  */
@@ -477,4 +632,3 @@ declare global {
477
632
  _encatch: EncatchSDK;
478
633
  }
479
634
  }
480
- //# sourceMappingURL=types.d.ts.map