@encatch/web-sdk 1.2.1-beta.1 → 1.2.1-beta.2

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,463 +1,443 @@
1
- /**
2
- * Internal command tuple type for the queue
3
- */
4
- declare type Command = [string, ...unknown[]];
5
-
6
- /**
7
- * Context values that can be attached to a form submission.
8
- * Date values are automatically serialized to ISO strings before being sent.
9
- */
10
- declare type ContextValue = string | number | Date | boolean;
11
-
12
- declare const _encatch: EncatchSDK;
13
- export { _encatch }
14
- export default _encatch;
15
-
16
- /**
17
- * Configuration options for the SDK
18
- */
19
- export declare interface EncatchConfig {
20
- /** Override the default web host for loading the SDK script */
21
- webHost?: string;
22
- /** Theme setting - defaults to 'system' */
23
- theme?: Theme;
24
- /** API base URL - defaults to 'https://app.encatch.com' */
25
- apiBaseUrl?: string;
26
- /** When true, displays the form inline at full height without modal overlay */
27
- isFullScreen?: boolean;
28
- /**
29
- * Optional interceptor called before any form is shown (manual or automatic).
30
- * Receives the form configuration payload. If it returns false (or Promise<false>),
31
- * the SDK will not display its built-in iframe form; the app can instead render a
32
- * custom UI and use submitForm / emitEvent / refineText to complete the flow.
33
- * Pending responses from addToResponse() are cleared when false is returned.
34
- */
35
- onBeforeShowForm?: (payload: ShowFormInterceptorPayload) => boolean | Promise<boolean>;
36
- }
37
-
38
- /**
39
- * The Encatch SDK interface
40
- */
41
- export declare interface EncatchSDK {
42
- /**
43
- * Initialize the SDK with an API key
44
- * This triggers the loading of the remote implementation script
45
- * @param apiKey - Your Encatch API key
46
- * @param config - Optional configuration options
47
- */
48
- init(apiKey: string, config?: EncatchConfig): void;
49
- /**
50
- * Identify the current user
51
- * @param userName - User name or unique identifier (e.g. username, email) (required)
52
- * @param traits - Optional user traits with nested operations ($set, $setOnce, $increment, $decrement, $unset)
53
- * @param options - Optional settings like locale, country, and secure signature
54
- */
55
- identifyUser(userName: string, traits?: UserTraits, options?: IdentifyOptions): void;
56
- /**
57
- * Set the user's preferred locale
58
- * @param locale - Comma-separated ISO 639-1 language codes (e.g., 'fr,en,es')
59
- */
60
- setLocale(locale: string): void;
61
- /**
62
- * Set the user's country
63
- * @param country - ISO 3166 country code (e.g., 'US', 'FR')
64
- */
65
- setCountry(country: string): void;
66
- /**
67
- * Set the theme
68
- * @param theme - Theme value ('light', 'dark', or 'system')
69
- */
70
- setTheme(theme: Theme): void;
71
- /**
72
- * Track a custom event
73
- * @param eventName - Name of the event to track
74
- */
75
- trackEvent(eventName: string): void;
76
- /**
77
- * Track a screen view
78
- * @param screenName - Name of the screen to track
79
- */
80
- trackScreen(screenName: string): void;
81
- /**
82
- * Manually start a new session
83
- * Useful after user login to reset session timing
84
- * @param options - Optional flags to skip immediate ping and/or immediate trackScreen
85
- */
86
- startSession(options?: StartSessionOptions): void;
87
- /**
88
- * Reset the current user (logout)
89
- * Reverts the SDK to anonymous mode
90
- */
91
- resetUser(): void;
92
- /**
93
- * Show a specific form by ID
94
- * @param formId - The ID of the form to display
95
- * @param options - Optional settings for form display behavior
96
- */
97
- showForm(formId: string, options?: ShowFormOptions): void;
98
- /**
99
- * Dismiss a form and report to the server
100
- * Closes the iframe if open and calls the dismiss-form endpoint
101
- * @param formConfigurationId - The form configuration ID to dismiss (required for API call)
102
- */
103
- dismissForm(formConfigurationId?: string): void;
104
- /**
105
- * Prepopulate a form response.
106
- * @param questionId - The ID or slug of the question to prepopulate. When a slug
107
- * is provided the form engine resolves it to the matching question ID automatically.
108
- * @param value - The value to set
109
- */
110
- addToResponse(questionId: string, value: unknown): void;
111
- /**
112
- * Manually submit a form to the Encatch API.
113
- * Use this when onBeforeShowForm returns false and you render a custom UI —
114
- * call submitForm once the user completes your custom form.
115
- * @param params - Submission details including formConfigurationId and question responses
116
- */
117
- submitForm(params: SubmitFormRequest): void;
118
- /**
119
- * Emit a form lifecycle event to all on() subscribers.
120
- * Use this when onBeforeShowForm returns false to mirror the events that the
121
- * built-in iframe form would normally fire (e.g. form:show, form:started,
122
- * form:answered, form:submit, form:complete, form:close).
123
- * @param eventType - The event type to emit
124
- * @param payload - Event payload (timestamp is added automatically)
125
- */
126
- emitEvent(eventType: EventType, payload: Omit<EventPayload, 'timestamp'>): void;
127
- /**
128
- * Request AI text refinement for a long-text answer.
129
- * Use this when onBeforeShowForm returns false and your custom UI includes
130
- * an AI-enhance feature.
131
- * @param params - The question ID, form configuration ID, and user text to refine
132
- * @returns Promise resolving to the refined text response
133
- */
134
- refineText(params: RefineTextRequest): Promise<RefineTextResponse>;
135
- /**
136
- * Call the Q&A with AI endpoint for a qna_with_ai question.
137
- * Sends the full conversation history (including the current unanswered turn) and
138
- * returns the AI-generated answer.
139
- * @param params - feedbackConfigurationId, questionId, and full conversation array
140
- * @returns Promise resolving to { answer: string }
141
- */
142
- qnaWithAi(params: QnaWithAiRequest): Promise<QnaWithAiResponse>;
143
- /**
144
- * Streaming variant of qnaWithAi.
145
- * Calls onChunk for each partial delta as the AI generates the answer,
146
- * and onDone with the final authoritative answer when complete.
147
- * @param params - feedbackConfigurationId, questionId, and full conversation array
148
- * @param callbacks.onChunk - Called for each partial text delta
149
- * @param callbacks.onDone - Called once with the complete final answer
150
- * @returns Promise that resolves when the stream is complete
151
- */
152
- streamQnaWithAi(params: QnaWithAiRequest, callbacks: {
153
- onChunk: (delta: string) => void;
154
- onDone: (answer: string) => void;
155
- }): Promise<void>;
156
- /**
157
- * Upload a file to the Encatch file storage.
158
- * Use this when onBeforeShowForm returns false and your custom UI contains a
159
- * file, image, signature, or media question — call uploadFile for each selected
160
- * file and store the returned fileUrl in your answer payload.
161
- * @param params - feedbackConfigurationId, questionId, file, optional fileName and onProgress
162
- * @returns Promise resolving to { fileUrl: string }
163
- */
164
- uploadFile(params: UploadFileRequest): Promise<UploadFileResponse>;
165
- /**
166
- * Subscribe to all form events
167
- * The callback receives all form events (show, submit, close, complete, error)
168
- * @param callback - Function to call when any form event occurs
169
- * @returns Unsubscribe function
170
- */
171
- on(callback: EventCallback): () => void;
172
- /**
173
- * Clear all SDK state and stored data, reverting to a brand-new visitor state.
174
- * Stops the ping interval and URL change listeners, clears all localStorage and
175
- * IndexedDB data written by the SDK, and resets all in-memory identity state.
176
- * showForm() and submitForm() continue to work after this call (with NIL UUIDs),
177
- * but no tracking fires until startSession() or identifyUser() is called again.
178
- * Use this to implement a "forget me" / consent withdrawal flow.
179
- */
180
- clearAll(): void;
181
- /**
182
- * Merge additional source tracking key-value pairs into the SDK's in-memory
183
- * source tracking store. These values are combined with auto-parsed URL params
184
- * whenever showForm() is called. Values set here take precedence over URL params
185
- * on key collision. Persists in memory for the lifetime of the page session.
186
- * Supported on the web SDK only.
187
- * @param values - Key-value pairs to merge into the source tracking store
188
- */
189
- addSourceTracking(values: Record<string, string>): void;
190
- /** Internal: Command queue for calls made before script loads */
191
- _q: Command[];
192
- /** Internal: Event callbacks */
193
- _eventCallbacks: EventCallback[];
194
- /** Internal: Whether the SDK has been initialized */
195
- _initialized: boolean;
196
- /** Internal: The API key */
197
- _apiKey: string | null;
198
- /** Internal: Configuration */
199
- _config: EncatchConfig;
200
- }
201
-
202
- /**
203
- * Event callback function type
204
- * Receives all form events with the event type and payload
205
- */
206
- export declare type EventCallback = (eventType: EventType, payload: EventPayload) => void;
207
-
208
- /**
209
- * Event payload structure
210
- */
211
- export declare interface EventPayload {
212
- /** The form ID related to the event */
213
- formId?: string;
214
- /** Timestamp of the event */
215
- timestamp: number;
216
- /** Additional event-specific data */
217
- data?: Record<string, unknown>;
218
- }
219
-
220
- /**
221
- * Event types that can be subscribed to
222
- */
223
- export declare type EventType = 'form:show' | 'form:started' | 'form:submit' | 'form:complete' | 'form:close' | 'form:dismissed' | 'form:error' | 'form:section:change' | 'form:answered';
224
-
225
- /**
226
- * Form details for a manual form submission
227
- */
228
- export declare interface FormDetails {
229
- /** The server-issued configuration ID for this form */
230
- formConfigurationId: string;
231
- /** When true, marks this as a partial (mid-journey) submission */
232
- isPartialSubmit?: boolean;
233
- feedbackIdentifier?: string;
234
- responseLanguageCode?: string;
235
- response?: {
236
- questions?: QuestionResponse[];
237
- };
238
- completionTimeInSeconds?: number;
239
- /** Caller-provided metadata attached to this submission (Dates already serialized to ISO strings) */
240
- context?: Record<string, string | number | boolean>;
241
- /** IDs of questions the user actually visited, in order */
242
- visitedQuestionIds?: string[];
243
- }
244
-
245
- /**
246
- * Options for the identifyUser method
247
- */
248
- export declare interface IdentifyOptions {
249
- /** User's preferred locale (ISO 639-1 codes, comma-separated) */
250
- locale?: string;
251
- /** User's country (ISO 3166 country code) */
252
- country?: string;
253
- /** Secure identification options with signature */
254
- secure?: SecureOptions;
255
- }
256
-
257
- /**
258
- * A single turn in a Q&A with AI conversation
259
- */
260
- export declare interface QnaWithAiConversationTurn {
261
- /** The question asked by the respondent */
262
- question: string;
263
- /** The AI's answer; empty string for the current unanswered turn */
264
- answer: string;
265
- }
266
-
267
- /**
268
- * Parameters for the qnaWithAi endpoint
269
- */
270
- export declare interface QnaWithAiRequest {
271
- feedbackConfigurationId: string;
272
- questionId: string;
273
- /** Full conversation including the current unanswered turn as the last entry */
274
- conversation: QnaWithAiConversationTurn[];
275
- }
276
-
277
- /**
278
- * Response from the qnaWithAi endpoint
279
- */
280
- export declare interface QnaWithAiResponse {
281
- answer: string;
282
- }
283
-
284
- /**
285
- * An individual question answer within a form submission
286
- */
287
- export declare interface QuestionAnswer {
288
- nps?: number;
289
- csat?: number;
290
- starRating?: number;
291
- singleChoice?: string;
292
- singleChoiceOther?: string;
293
- multipleChoiceMultiple?: string[];
294
- multipleChoiceMultipleOther?: string;
295
- nestedSelection?: string[];
296
- shortAnswer?: string;
297
- longText?: string;
298
- }
299
-
300
- /**
301
- * A single question response within a form submission
302
- */
303
- export declare interface QuestionResponse {
304
- questionId: string;
305
- type?: string;
306
- answer?: QuestionAnswer;
307
- /** Present on engine-built submits: whether this question was on the respondent's path */
308
- isOnPath?: boolean;
309
- }
310
-
311
- /**
312
- * Parameters for the refineText AI enhancement endpoint
313
- */
314
- export declare interface RefineTextRequest {
315
- questionId: string;
316
- feedbackConfigurationId: string;
317
- userText: string;
318
- }
319
-
320
- /**
321
- * Response from the refineText endpoint
322
- */
323
- export declare interface RefineTextResponse {
324
- message?: string;
325
- refinedText?: string;
326
- status?: number;
327
- error?: string;
328
- code?: string;
329
- }
330
-
331
- /**
332
- * Reset mode for form data when showing a form
333
- * - 'always': Clear form data every time showForm is called (default)
334
- * - 'on-complete': Clear form data only if form was previously completed
335
- * - 'never': Never clear form data (preserve user's previous answers)
336
- */
337
- export declare type ResetMode = 'always' | 'on-complete' | 'never';
338
-
339
- /**
340
- * Secure options for user identification
341
- */
342
- declare interface SecureOptions {
343
- /** User signature (required when secure is set) */
344
- signature: string;
345
- /** Optional datetime in UTC when the signature was generated */
346
- generatedDateTimeinUTC?: string;
347
- }
348
-
349
- /**
350
- * Payload passed to the onBeforeShowForm interceptor.
351
- * Contains the full form configuration returned by the server along with
352
- * context values the SDK resolved at call time.
353
- */
354
- export declare interface ShowFormInterceptorPayload {
355
- /** The form slug or ID that was requested */
356
- formId: string;
357
- /** Raw form configuration returned by the show-form API */
358
- formConfig: Record<string, unknown>;
359
- /** Reset mode in effect for this show call */
360
- resetMode: ResetMode;
361
- /** Whether the form was triggered automatically (server-side) or manually (developer call) */
362
- triggerType: 'automatic' | 'manual';
363
- /** Pre-filled responses staged via addToResponse() */
364
- prefillResponses: Record<string, unknown>;
365
- /** Active locale, if set */
366
- locale?: string;
367
- /** Active theme */
368
- theme?: Theme;
369
- /** Serialized context values (Dates already converted to ISO strings) */
370
- context?: Record<string, string | number | boolean>;
371
- }
372
-
373
- /**
374
- * Options for the showForm method
375
- */
376
- export declare interface ShowFormOptions {
377
- /**
378
- * Controls when form data should be cleared
379
- * @default 'always'
380
- */
381
- reset?: ResetMode;
382
- /**
383
- * Arbitrary key-value pairs attached to the form submission.
384
- * Useful for passing caller-side metadata (e.g. plan tier, feature flag states).
385
- * Date values are automatically serialized to ISO 8601 strings.
386
- */
387
- context?: Record<string, ContextValue>;
388
- }
389
-
390
- /**
391
- * Options for the startSession method
392
- */
393
- export declare interface StartSessionOptions {
394
- /** When true, do not call the immediate ping (30s ping interval still runs) */
395
- skipImmediatePing?: boolean;
396
- /** When true, do not send the initial trackScreen for the current URL (URL change listeners still run) */
397
- skipImmediateTrackScreen?: boolean;
398
- }
399
-
400
- /**
401
- * Parameters for manually submitting a form (used with onBeforeShowForm interceptor)
402
- */
403
- export declare interface SubmitFormRequest {
404
- triggerType?: 'automatic' | 'manual';
405
- formDetails: FormDetails;
406
- }
407
-
408
- /**
409
- * Theme options
410
- */
411
- export declare type Theme = 'light' | 'dark' | 'system';
412
-
413
- /**
414
- * Parameters for the uploadFile method
415
- */
416
- export declare interface UploadFileRequest {
417
- /** The form's server-issued configuration ID */
418
- feedbackConfigurationId: string;
419
- /** The question ID the file belongs to */
420
- questionId: string;
421
- /** The file or blob to upload */
422
- file: File | Blob;
423
- /**
424
- * File name to send to the server (e.g. "signature.png").
425
- * Defaults to "upload" when omitted.
426
- */
427
- fileName?: string;
428
- /**
429
- * Optional progress callback — receives upload percentage (0–100).
430
- * Useful for driving a progress bar in custom UIs.
431
- */
432
- onProgress?: (percent: number) => void;
433
- }
434
-
435
- /**
436
- * Response from the uploadFile endpoint
437
- */
438
- export declare interface UploadFileResponse {
439
- /** Permanent URL of the uploaded file */
440
- fileUrl: string;
441
- }
442
-
443
- /**
444
- * Encatch Web SDK Type Definitions
445
- */
446
- /**
447
- * User traits for identifying users
448
- * Supports nested operations: $set, $setOnce, $increment, $decrement, $unset
449
- */
450
- export declare interface UserTraits {
451
- /** Set user attributes (overwrites existing values) */
452
- $set?: Record<string, any>;
453
- /** Set user attributes only if they don't already exist */
454
- $setOnce?: Record<string, any>;
455
- /** Increment numeric user attributes */
456
- $increment?: Record<string, number>;
457
- /** Decrement numeric user attributes */
458
- $decrement?: Record<string, number>;
459
- /** Remove user attributes */
460
- $unset?: string[];
461
- }
462
-
463
- export { }
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
+ /** When true, do not send the initial trackScreen for the current URL (URL change listeners still run) */
47
+ skipImmediateTrackScreen?: boolean;
48
+ }
49
+ /**
50
+ * Theme options
51
+ */
52
+ export type Theme = 'light' | 'dark' | 'system';
53
+ /**
54
+ * Configuration options for the SDK
55
+ */
56
+ export interface EncatchConfig {
57
+ /** Override the default web host for loading the SDK script */
58
+ webHost?: string;
59
+ /** Theme setting - defaults to 'system' */
60
+ theme?: Theme;
61
+ /** API base URL - defaults to 'https://app.encatch.com' */
62
+ apiBaseUrl?: string;
63
+ /** When true, displays the form inline at full height without modal overlay */
64
+ isFullScreen?: boolean;
65
+ /**
66
+ * Optional interceptor called before any form is shown (manual or automatic).
67
+ * Receives the form configuration payload. If it returns false (or Promise<false>),
68
+ * the SDK will not display its built-in iframe form; the app can instead render a
69
+ * custom UI and use submitForm / emitEvent / refineText to complete the flow.
70
+ * Pending responses from addToResponse() are cleared when false is returned.
71
+ */
72
+ onBeforeShowForm?: (payload: ShowFormInterceptorPayload) => boolean | Promise<boolean>;
73
+ }
74
+ /**
75
+ * Payload passed to the onBeforeShowForm interceptor.
76
+ * Contains the full form configuration returned by the server along with
77
+ * context values the SDK resolved at call time.
78
+ */
79
+ export interface ShowFormInterceptorPayload {
80
+ /** The form slug or ID that was requested */
81
+ formId: string;
82
+ /** Raw form configuration returned by the show-form API */
83
+ formConfig: Record<string, unknown>;
84
+ /** Reset mode in effect for this show call */
85
+ resetMode: ResetMode;
86
+ /** Whether the form was triggered automatically (server-side) or manually (developer call) */
87
+ triggerType: 'automatic' | 'manual';
88
+ /** Pre-filled responses staged via addToResponse() */
89
+ prefillResponses: Record<string, unknown>;
90
+ /** Active locale, if set */
91
+ locale?: string;
92
+ /** Active theme */
93
+ theme?: Theme;
94
+ /** Serialized context values (Dates already converted to ISO strings) */
95
+ context?: Record<string, string | number | boolean>;
96
+ }
97
+ /**
98
+ * An individual question answer within a form submission
99
+ */
100
+ export interface QuestionAnswer {
101
+ nps?: number;
102
+ csat?: number;
103
+ /** Star-rating / rating scale answer (schema field: `rating`) */
104
+ rating?: number;
105
+ singleChoice?: string;
106
+ singleChoiceOther?: string;
107
+ multipleChoiceMultiple?: string[];
108
+ /** Free-text "Other" answer for multiple-choice-multiple questions (schema field: `multipleChoiceOther`) */
109
+ multipleChoiceOther?: string;
110
+ nestedSelection?: string[];
111
+ shortAnswer?: string;
112
+ longText?: string;
113
+ }
114
+ /**
115
+ * A single question response within a form submission
116
+ */
117
+ export interface QuestionResponse {
118
+ questionId: string;
119
+ type?: string;
120
+ answer?: QuestionAnswer;
121
+ /** Present on engine-built submits: whether this question was on the respondent's path */
122
+ isOnPath?: boolean;
123
+ }
124
+ /**
125
+ * Form details for a manual form submission
126
+ */
127
+ export interface FormDetails {
128
+ /** The server-issued configuration ID for this form */
129
+ formConfigurationId: string;
130
+ /** When true, marks this as a partial (mid-journey) submission */
131
+ isPartialSubmit?: boolean;
132
+ feedbackIdentifier?: string;
133
+ responseLanguageCode?: string;
134
+ response?: {
135
+ questions?: QuestionResponse[];
136
+ };
137
+ completionTimeInSeconds?: number;
138
+ /** Caller-provided metadata attached to this submission (Dates already serialized to ISO strings) */
139
+ context?: Record<string, string | number | boolean>;
140
+ /** IDs of questions the user actually visited, in order */
141
+ visitedQuestionIds?: string[];
142
+ }
143
+ /**
144
+ * Parameters for manually submitting a form (used with onBeforeShowForm interceptor)
145
+ */
146
+ export interface SubmitFormRequest {
147
+ triggerType?: 'automatic' | 'manual';
148
+ formDetails: FormDetails;
149
+ }
150
+ /**
151
+ * Parameters for the refineText AI enhancement endpoint
152
+ */
153
+ export interface RefineTextRequest {
154
+ questionId: string;
155
+ feedbackConfigurationId: string;
156
+ userText: string;
157
+ }
158
+ /**
159
+ * Response from the refineText endpoint
160
+ */
161
+ export interface RefineTextResponse {
162
+ message?: string;
163
+ refinedText?: string;
164
+ status?: number;
165
+ error?: string;
166
+ code?: string;
167
+ }
168
+ /**
169
+ * A single turn in a Q&A with AI conversation
170
+ */
171
+ export interface QnaWithAiConversationTurn {
172
+ /** The question asked by the respondent */
173
+ question: string;
174
+ /** The AI's answer; empty string for the current unanswered turn */
175
+ answer: string;
176
+ }
177
+ /**
178
+ * Parameters for the qnaWithAi endpoint
179
+ */
180
+ export interface QnaWithAiRequest {
181
+ feedbackConfigurationId: string;
182
+ questionId: string;
183
+ /** Full conversation including the current unanswered turn as the last entry */
184
+ conversation: QnaWithAiConversationTurn[];
185
+ }
186
+ /**
187
+ * Response from the qnaWithAi endpoint
188
+ */
189
+ export interface QnaWithAiResponse {
190
+ answer: string;
191
+ }
192
+ /**
193
+ * Parameters for the uploadFile method
194
+ */
195
+ export interface UploadFileRequest {
196
+ /** The form's server-issued configuration ID */
197
+ feedbackConfigurationId: string;
198
+ /** The question ID the file belongs to */
199
+ questionId: string;
200
+ /** The file or blob to upload */
201
+ file: File | Blob;
202
+ /**
203
+ * File name to send to the server (e.g. "signature.png").
204
+ * Defaults to "upload" when omitted.
205
+ */
206
+ fileName?: string;
207
+ /**
208
+ * Optional progress callback — receives upload percentage (0–100).
209
+ * Useful for driving a progress bar in custom UIs.
210
+ */
211
+ onProgress?: (percent: number) => void;
212
+ }
213
+ /**
214
+ * Response from the uploadFile endpoint
215
+ */
216
+ export interface UploadFileResponse {
217
+ /** Permanent URL of the uploaded file */
218
+ fileUrl: string;
219
+ }
220
+ /**
221
+ * Reset mode for form data when showing a form
222
+ * - 'always': Clear form data every time showForm is called (default)
223
+ * - 'on-complete': Clear form data only if form was previously completed
224
+ * - 'never': Never clear form data (preserve user's previous answers)
225
+ */
226
+ export type ResetMode = 'always' | 'on-complete' | 'never';
227
+ /**
228
+ * Context values that can be attached to a form submission.
229
+ * Date values are automatically serialized to ISO strings before being sent.
230
+ */
231
+ export type ContextValue = string | number | Date | boolean;
232
+ /**
233
+ * Options for the showForm method
234
+ */
235
+ export interface ShowFormOptions {
236
+ /**
237
+ * Controls when form data should be cleared
238
+ * @default 'always'
239
+ */
240
+ reset?: ResetMode;
241
+ /**
242
+ * Arbitrary key-value pairs attached to the form submission.
243
+ * Useful for passing caller-side metadata (e.g. plan tier, feature flag states).
244
+ * Date values are automatically serialized to ISO 8601 strings.
245
+ */
246
+ context?: Record<string, ContextValue>;
247
+ }
248
+ /**
249
+ * Event types that can be subscribed to
250
+ */
251
+ export type EventType = 'form:show' | 'form:started' | 'form:submit' | 'form:complete' | 'form:close' | 'form:dismissed' | 'form:error' | 'form:section:change' | 'form:answered';
252
+ /**
253
+ * Event callback function type
254
+ * Receives all form events with the event type and payload
255
+ */
256
+ export type EventCallback = (eventType: EventType, payload: EventPayload) => void;
257
+ /**
258
+ * Event payload structure
259
+ */
260
+ export interface EventPayload {
261
+ /** The form ID related to the event */
262
+ formId?: string;
263
+ /** Timestamp of the event */
264
+ timestamp: number;
265
+ /** Additional event-specific data */
266
+ data?: Record<string, unknown>;
267
+ }
268
+ /**
269
+ * Internal command tuple type for the queue
270
+ */
271
+ export type Command = [string, ...unknown[]];
272
+ /**
273
+ * The Encatch SDK interface
274
+ */
275
+ export interface EncatchSDK {
276
+ /**
277
+ * Initialize the SDK with an API key
278
+ * This triggers the loading of the remote implementation script
279
+ * @param apiKey - Your Encatch API key
280
+ * @param config - Optional configuration options
281
+ */
282
+ init(apiKey: string, config?: EncatchConfig): void;
283
+ /**
284
+ * Identify the current user
285
+ * @param userName - User name or unique identifier (e.g. username, email) (required)
286
+ * @param traits - Optional user traits with nested operations ($set, $setOnce, $increment, $decrement, $unset)
287
+ * @param options - Optional settings like locale, country, and secure signature
288
+ */
289
+ identifyUser(userName: string, traits?: UserTraits, options?: IdentifyOptions): void;
290
+ /**
291
+ * Set the user's preferred locale
292
+ * @param locale - Comma-separated ISO 639-1 language codes (e.g., 'fr,en,es')
293
+ */
294
+ setLocale(locale: string): void;
295
+ /**
296
+ * Set the user's country
297
+ * @param country - ISO 3166 country code (e.g., 'US', 'FR')
298
+ */
299
+ setCountry(country: string): void;
300
+ /**
301
+ * Set the theme
302
+ * @param theme - Theme value ('light', 'dark', or 'system')
303
+ */
304
+ setTheme(theme: Theme): void;
305
+ /**
306
+ * Track a custom event
307
+ * @param eventName - Name of the event to track
308
+ */
309
+ trackEvent(eventName: string): void;
310
+ /**
311
+ * Track a screen view
312
+ * @param screenName - Name of the screen to track
313
+ */
314
+ trackScreen(screenName: string): void;
315
+ /**
316
+ * Manually start a new session
317
+ * Useful after user login to reset session timing
318
+ * @param options - Optional flags to skip immediate ping and/or immediate trackScreen
319
+ */
320
+ startSession(options?: StartSessionOptions): void;
321
+ /**
322
+ * Reset the current user (logout)
323
+ * Reverts the SDK to anonymous mode
324
+ */
325
+ resetUser(): void;
326
+ /**
327
+ * Show a specific form by ID
328
+ * @param formId - The ID of the form to display
329
+ * @param options - Optional settings for form display behavior
330
+ */
331
+ showForm(formId: string, options?: ShowFormOptions): void;
332
+ /**
333
+ * Dismiss a form and report to the server
334
+ * Closes the iframe if open and calls the dismiss-form endpoint
335
+ * @param formConfigurationId - The form configuration ID to dismiss (required for API call)
336
+ */
337
+ dismissForm(formConfigurationId?: string): void;
338
+ /**
339
+ * Prepopulate a form response.
340
+ * @param questionId - The ID or slug of the question to prepopulate. When a slug
341
+ * is provided the form engine resolves it to the matching question ID automatically.
342
+ * @param value - The value to set
343
+ */
344
+ addToResponse(questionId: string, value: unknown): void;
345
+ /**
346
+ * Manually submit a form to the Encatch API.
347
+ * Use this when onBeforeShowForm returns false and you render a custom UI —
348
+ * call submitForm once the user completes your custom form.
349
+ * @param params - Submission details including formConfigurationId and question responses
350
+ */
351
+ submitForm(params: SubmitFormRequest): void;
352
+ /**
353
+ * Emit a form lifecycle event to all on() subscribers.
354
+ * Use this when onBeforeShowForm returns false to mirror the events that the
355
+ * built-in iframe form would normally fire (e.g. form:show, form:started,
356
+ * form:answered, form:submit, form:complete, form:close).
357
+ * @param eventType - The event type to emit
358
+ * @param payload - Event payload (timestamp is added automatically)
359
+ */
360
+ emitEvent(eventType: EventType, payload: Omit<EventPayload, 'timestamp'>): void;
361
+ /**
362
+ * Request AI text refinement for a long-text answer.
363
+ * Use this when onBeforeShowForm returns false and your custom UI includes
364
+ * an AI-enhance feature.
365
+ * @param params - The question ID, form configuration ID, and user text to refine
366
+ * @returns Promise resolving to the refined text response
367
+ */
368
+ refineText(params: RefineTextRequest): Promise<RefineTextResponse>;
369
+ /**
370
+ * Call the Q&A with AI endpoint for a qna_with_ai question.
371
+ * Sends the full conversation history (including the current unanswered turn) and
372
+ * returns the AI-generated answer.
373
+ * @param params - feedbackConfigurationId, questionId, and full conversation array
374
+ * @returns Promise resolving to { answer: string }
375
+ */
376
+ qnaWithAi(params: QnaWithAiRequest): Promise<QnaWithAiResponse>;
377
+ /**
378
+ * Streaming variant of qnaWithAi.
379
+ * Calls onChunk for each partial delta as the AI generates the answer,
380
+ * and onDone with the final authoritative answer when complete.
381
+ * @param params - feedbackConfigurationId, questionId, and full conversation array
382
+ * @param callbacks.onChunk - Called for each partial text delta
383
+ * @param callbacks.onDone - Called once with the complete final answer
384
+ * @returns Promise that resolves when the stream is complete
385
+ */
386
+ streamQnaWithAi(params: QnaWithAiRequest, callbacks: {
387
+ onChunk: (delta: string) => void;
388
+ onDone: (answer: string) => void;
389
+ }): Promise<void>;
390
+ /**
391
+ * Upload a file to the Encatch file storage.
392
+ * Use this when onBeforeShowForm returns false and your custom UI contains a
393
+ * file, image, signature, or media question — call uploadFile for each selected
394
+ * file and store the returned fileUrl in your answer payload.
395
+ * @param params - feedbackConfigurationId, questionId, file, optional fileName and onProgress
396
+ * @returns Promise resolving to { fileUrl: string }
397
+ */
398
+ uploadFile(params: UploadFileRequest): Promise<UploadFileResponse>;
399
+ /**
400
+ * Subscribe to all form events
401
+ * The callback receives all form events (show, submit, close, complete, error)
402
+ * @param callback - Function to call when any form event occurs
403
+ * @returns Unsubscribe function
404
+ */
405
+ on(callback: EventCallback): () => void;
406
+ /**
407
+ * Clear all SDK state and stored data, reverting to a brand-new visitor state.
408
+ * Stops the ping interval and URL change listeners, clears all localStorage and
409
+ * IndexedDB data written by the SDK, and resets all in-memory identity state.
410
+ * showForm() and submitForm() continue to work after this call (with NIL UUIDs),
411
+ * but no tracking fires until startSession() or identifyUser() is called again.
412
+ * Use this to implement a "forget me" / consent withdrawal flow.
413
+ */
414
+ clearAll(): void;
415
+ /**
416
+ * Merge additional source tracking key-value pairs into the SDK's in-memory
417
+ * source tracking store. These values are combined with auto-parsed URL params
418
+ * whenever showForm() is called. Values set here take precedence over URL params
419
+ * on key collision. Persists in memory for the lifetime of the page session.
420
+ * Supported on the web SDK only.
421
+ * @param values - Key-value pairs to merge into the source tracking store
422
+ */
423
+ addSourceTracking(values: Record<string, string>): void;
424
+ /** Internal: Command queue for calls made before script loads */
425
+ _q: Command[];
426
+ /** Internal: Event callbacks */
427
+ _eventCallbacks: EventCallback[];
428
+ /** Internal: Whether the SDK has been initialized */
429
+ _initialized: boolean;
430
+ /** Internal: The API key */
431
+ _apiKey: string | null;
432
+ /** Internal: Configuration */
433
+ _config: EncatchConfig;
434
+ }
435
+ /**
436
+ * Global window augmentation for TypeScript
437
+ */
438
+ declare global {
439
+ interface Window {
440
+ _encatch: EncatchSDK;
441
+ }
442
+ }
443
+ //# sourceMappingURL=types.d.ts.map