@encatch/react-native-sdk 1.0.0-beta.0 → 1.0.0-beta.3
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 +13 -193
- package/dist/index.d.mts +30 -4
- package/dist/index.d.ts +30 -4
- package/dist/index.js +25 -6
- package/dist/index.mjs +25 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,204 +1,24 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @encatch/react-native-sdk
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Ensight SDK provides a seamless way to integrate user feedback collection into your React Native applications. This SDK allows you to display customized feedback forms, collect user responses, and submit them to the Ensight backend.
|
|
3
|
+
The Encatch React Native SDK lets you collect user feedback in your React Native and Expo apps. Display feedback forms in using native with encatch hooks or a WebView overlay, identify users, track screens and events, and submit responses to the Encatch backend.
|
|
6
4
|
|
|
7
5
|
## Installation
|
|
8
6
|
|
|
9
7
|
```bash
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
#
|
|
14
|
-
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## Quick Start
|
|
18
|
-
|
|
19
|
-
```javascript
|
|
20
|
-
import Ensight, { EnsightConfig, EnsightTheme } from "ensight-react-native";
|
|
21
|
-
|
|
22
|
-
// Initialize the SDK
|
|
23
|
-
const config = new EnsightConfig({
|
|
24
|
-
host: "https://app.dev.en-gage.in",
|
|
25
|
-
themeMode: "light",
|
|
26
|
-
language: "en",
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
Ensight.instance.ensightApp.initialize({
|
|
30
|
-
apiKey: "YOUR_API_KEY_HERE",
|
|
31
|
-
config: config,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
// Open feedback form
|
|
35
|
-
Ensight.instance.ensightApp.openFeedback();
|
|
8
|
+
npm install @encatch/react-native-sdk
|
|
9
|
+
# or
|
|
10
|
+
yarn add @encatch/react-native-sdk
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @encatch/react-native-sdk
|
|
36
13
|
```
|
|
37
14
|
|
|
38
|
-
##
|
|
39
|
-
|
|
40
|
-
- In-app feedback collection
|
|
41
|
-
- Customizable feedback forms
|
|
42
|
-
- Theme support (light/dark)
|
|
43
|
-
- Multilingual support
|
|
44
|
-
- User identification
|
|
45
|
-
- Session management
|
|
46
|
-
- Event analytics
|
|
47
|
-
|
|
48
|
-
## SDK Initialization
|
|
49
|
-
|
|
50
|
-
Initialize the SDK early in your application lifecycle:
|
|
51
|
-
|
|
52
|
-
```javascript
|
|
53
|
-
const userInfo = {
|
|
54
|
-
user_name: "user@example.com",
|
|
55
|
-
properties: {
|
|
56
|
-
email: "user@example.com",
|
|
57
|
-
user_age: 30,
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const config = new EnsightConfig({
|
|
62
|
-
host: "https://app.dev.en-gage.in",
|
|
63
|
-
identity: userInfo,
|
|
64
|
-
processAfterIdentitySet: false,
|
|
65
|
-
isAutoCaptureEnabled: true,
|
|
66
|
-
themeMode: "light",
|
|
67
|
-
language: "en",
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
Ensight.instance.ensightApp.initialize({
|
|
71
|
-
apiKey: "YOUR_API_KEY_HERE",
|
|
72
|
-
config: config,
|
|
73
|
-
});
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
## Displaying Feedback Forms
|
|
77
|
-
|
|
78
|
-
### Open Default Feedback
|
|
79
|
-
|
|
80
|
-
```javascript
|
|
81
|
-
await Ensight.instance.ensightApp.openFeedback();
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
### Open Feedback by ID
|
|
85
|
-
|
|
86
|
-
```javascript
|
|
87
|
-
await Ensight.instance.ensightApp.openFeedbackById("FEEDBACK_CONFIGURATION_ID");
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
### Open Feedback by Name
|
|
91
|
-
|
|
92
|
-
```javascript
|
|
93
|
-
await Ensight.instance.ensightApp.openFeedbackByName("Feedback Form Title");
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
## User Identification
|
|
97
|
-
|
|
98
|
-
Identify users to personalize feedback forms:
|
|
99
|
-
|
|
100
|
-
```javascript
|
|
101
|
-
Ensight.instance.ensightApp.identify("user@example.com", {
|
|
102
|
-
email: "user@example.com",
|
|
103
|
-
user_age: 30,
|
|
104
|
-
});
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
## Session Management
|
|
108
|
-
|
|
109
|
-
Control and manage user sessions:
|
|
110
|
-
|
|
111
|
-
```javascript
|
|
112
|
-
// Stop the current session and generate a new session ID
|
|
113
|
-
await Ensight.instance.ensightApp.stopSession();
|
|
114
|
-
|
|
115
|
-
// Reset the session, clear user data, and reinitialize
|
|
116
|
-
await Ensight.instance.ensightApp.resetSession();
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
## Theming
|
|
120
|
-
|
|
121
|
-
Customize the appearance of feedback forms:
|
|
122
|
-
|
|
123
|
-
```javascript
|
|
124
|
-
// Set theme to dark mode
|
|
125
|
-
Ensight.instance.ensightApp.setTheme(EnsightTheme.dark);
|
|
126
|
-
|
|
127
|
-
// Set theme to light mode
|
|
128
|
-
Ensight.instance.ensightApp.setTheme(EnsightTheme.light);
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
## Language Support
|
|
132
|
-
|
|
133
|
-
Change the language for feedback forms:
|
|
134
|
-
|
|
135
|
-
```javascript
|
|
136
|
-
// Set language to English
|
|
137
|
-
Ensight.instance.ensightApp.setLanguage("en");
|
|
138
|
-
|
|
139
|
-
// Set language to Spanish
|
|
140
|
-
Ensight.instance.ensightApp.setLanguage("es");
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
## Event Tracking
|
|
144
|
-
|
|
145
|
-
Track user events for analytics:
|
|
146
|
-
|
|
147
|
-
```javascript
|
|
148
|
-
const eventInfo = {
|
|
149
|
-
event_name: "button_click",
|
|
150
|
-
properties: {
|
|
151
|
-
button_id: "submit_form",
|
|
152
|
-
page: "checkout",
|
|
153
|
-
},
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
Ensight.instance.ensightApp.queueEvent(eventInfo);
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
## Path Observation
|
|
160
|
-
|
|
161
|
-
Track user navigation within your app:
|
|
162
|
-
|
|
163
|
-
```javascript
|
|
164
|
-
// Set the current path
|
|
165
|
-
Ensight.instance.ensightApp.setCurrentPath("/home/products");
|
|
166
|
-
|
|
167
|
-
// Add path change observer
|
|
168
|
-
const pathObserver = Ensight.instance.ensightApp.pathObserver;
|
|
169
|
-
pathObserver.addObserver((oldPath, newPath) => {
|
|
170
|
-
console.log(`Navigation changed from ${oldPath} to ${newPath}`);
|
|
171
|
-
});
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
## Troubleshooting
|
|
175
|
-
|
|
176
|
-
If you encounter issues with the SDK:
|
|
177
|
-
|
|
178
|
-
1. Check initialization parameters
|
|
179
|
-
2. Verify API key and host URL
|
|
180
|
-
3. Ensure network connectivity
|
|
181
|
-
4. Check console logs for error messages
|
|
15
|
+
## Documentation
|
|
182
16
|
|
|
183
|
-
|
|
17
|
+
For the full API reference, configuration options, and usage examples, visit the official documentation:
|
|
184
18
|
|
|
185
|
-
|
|
186
|
-
| ----------------------- | --------------------------------------- | -------------------------------------------------------------- | --------------- |
|
|
187
|
-
| `initialize` | Initializes the SDK | `apiKey: string, config?: EnsightConfig` | `void` |
|
|
188
|
-
| `openFeedback` | Opens the default feedback form | None | `Promise<void>` |
|
|
189
|
-
| `openFeedbackById` | Opens a feedback form by ID | `id: string` | `Promise<void>` |
|
|
190
|
-
| `openFeedbackByName` | Opens a feedback form by name | `name: string` | `Promise<void>` |
|
|
191
|
-
| `identify` | Identifies a user | `userId: string, traits?: Record<string, any>` | `void` |
|
|
192
|
-
| `submitFeedback` | Submits feedback data | `feedback?: Record<string, any>` | `Promise<void>` |
|
|
193
|
-
| `stopSession` | Stops the current session | None | `Promise<void>` |
|
|
194
|
-
| `resetSession` | Resets the session and clears user data | None | `Promise<void>` |
|
|
195
|
-
| `setTheme` | Sets the theme | `theme: EnsightTheme` | `void` |
|
|
196
|
-
| `setLanguage` | Sets the language | `language: string` | `void` |
|
|
197
|
-
| `queueEvent` | Adds an event to the analytics queue | `event: EventInfo` | `void` |
|
|
198
|
-
| `setCurrentPath` | Sets the current path for analytics | `path: string` | `void` |
|
|
199
|
-
| `addPopupStateListener` | Adds a listener for popup state changes | `listener: (isVisible: boolean, props?: PopupUIProps) => void` | `() => void` |
|
|
200
|
-
| `pathObserver` | Gets the path observer instance | None | `PathObserver` |
|
|
19
|
+
**[https://encatch.com/docs/sdk-reference/mobile-sdk/react-native](https://encatch.com/docs/sdk-reference/mobile-sdk/react-native)**
|
|
201
20
|
|
|
202
|
-
##
|
|
21
|
+
## License
|
|
203
22
|
|
|
204
|
-
|
|
23
|
+
MIT
|
|
24
|
+
|
package/dist/index.d.mts
CHANGED
|
@@ -39,6 +39,8 @@ interface ShowFormInterceptorPayload {
|
|
|
39
39
|
prefillResponses: Record<string, unknown>;
|
|
40
40
|
locale?: string;
|
|
41
41
|
theme?: Theme;
|
|
42
|
+
/** Serialized caller context (Dates already converted to ISO strings) */
|
|
43
|
+
context?: Record<string, string | number | boolean>;
|
|
42
44
|
}
|
|
43
45
|
interface StartSessionOptions {
|
|
44
46
|
/** When true, do not call the immediate ping (30s ping interval still runs) */
|
|
@@ -75,12 +77,23 @@ type Theme = 'light' | 'dark' | 'system';
|
|
|
75
77
|
* - 'never': Never clear form data (preserve user's previous answers)
|
|
76
78
|
*/
|
|
77
79
|
type ResetMode = 'always' | 'on-complete' | 'never';
|
|
80
|
+
/**
|
|
81
|
+
* Context values that can be attached to a form submission.
|
|
82
|
+
* Date values are automatically serialized to ISO strings before being sent.
|
|
83
|
+
*/
|
|
84
|
+
type ContextValue = string | number | Date | boolean;
|
|
78
85
|
interface ShowFormOptions {
|
|
79
86
|
/**
|
|
80
87
|
* Controls when form data should be cleared.
|
|
81
88
|
* @default 'always'
|
|
82
89
|
*/
|
|
83
90
|
reset?: ResetMode;
|
|
91
|
+
/**
|
|
92
|
+
* Arbitrary key-value pairs attached to the form submission.
|
|
93
|
+
* Useful for passing caller-side metadata (e.g. plan tier, feature flag states).
|
|
94
|
+
* Date values are automatically serialized to ISO 8601 strings.
|
|
95
|
+
*/
|
|
96
|
+
context?: Record<string, ContextValue>;
|
|
84
97
|
}
|
|
85
98
|
type EventType = 'form:show' | 'form:started' | 'form:submit' | 'form:complete' | 'form:close' | 'form:dismissed' | 'form:error' | 'form:section:change' | 'form:answered';
|
|
86
99
|
interface EventPayload {
|
|
@@ -112,8 +125,6 @@ interface ShowFormResponse {
|
|
|
112
125
|
formConfiguration?: Record<string, unknown>;
|
|
113
126
|
questionnaireFields?: any;
|
|
114
127
|
otherConfigurationProperties?: any;
|
|
115
|
-
welcomeScreenProperties?: any;
|
|
116
|
-
endScreenProperties?: any;
|
|
117
128
|
appearanceProperties?: any;
|
|
118
129
|
partialResponseEnabled?: boolean;
|
|
119
130
|
pingAgainIn?: number;
|
|
@@ -136,6 +147,7 @@ interface RefineTextResponse {
|
|
|
136
147
|
pingOnNextPageVisit?: boolean;
|
|
137
148
|
$feedbackTransactions?: string;
|
|
138
149
|
}
|
|
150
|
+
type QuestionType = 'rating' | 'single_choice' | 'nps' | 'nested_selection' | 'multiple_choice_multiple' | 'short_answer' | 'long_text' | 'annotation' | 'welcome' | 'thank_you' | 'message_panel' | 'yes_no' | 'rating_matrix' | 'matrix_single_choice' | 'matrix_multiple_choice' | 'exit_form';
|
|
139
151
|
interface QuestionAnswer {
|
|
140
152
|
nps?: number;
|
|
141
153
|
rating?: number;
|
|
@@ -151,10 +163,14 @@ interface QuestionAnswer {
|
|
|
151
163
|
fileData?: string;
|
|
152
164
|
fileName?: string;
|
|
153
165
|
};
|
|
166
|
+
yesNo?: boolean;
|
|
167
|
+
ratingMatrix?: Record<string, number | string>;
|
|
168
|
+
matrixSingleChoice?: Record<string, string>;
|
|
169
|
+
matrixMultipleChoice?: Record<string, string[]>;
|
|
154
170
|
}
|
|
155
171
|
interface QuestionResponse {
|
|
156
172
|
questionId: string;
|
|
157
|
-
type?:
|
|
173
|
+
type?: QuestionType;
|
|
158
174
|
answer?: QuestionAnswer;
|
|
159
175
|
}
|
|
160
176
|
interface FormDetails {
|
|
@@ -166,6 +182,10 @@ interface FormDetails {
|
|
|
166
182
|
questions?: QuestionResponse[];
|
|
167
183
|
};
|
|
168
184
|
completionTimeInSeconds?: number;
|
|
185
|
+
/** Caller-provided metadata attached to this submission (Dates already serialized to ISO strings) */
|
|
186
|
+
context?: Record<string, string | number | boolean>;
|
|
187
|
+
/** IDs of questions the user actually navigated to, in order. Used for drop-off analysis. */
|
|
188
|
+
visitedQuestionIds?: string[];
|
|
169
189
|
}
|
|
170
190
|
interface SubmitFormRequest {
|
|
171
191
|
triggerType?: 'automatic' | 'manual';
|
|
@@ -233,6 +253,12 @@ declare class EncatchSDK {
|
|
|
233
253
|
private _showFormById;
|
|
234
254
|
dismissForm(formConfigurationId?: string): Promise<void>;
|
|
235
255
|
private _pendingResponses;
|
|
256
|
+
/**
|
|
257
|
+
* Pre-fills a response before showing a form.
|
|
258
|
+
* @param questionId - The ID or slug of the question to prepopulate. When a slug
|
|
259
|
+
* is provided the form engine resolves it to the matching question ID automatically.
|
|
260
|
+
* @param value - The value to set
|
|
261
|
+
*/
|
|
236
262
|
addToResponse(questionId: string, value: unknown): void;
|
|
237
263
|
getPendingResponses(): Record<string, unknown>;
|
|
238
264
|
clearPendingResponses(): void;
|
|
@@ -308,7 +334,7 @@ interface EncatchContextValue {
|
|
|
308
334
|
showForm: (formId: string, options?: ShowFormOptions) => void;
|
|
309
335
|
/** Call Encatch.dismissForm */
|
|
310
336
|
dismissForm: (formConfigurationId?: string) => void;
|
|
311
|
-
/** Call Encatch.addToResponse */
|
|
337
|
+
/** Call Encatch.addToResponse. Accepts a question ID or slug. */
|
|
312
338
|
addToResponse: (questionId: string, value: unknown) => void;
|
|
313
339
|
/** Call Encatch.resetUser */
|
|
314
340
|
resetUser: () => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -39,6 +39,8 @@ interface ShowFormInterceptorPayload {
|
|
|
39
39
|
prefillResponses: Record<string, unknown>;
|
|
40
40
|
locale?: string;
|
|
41
41
|
theme?: Theme;
|
|
42
|
+
/** Serialized caller context (Dates already converted to ISO strings) */
|
|
43
|
+
context?: Record<string, string | number | boolean>;
|
|
42
44
|
}
|
|
43
45
|
interface StartSessionOptions {
|
|
44
46
|
/** When true, do not call the immediate ping (30s ping interval still runs) */
|
|
@@ -75,12 +77,23 @@ type Theme = 'light' | 'dark' | 'system';
|
|
|
75
77
|
* - 'never': Never clear form data (preserve user's previous answers)
|
|
76
78
|
*/
|
|
77
79
|
type ResetMode = 'always' | 'on-complete' | 'never';
|
|
80
|
+
/**
|
|
81
|
+
* Context values that can be attached to a form submission.
|
|
82
|
+
* Date values are automatically serialized to ISO strings before being sent.
|
|
83
|
+
*/
|
|
84
|
+
type ContextValue = string | number | Date | boolean;
|
|
78
85
|
interface ShowFormOptions {
|
|
79
86
|
/**
|
|
80
87
|
* Controls when form data should be cleared.
|
|
81
88
|
* @default 'always'
|
|
82
89
|
*/
|
|
83
90
|
reset?: ResetMode;
|
|
91
|
+
/**
|
|
92
|
+
* Arbitrary key-value pairs attached to the form submission.
|
|
93
|
+
* Useful for passing caller-side metadata (e.g. plan tier, feature flag states).
|
|
94
|
+
* Date values are automatically serialized to ISO 8601 strings.
|
|
95
|
+
*/
|
|
96
|
+
context?: Record<string, ContextValue>;
|
|
84
97
|
}
|
|
85
98
|
type EventType = 'form:show' | 'form:started' | 'form:submit' | 'form:complete' | 'form:close' | 'form:dismissed' | 'form:error' | 'form:section:change' | 'form:answered';
|
|
86
99
|
interface EventPayload {
|
|
@@ -112,8 +125,6 @@ interface ShowFormResponse {
|
|
|
112
125
|
formConfiguration?: Record<string, unknown>;
|
|
113
126
|
questionnaireFields?: any;
|
|
114
127
|
otherConfigurationProperties?: any;
|
|
115
|
-
welcomeScreenProperties?: any;
|
|
116
|
-
endScreenProperties?: any;
|
|
117
128
|
appearanceProperties?: any;
|
|
118
129
|
partialResponseEnabled?: boolean;
|
|
119
130
|
pingAgainIn?: number;
|
|
@@ -136,6 +147,7 @@ interface RefineTextResponse {
|
|
|
136
147
|
pingOnNextPageVisit?: boolean;
|
|
137
148
|
$feedbackTransactions?: string;
|
|
138
149
|
}
|
|
150
|
+
type QuestionType = 'rating' | 'single_choice' | 'nps' | 'nested_selection' | 'multiple_choice_multiple' | 'short_answer' | 'long_text' | 'annotation' | 'welcome' | 'thank_you' | 'message_panel' | 'yes_no' | 'rating_matrix' | 'matrix_single_choice' | 'matrix_multiple_choice' | 'exit_form';
|
|
139
151
|
interface QuestionAnswer {
|
|
140
152
|
nps?: number;
|
|
141
153
|
rating?: number;
|
|
@@ -151,10 +163,14 @@ interface QuestionAnswer {
|
|
|
151
163
|
fileData?: string;
|
|
152
164
|
fileName?: string;
|
|
153
165
|
};
|
|
166
|
+
yesNo?: boolean;
|
|
167
|
+
ratingMatrix?: Record<string, number | string>;
|
|
168
|
+
matrixSingleChoice?: Record<string, string>;
|
|
169
|
+
matrixMultipleChoice?: Record<string, string[]>;
|
|
154
170
|
}
|
|
155
171
|
interface QuestionResponse {
|
|
156
172
|
questionId: string;
|
|
157
|
-
type?:
|
|
173
|
+
type?: QuestionType;
|
|
158
174
|
answer?: QuestionAnswer;
|
|
159
175
|
}
|
|
160
176
|
interface FormDetails {
|
|
@@ -166,6 +182,10 @@ interface FormDetails {
|
|
|
166
182
|
questions?: QuestionResponse[];
|
|
167
183
|
};
|
|
168
184
|
completionTimeInSeconds?: number;
|
|
185
|
+
/** Caller-provided metadata attached to this submission (Dates already serialized to ISO strings) */
|
|
186
|
+
context?: Record<string, string | number | boolean>;
|
|
187
|
+
/** IDs of questions the user actually navigated to, in order. Used for drop-off analysis. */
|
|
188
|
+
visitedQuestionIds?: string[];
|
|
169
189
|
}
|
|
170
190
|
interface SubmitFormRequest {
|
|
171
191
|
triggerType?: 'automatic' | 'manual';
|
|
@@ -233,6 +253,12 @@ declare class EncatchSDK {
|
|
|
233
253
|
private _showFormById;
|
|
234
254
|
dismissForm(formConfigurationId?: string): Promise<void>;
|
|
235
255
|
private _pendingResponses;
|
|
256
|
+
/**
|
|
257
|
+
* Pre-fills a response before showing a form.
|
|
258
|
+
* @param questionId - The ID or slug of the question to prepopulate. When a slug
|
|
259
|
+
* is provided the form engine resolves it to the matching question ID automatically.
|
|
260
|
+
* @param value - The value to set
|
|
261
|
+
*/
|
|
236
262
|
addToResponse(questionId: string, value: unknown): void;
|
|
237
263
|
getPendingResponses(): Record<string, unknown>;
|
|
238
264
|
clearPendingResponses(): void;
|
|
@@ -308,7 +334,7 @@ interface EncatchContextValue {
|
|
|
308
334
|
showForm: (formId: string, options?: ShowFormOptions) => void;
|
|
309
335
|
/** Call Encatch.dismissForm */
|
|
310
336
|
dismissForm: (formConfigurationId?: string) => void;
|
|
311
|
-
/** Call Encatch.addToResponse */
|
|
337
|
+
/** Call Encatch.addToResponse. Accepts a question ID or slug. */
|
|
312
338
|
addToResponse: (questionId: string, value: unknown) => void;
|
|
313
339
|
/** Call Encatch.resetUser */
|
|
314
340
|
resetUser: () => void;
|
package/dist/index.js
CHANGED
|
@@ -553,7 +553,8 @@ var EncatchSDK = class {
|
|
|
553
553
|
// ============================================================================
|
|
554
554
|
// Form response helpers
|
|
555
555
|
// ============================================================================
|
|
556
|
-
// Pre-filled responses stored by addToResponse, sent with sdk:prefillResponses
|
|
556
|
+
// Pre-filled responses stored by addToResponse, sent with sdk:prefillResponses.
|
|
557
|
+
// Keys may be question IDs or slugs; the form engine resolves slugs to IDs.
|
|
557
558
|
this._pendingResponses = {};
|
|
558
559
|
}
|
|
559
560
|
// ============================================================================
|
|
@@ -787,6 +788,13 @@ var EncatchSDK = class {
|
|
|
787
788
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
788
789
|
const resetMode = (_a = options == null ? void 0 : options.reset) != null ? _a : "always";
|
|
789
790
|
const triggerType = (_b = options == null ? void 0 : options.triggerType) != null ? _b : "manual";
|
|
791
|
+
const serializedContext = (options == null ? void 0 : options.context) ? Object.entries(options.context).reduce(
|
|
792
|
+
(acc, [key, value]) => {
|
|
793
|
+
acc[key] = value instanceof Date ? value.toISOString() : value;
|
|
794
|
+
return acc;
|
|
795
|
+
},
|
|
796
|
+
{}
|
|
797
|
+
) : void 0;
|
|
790
798
|
const deviceInfo = await this._buildDeviceInfo();
|
|
791
799
|
const req = {
|
|
792
800
|
formSlugOrId: formId,
|
|
@@ -811,7 +819,8 @@ var EncatchSDK = class {
|
|
|
811
819
|
triggerType,
|
|
812
820
|
prefillResponses,
|
|
813
821
|
locale: (_f = this._locale) != null ? _f : void 0,
|
|
814
|
-
theme: this._theme
|
|
822
|
+
theme: this._theme,
|
|
823
|
+
context: serializedContext
|
|
815
824
|
};
|
|
816
825
|
if (this._onBeforeShowForm) {
|
|
817
826
|
const allow = await Promise.resolve(this._onBeforeShowForm(payload));
|
|
@@ -827,7 +836,8 @@ var EncatchSDK = class {
|
|
|
827
836
|
triggerType,
|
|
828
837
|
prefillResponses: Object.keys(prefillResponses).length > 0 ? prefillResponses : void 0,
|
|
829
838
|
locale: (_g = this._locale) != null ? _g : void 0,
|
|
830
|
-
theme: this._theme
|
|
839
|
+
theme: this._theme,
|
|
840
|
+
context: serializedContext
|
|
831
841
|
});
|
|
832
842
|
this._isFormVisible = true;
|
|
833
843
|
} catch (err) {
|
|
@@ -864,6 +874,12 @@ var EncatchSDK = class {
|
|
|
864
874
|
}
|
|
865
875
|
this.emitEvent("form:dismissed", { formId: formConfigurationId != null ? formConfigurationId : "" });
|
|
866
876
|
}
|
|
877
|
+
/**
|
|
878
|
+
* Pre-fills a response before showing a form.
|
|
879
|
+
* @param questionId - The ID or slug of the question to prepopulate. When a slug
|
|
880
|
+
* is provided the form engine resolves it to the matching question ID automatically.
|
|
881
|
+
* @param value - The value to set
|
|
882
|
+
*/
|
|
867
883
|
addToResponse(questionId, value) {
|
|
868
884
|
this._pendingResponses[questionId] = value;
|
|
869
885
|
}
|
|
@@ -1626,11 +1642,12 @@ var EncatchWebView = () => {
|
|
|
1626
1642
|
switch (type) {
|
|
1627
1643
|
case "form:ready": {
|
|
1628
1644
|
if (!formPayload) return;
|
|
1629
|
-
const { formConfig, resetMode, triggerType, prefillResponses, locale, theme } = formPayload;
|
|
1645
|
+
const { formConfig, resetMode, triggerType, prefillResponses, locale, theme, context } = formPayload;
|
|
1630
1646
|
injectSDKMessage({
|
|
1631
1647
|
type: "sdk:formConfig",
|
|
1632
1648
|
data: __spreadProps(__spreadValues({}, formConfig), {
|
|
1633
|
-
triggerType
|
|
1649
|
+
triggerType,
|
|
1650
|
+
context
|
|
1634
1651
|
})
|
|
1635
1652
|
});
|
|
1636
1653
|
if (resetMode === "always") {
|
|
@@ -1681,7 +1698,9 @@ var EncatchWebView = () => {
|
|
|
1681
1698
|
feedbackIdentifier: data.feedbackIdentifier,
|
|
1682
1699
|
responseLanguageCode: data.responseLanguageCode,
|
|
1683
1700
|
response: data.response,
|
|
1684
|
-
completionTimeInSeconds: data.completionTimeInSeconds
|
|
1701
|
+
completionTimeInSeconds: data.completionTimeInSeconds,
|
|
1702
|
+
context: data.context,
|
|
1703
|
+
visitedQuestionIds: data.visitedQuestionIds
|
|
1685
1704
|
},
|
|
1686
1705
|
$feedbackTransactions: void 0
|
|
1687
1706
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -522,7 +522,8 @@ var EncatchSDK = class {
|
|
|
522
522
|
// ============================================================================
|
|
523
523
|
// Form response helpers
|
|
524
524
|
// ============================================================================
|
|
525
|
-
// Pre-filled responses stored by addToResponse, sent with sdk:prefillResponses
|
|
525
|
+
// Pre-filled responses stored by addToResponse, sent with sdk:prefillResponses.
|
|
526
|
+
// Keys may be question IDs or slugs; the form engine resolves slugs to IDs.
|
|
526
527
|
this._pendingResponses = {};
|
|
527
528
|
}
|
|
528
529
|
// ============================================================================
|
|
@@ -756,6 +757,13 @@ var EncatchSDK = class {
|
|
|
756
757
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
757
758
|
const resetMode = (_a = options == null ? void 0 : options.reset) != null ? _a : "always";
|
|
758
759
|
const triggerType = (_b = options == null ? void 0 : options.triggerType) != null ? _b : "manual";
|
|
760
|
+
const serializedContext = (options == null ? void 0 : options.context) ? Object.entries(options.context).reduce(
|
|
761
|
+
(acc, [key, value]) => {
|
|
762
|
+
acc[key] = value instanceof Date ? value.toISOString() : value;
|
|
763
|
+
return acc;
|
|
764
|
+
},
|
|
765
|
+
{}
|
|
766
|
+
) : void 0;
|
|
759
767
|
const deviceInfo = await this._buildDeviceInfo();
|
|
760
768
|
const req = {
|
|
761
769
|
formSlugOrId: formId,
|
|
@@ -780,7 +788,8 @@ var EncatchSDK = class {
|
|
|
780
788
|
triggerType,
|
|
781
789
|
prefillResponses,
|
|
782
790
|
locale: (_f = this._locale) != null ? _f : void 0,
|
|
783
|
-
theme: this._theme
|
|
791
|
+
theme: this._theme,
|
|
792
|
+
context: serializedContext
|
|
784
793
|
};
|
|
785
794
|
if (this._onBeforeShowForm) {
|
|
786
795
|
const allow = await Promise.resolve(this._onBeforeShowForm(payload));
|
|
@@ -796,7 +805,8 @@ var EncatchSDK = class {
|
|
|
796
805
|
triggerType,
|
|
797
806
|
prefillResponses: Object.keys(prefillResponses).length > 0 ? prefillResponses : void 0,
|
|
798
807
|
locale: (_g = this._locale) != null ? _g : void 0,
|
|
799
|
-
theme: this._theme
|
|
808
|
+
theme: this._theme,
|
|
809
|
+
context: serializedContext
|
|
800
810
|
});
|
|
801
811
|
this._isFormVisible = true;
|
|
802
812
|
} catch (err) {
|
|
@@ -833,6 +843,12 @@ var EncatchSDK = class {
|
|
|
833
843
|
}
|
|
834
844
|
this.emitEvent("form:dismissed", { formId: formConfigurationId != null ? formConfigurationId : "" });
|
|
835
845
|
}
|
|
846
|
+
/**
|
|
847
|
+
* Pre-fills a response before showing a form.
|
|
848
|
+
* @param questionId - The ID or slug of the question to prepopulate. When a slug
|
|
849
|
+
* is provided the form engine resolves it to the matching question ID automatically.
|
|
850
|
+
* @param value - The value to set
|
|
851
|
+
*/
|
|
836
852
|
addToResponse(questionId, value) {
|
|
837
853
|
this._pendingResponses[questionId] = value;
|
|
838
854
|
}
|
|
@@ -1615,11 +1631,12 @@ var EncatchWebView = () => {
|
|
|
1615
1631
|
switch (type) {
|
|
1616
1632
|
case "form:ready": {
|
|
1617
1633
|
if (!formPayload) return;
|
|
1618
|
-
const { formConfig, resetMode, triggerType, prefillResponses, locale, theme } = formPayload;
|
|
1634
|
+
const { formConfig, resetMode, triggerType, prefillResponses, locale, theme, context } = formPayload;
|
|
1619
1635
|
injectSDKMessage({
|
|
1620
1636
|
type: "sdk:formConfig",
|
|
1621
1637
|
data: __spreadProps(__spreadValues({}, formConfig), {
|
|
1622
|
-
triggerType
|
|
1638
|
+
triggerType,
|
|
1639
|
+
context
|
|
1623
1640
|
})
|
|
1624
1641
|
});
|
|
1625
1642
|
if (resetMode === "always") {
|
|
@@ -1670,7 +1687,9 @@ var EncatchWebView = () => {
|
|
|
1670
1687
|
feedbackIdentifier: data.feedbackIdentifier,
|
|
1671
1688
|
responseLanguageCode: data.responseLanguageCode,
|
|
1672
1689
|
response: data.response,
|
|
1673
|
-
completionTimeInSeconds: data.completionTimeInSeconds
|
|
1690
|
+
completionTimeInSeconds: data.completionTimeInSeconds,
|
|
1691
|
+
context: data.context,
|
|
1692
|
+
visitedQuestionIds: data.visitedQuestionIds
|
|
1674
1693
|
},
|
|
1675
1694
|
$feedbackTransactions: void 0
|
|
1676
1695
|
};
|
package/package.json
CHANGED
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/get-encatch/react-native-sdk"
|
|
7
7
|
},
|
|
8
|
-
"homepage": "https://
|
|
8
|
+
"homepage": "https://encatch.com",
|
|
9
9
|
"bugs": {
|
|
10
10
|
"url": "https://github.com/get-encatch/react-native-sdk/issues"
|
|
11
11
|
},
|
|
12
12
|
"main": "dist/index.js",
|
|
13
13
|
"module": "dist/index.mjs",
|
|
14
14
|
"types": "dist/index.d.ts",
|
|
15
|
-
"version": "1.0.0-beta.
|
|
15
|
+
"version": "1.0.0-beta.3",
|
|
16
16
|
"files": [
|
|
17
17
|
"dist"
|
|
18
18
|
],
|