react-native-my-survey-sdk 3.1.2 → 4.0.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.
Files changed (65) hide show
  1. package/dist/components/XeboDropdownView.d.ts +6 -2
  2. package/dist/components/XeboDropdownView.d.ts.map +1 -1
  3. package/dist/components/XeboDropdownView.js +35 -22
  4. package/dist/components/XeboIntroView.d.ts.map +1 -1
  5. package/dist/components/XeboIntroView.js +3 -2
  6. package/dist/components/XeboLanguageView.d.ts +11 -0
  7. package/dist/components/XeboLanguageView.d.ts.map +1 -0
  8. package/dist/components/XeboLanguageView.js +90 -0
  9. package/dist/components/XeboMultiNPSView.d.ts +4 -2
  10. package/dist/components/XeboMultiNPSView.d.ts.map +1 -1
  11. package/dist/components/XeboMultiNPSView.js +32 -23
  12. package/dist/components/XeboMultiRatingView.d.ts +4 -2
  13. package/dist/components/XeboMultiRatingView.d.ts.map +1 -1
  14. package/dist/components/XeboMultiRatingView.js +31 -22
  15. package/dist/components/XeboMultipleChoiceView.d.ts +6 -2
  16. package/dist/components/XeboMultipleChoiceView.d.ts.map +1 -1
  17. package/dist/components/XeboMultipleChoiceView.js +43 -44
  18. package/dist/components/XeboNPSView.d.ts +8 -2
  19. package/dist/components/XeboNPSView.d.ts.map +1 -1
  20. package/dist/components/XeboNPSView.js +315 -55
  21. package/dist/components/XeboPageView.d.ts +33 -0
  22. package/dist/components/XeboPageView.d.ts.map +1 -0
  23. package/dist/components/XeboPageView.js +190 -0
  24. package/dist/components/XeboRatingView.d.ts +20 -2
  25. package/dist/components/XeboRatingView.d.ts.map +1 -1
  26. package/dist/components/XeboRatingView.js +71 -43
  27. package/dist/components/XeboSingleChoiceView.d.ts +8 -2
  28. package/dist/components/XeboSingleChoiceView.d.ts.map +1 -1
  29. package/dist/components/XeboSingleChoiceView.js +50 -46
  30. package/dist/components/XeboSurveyModal.d.ts.map +1 -1
  31. package/dist/components/XeboSurveyModal.js +236 -42
  32. package/dist/components/XeboTextBoxView.d.ts +4 -2
  33. package/dist/components/XeboTextBoxView.d.ts.map +1 -1
  34. package/dist/components/XeboTextBoxView.js +35 -23
  35. package/dist/components/XeboThankYouView.d.ts.map +1 -1
  36. package/dist/components/XeboThankYouView.js +3 -2
  37. package/dist/core/XeboLanguageService.d.ts +28 -0
  38. package/dist/core/XeboLanguageService.d.ts.map +1 -0
  39. package/dist/core/XeboLanguageService.js +267 -0
  40. package/dist/core/XeboNetworkService.d.ts +24 -3
  41. package/dist/core/XeboNetworkService.d.ts.map +1 -1
  42. package/dist/core/XeboNetworkService.js +202 -69
  43. package/dist/core/XeboOfflineQueue.d.ts +2 -1
  44. package/dist/core/XeboOfflineQueue.d.ts.map +1 -1
  45. package/dist/core/XeboOfflineQueue.js +24 -10
  46. package/dist/core/XeboSurveyManager.d.ts +38 -2
  47. package/dist/core/XeboSurveyManager.d.ts.map +1 -1
  48. package/dist/core/XeboSurveyManager.js +246 -72
  49. package/dist/i18n/XeboRtl.d.ts +16 -0
  50. package/dist/i18n/XeboRtl.d.ts.map +1 -0
  51. package/dist/i18n/XeboRtl.js +32 -0
  52. package/dist/i18n/XeboStrings.d.ts +35 -0
  53. package/dist/i18n/XeboStrings.d.ts.map +1 -0
  54. package/dist/i18n/XeboStrings.js +73 -0
  55. package/dist/index.d.ts +3 -1
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/models/XeboAPIModels.d.ts +103 -1
  58. package/dist/models/XeboAPIModels.d.ts.map +1 -1
  59. package/dist/models/XeboLanguageModels.d.ts +62 -0
  60. package/dist/models/XeboLanguageModels.d.ts.map +1 -0
  61. package/dist/models/XeboLanguageModels.js +3 -0
  62. package/dist/models/XeboModels.d.ts +93 -2
  63. package/dist/models/XeboModels.d.ts.map +1 -1
  64. package/dist/models/XeboModels.js +24 -0
  65. package/package.json +5 -5
@@ -37,14 +37,18 @@ const uuidv4 = () => 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c =
37
37
  return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
38
38
  });
39
39
  const XeboNetworkService_1 = require("./XeboNetworkService");
40
+ const XeboLanguageService_1 = require("./XeboLanguageService");
40
41
  const XeboOfflineQueue_1 = require("./XeboOfflineQueue");
41
42
  const XeboTheme_1 = require("../theme/XeboTheme");
43
+ const XeboStrings_1 = require("../i18n/XeboStrings");
42
44
  // ─── Event names ──────────────────────────────────────────────────────────────
43
45
  exports.XEBO_EVENTS = {
44
46
  SURVEY_LOADED: 'survey_loaded',
45
47
  QUESTION_CHANGED: 'question_changed',
46
48
  SURVEY_VISIBLE: 'survey_visible',
47
49
  SURVEY_DISMISSED: 'survey_dismissed',
50
+ LANGUAGE_PAGE: 'language_page',
51
+ LANGUAGE_SELECTED: 'language_selected',
48
52
  };
49
53
  // ─── Singleton class ──────────────────────────────────────────────────────────
50
54
  class XeboSurveyManagerClass extends SimpleEventEmitter {
@@ -66,10 +70,21 @@ class XeboSurveyManagerClass extends SimpleEventEmitter {
66
70
  this.survey = null;
67
71
  this.currentAnswers = [];
68
72
  this.currentQuestionIndex = 0;
73
+ /** Indices of the questions shown together, starting at currentQuestionIndex. */
74
+ this.currentPage = [];
75
+ /** Pages already passed, oldest first, so Previous can return to them. */
76
+ this.pageHistory = [];
69
77
  this.surveyStartTime = '';
70
78
  this.resolvedCollectorUUID = '';
71
79
  this.resolvedCollectorMongoId = '';
72
80
  this.surveyVisible = false;
81
+ this.disqualified = false;
82
+ // Language
83
+ this.rawSurveyData = null;
84
+ this.resolvedSurveyId = '';
85
+ this.languagePage = null;
86
+ /** Bumped on dismiss and on each pick, so a stale translation never opens the survey. */
87
+ this.languageLoadToken = 0;
73
88
  // Timing / quality
74
89
  this.surveyStartEpoch = 0;
75
90
  this.questionStartEpoch = 0;
@@ -82,6 +97,8 @@ class XeboSurveyManagerClass extends SimpleEventEmitter {
82
97
  configure(config) {
83
98
  this.apiKey = config.apiKey;
84
99
  this.collectorId = config.collectorId;
100
+ this.onLanguageSelected = config.onLanguageSelected;
101
+ XeboOfflineQueue_1.XeboOfflineQueue.setStorage(config.storage);
85
102
  this.resolvedZone = config.zone;
86
103
  this.baseURL = (0, XeboNetworkService_1.buildBaseURL)(this.resolvedZone);
87
104
  this.feedbackBaseURL = (0, XeboNetworkService_1.buildFeedbackBaseURL)(this.resolvedZone);
@@ -113,7 +130,6 @@ class XeboSurveyManagerClass extends SimpleEventEmitter {
113
130
  var _a;
114
131
  const isConnected = (_a = state.isConnected) !== null && _a !== void 0 ? _a : false;
115
132
  if (wasOffline && isConnected) {
116
- console.log('[Xebo] Network restored — flushing offline queue');
117
133
  this.flushQueue();
118
134
  }
119
135
  wasOffline = !isConnected;
@@ -126,60 +142,181 @@ class XeboSurveyManagerClass extends SimpleEventEmitter {
126
142
  // ─── Background pre-fetch ──────────────────────────────────────────────────
127
143
  async _prefetchSurvey() {
128
144
  try {
129
- console.log('[Xebo] Pre-fetching survey in background...');
130
- await this._verifyAndGetToken();
131
- const collector = await (0, XeboNetworkService_1.fetchCollector)(this.baseURL, this.collectorId, this.bearerToken);
132
- this.resolvedCollectorUUID = collector.uuid;
133
- this.resolvedCollectorMongoId = collector.mongoId;
134
- const survey = await (0, XeboNetworkService_1.fetchSurvey)(this.baseURL, collector.surveyId, this.bearerToken);
135
- this.survey = survey;
136
- this.emit(exports.XEBO_EVENTS.SURVEY_LOADED, survey);
137
- console.log('[Xebo] Pre-fetch done —', survey.questions.length, 'questions ready');
145
+ await this._loadSurveyData();
146
+ const survey = this.survey;
147
+ if (survey)
148
+ this.emit(exports.XEBO_EVENTS.SURVEY_LOADED, survey);
138
149
  }
139
- catch (err) {
140
- console.warn('[Xebo] Pre-fetch failed (will retry on fetchAndPresentSurvey):', err);
150
+ catch (_a) {
151
+ // Retried on fetchAndPresentSurvey.
141
152
  }
142
153
  }
154
+ /** Resolves token + collector + raw survey JSON, and parses the primary language. */
155
+ async _loadSurveyData(surveyId) {
156
+ await this._verifyAndGetToken();
157
+ const collector = await (0, XeboNetworkService_1.fetchCollector)(this.baseURL, this.collectorId, this.bearerToken);
158
+ this.resolvedCollectorUUID = collector.uuid;
159
+ this.resolvedCollectorMongoId = collector.mongoId;
160
+ this.resolvedSurveyId = surveyId !== null && surveyId !== void 0 ? surveyId : collector.surveyId;
161
+ this.rawSurveyData = await (0, XeboNetworkService_1.fetchSurveyRaw)(this.baseURL, this.resolvedSurveyId, this.bearerToken);
162
+ (0, XeboStrings_1.resetStrings)();
163
+ this.survey = (0, XeboNetworkService_1.parseSurvey)(this.rawSurveyData);
164
+ }
143
165
  // ─── Main flow ─────────────────────────────────────────────────────────────
144
- async fetchAndPresentSurvey() {
166
+ /** Collector-driven flow; `language` (e.g. "ar") skips the language page. */
167
+ async fetchAndPresentSurvey(language) {
168
+ return this._present(undefined, language);
169
+ }
170
+ /** Same flow for an explicit survey, still using the configured collector to submit. */
171
+ async fetchAndPresentSurveyById(surveyId, language) {
172
+ return this._present(surveyId, language);
173
+ }
174
+ async _present(surveyId, language) {
145
175
  try {
146
- // If already pre-fetched, show instantly
147
- if (this.survey && this.resolvedCollectorUUID) {
148
- console.log('[Xebo] Survey already cached — showing instantly');
149
- this.currentAnswers = [];
150
- this.currentQuestionIndex = 0;
151
- this.surveyStartTime = new Date().toISOString();
152
- this.surveyStartEpoch = Date.now();
153
- this.questionStartEpoch = Date.now();
154
- this.timePerQues = {};
155
- this.backTrackCount = 0;
156
- this.emit(exports.XEBO_EVENTS.SURVEY_LOADED, this.survey);
157
- this._setVisible(true);
176
+ const cached = this.rawSurveyData
177
+ && this.resolvedCollectorUUID
178
+ && (!surveyId || surveyId === this.resolvedSurveyId);
179
+ if (!cached)
180
+ await this._loadSurveyData(surveyId);
181
+ const raw = this.rawSurveyData;
182
+ if (raw && (0, XeboLanguageService_1.shouldShowLanguagePage)(raw, language)) {
183
+ this._presentLanguagePage(raw);
158
184
  return;
159
185
  }
160
- // Not cached yet — verify + fetch now
161
- console.log('[Xebo] Step 0: verifyApiKey');
162
- await this._verifyAndGetToken();
163
- console.log('[Xebo] Step 1: fetchCollector');
164
- const collector = await (0, XeboNetworkService_1.fetchCollector)(this.baseURL, this.collectorId, this.bearerToken);
165
- this.resolvedCollectorUUID = collector.uuid;
166
- this.resolvedCollectorMongoId = collector.mongoId;
167
- console.log('[Xebo] Step 2: fetchSurvey');
168
- const survey = await (0, XeboNetworkService_1.fetchSurvey)(this.baseURL, collector.surveyId, this.bearerToken);
169
- this.survey = survey;
170
- this.currentAnswers = [];
171
- this.currentQuestionIndex = 0;
172
- this.surveyStartTime = new Date().toISOString();
173
- this.surveyStartEpoch = Date.now();
174
- this.questionStartEpoch = Date.now();
175
- this.timePerQues = {};
176
- this.backTrackCount = 0;
177
- this.emit(exports.XEBO_EVENTS.SURVEY_LOADED, survey);
178
- this._setVisible(true);
186
+ await this._presentInLanguage(raw ? (0, XeboLanguageService_1.findLanguageOption)(raw, language) : undefined);
187
+ }
188
+ catch (_a) {
189
+ // Load failed; the survey stays hidden.
190
+ }
191
+ }
192
+ // ─── Language ──────────────────────────────────────────────────────────────
193
+ _presentLanguagePage(raw) {
194
+ this.languageLoadToken += 1;
195
+ (0, XeboStrings_1.resetStrings)();
196
+ this.languagePage = (0, XeboLanguageService_1.buildLanguagePage)(raw);
197
+ this.emit(exports.XEBO_EVENTS.LANGUAGE_PAGE, this.languagePage);
198
+ this._setVisible(true);
199
+ }
200
+ /** Called by the language page; loads the translation then swaps in the first question. */
201
+ async selectLanguage(langKey) {
202
+ var _a;
203
+ const raw = this.rawSurveyData;
204
+ if (!raw)
205
+ return;
206
+ const option = (0, XeboLanguageService_1.findLanguageOption)(raw, langKey);
207
+ if (!option)
208
+ return;
209
+ this.emit(exports.XEBO_EVENTS.LANGUAGE_SELECTED, option.langKey);
210
+ try {
211
+ (_a = this.onLanguageSelected) === null || _a === void 0 ? void 0 : _a.call(this, option.langKey);
212
+ }
213
+ catch (_b) {
214
+ // A throwing host callback must not block the survey.
215
+ }
216
+ await this._presentInLanguage(option);
217
+ }
218
+ async _presentInLanguage(option) {
219
+ var _a, _b;
220
+ const raw = this.rawSurveyData;
221
+ if (!raw)
222
+ return;
223
+ this.languageLoadToken += 1;
224
+ const token = this.languageLoadToken;
225
+ if (!option || option.isPrimary) {
226
+ (0, XeboStrings_1.resetStrings)();
227
+ (0, XeboStrings_1.setButtonLabels)((0, XeboNetworkService_1.primaryButtonLabels)(raw));
228
+ this.survey = (0, XeboNetworkService_1.parseSurvey)(raw, { langKey: option === null || option === void 0 ? void 0 : option.langKey, direction: option === null || option === void 0 ? void 0 : option.direction });
229
+ }
230
+ else {
231
+ try {
232
+ const bundle = await (0, XeboLanguageService_1.fetchTranslation)(this.baseURL, raw.uuid, option, this.bearerToken);
233
+ // A newer pick or a dismiss superseded this load.
234
+ if (token !== this.languageLoadToken)
235
+ return;
236
+ const direction = this._resolveDirection(option, (_a = bundle.script) === null || _a === void 0 ? void 0 : _a.direction);
237
+ (0, XeboStrings_1.configureStrings)({
238
+ langKey: option.langKey,
239
+ direction,
240
+ surveyEntry: (_b = bundle.textMapping[raw.uuid]) !== null && _b !== void 0 ? _b : undefined,
241
+ script: bundle.script,
242
+ });
243
+ this.survey = (0, XeboNetworkService_1.parseSurvey)((0, XeboLanguageService_1.applyTranslation)(raw, bundle.textMapping), {
244
+ localized: true,
245
+ langKey: option.langKey,
246
+ direction,
247
+ });
248
+ }
249
+ catch (_c) {
250
+ // A failed translation must not fail the load — fall back to the primary language.
251
+ if (token !== this.languageLoadToken)
252
+ return;
253
+ (0, XeboStrings_1.resetStrings)();
254
+ (0, XeboStrings_1.setButtonLabels)((0, XeboNetworkService_1.primaryButtonLabels)(raw));
255
+ this.survey = (0, XeboNetworkService_1.parseSurvey)(raw);
256
+ }
179
257
  }
180
- catch (err) {
181
- console.error('[Xebo] fetchAndPresentSurvey failed:', err);
258
+ if (token !== this.languageLoadToken)
259
+ return;
260
+ this._resetSession();
261
+ this.languagePage = null;
262
+ this.emit(exports.XEBO_EVENTS.SURVEY_LOADED, this.survey);
263
+ this._setVisible(true);
264
+ }
265
+ _resolveDirection(option, fromScript) {
266
+ if (String(fromScript !== null && fromScript !== void 0 ? fromScript : '').toLowerCase() === 'rtl')
267
+ return 'rtl';
268
+ return option.direction;
269
+ }
270
+ _resetSession() {
271
+ this.currentAnswers = [];
272
+ this.currentQuestionIndex = 0;
273
+ this.disqualified = false;
274
+ this.surveyStartTime = new Date().toISOString();
275
+ this.surveyStartEpoch = Date.now();
276
+ this.questionStartEpoch = Date.now();
277
+ this.timePerQues = {};
278
+ this.backTrackCount = 0;
279
+ this.pageHistory = [];
280
+ this._computePage();
281
+ }
282
+ /** True when there is an earlier page to go back to. */
283
+ get canGoBack() {
284
+ return this.pageHistory.length > 0;
285
+ }
286
+ /** The question's options left after options display logic, judged on the answers so far. */
287
+ optionsFor(question) {
288
+ var _a;
289
+ return (0, XeboNetworkService_1.visibleOptions)(question, (_a = this.survey) === null || _a === void 0 ? void 0 : _a.criteria, this._answersOnPath());
290
+ }
291
+ /** Answers on the path actually taken, so ones left on pages abandoned via Previous aren't used. */
292
+ _answersOnPath() {
293
+ var _a, _b;
294
+ const ids = new Set();
295
+ for (const i of [].concat(...this.pageHistory, this.currentPage)) {
296
+ const q = (_a = this.survey) === null || _a === void 0 ? void 0 : _a.questions[i];
297
+ if (!q)
298
+ continue;
299
+ ids.add(q.id);
300
+ (_b = q.conditionalFollowUps) === null || _b === void 0 ? void 0 : _b.forEach(f => ids.add(f.questionId));
182
301
  }
302
+ return this.currentAnswers.filter(a => ids.has(a.questionId));
303
+ }
304
+ /** Questions from the current one up to the next page break; display logic is checked as the page opens. */
305
+ _computePage() {
306
+ var _a, _b, _c;
307
+ const questions = (_b = (_a = this.survey) === null || _a === void 0 ? void 0 : _a.questions) !== null && _b !== void 0 ? _b : [];
308
+ const page = [];
309
+ for (let i = this.currentQuestionIndex; i < questions.length; i += 1) {
310
+ const q = questions[i];
311
+ if (q.id === 'thank_you_auto')
312
+ break;
313
+ if (i === this.currentQuestionIndex || (0, XeboNetworkService_1.isQuestionDisplayed)(q, (_c = this.survey) === null || _c === void 0 ? void 0 : _c.criteria, this._answersOnPath())) {
314
+ page.push(i);
315
+ }
316
+ if (q.pageBreakAfter)
317
+ break;
318
+ }
319
+ this.currentPage = page;
183
320
  }
184
321
  // ─── Answer recording ──────────────────────────────────────────────────────
185
322
  recordAnswer(answer) {
@@ -193,17 +330,49 @@ class XeboSurveyManagerClass extends SimpleEventEmitter {
193
330
  }
194
331
  // ─── Navigation ────────────────────────────────────────────────────────────
195
332
  nextQuestion() {
333
+ var _a;
196
334
  if (!this.survey)
197
335
  return;
198
- // Record time spent on the current question before advancing
199
- const currentQ = this.survey.questions[this.currentQuestionIndex];
200
- if (currentQ && currentQ.id !== 'thank_you_auto') {
201
- this.timePerQues[currentQ.id] = (Date.now() - this.questionStartEpoch) / 1000;
336
+ // Record time spent on the current page before advancing
337
+ const pageQuestions = this.currentPage.map(i => this.survey.questions[i]);
338
+ const elapsed = (Date.now() - this.questionStartEpoch) / 1000;
339
+ pageQuestions.forEach(q => { this.timePerQues[q.id] = elapsed; });
340
+ // The first question on the page whose logic jumps, ends or disqualifies decides where to go.
341
+ const answers = this._answersOnPath();
342
+ let rule;
343
+ for (const q of pageQuestions) {
344
+ const answer = answers.find(a => a.questionId === q.id);
345
+ const branch = (0, XeboNetworkService_1.resolveDelayedBranch)(q, this.survey.criteria, answers);
346
+ // An "otherwise" branch with no destination must not override skip logic.
347
+ rule = branch && branch.destinationType !== 'default'
348
+ ? branch
349
+ : (0, XeboNetworkService_1.resolveSkipRule)(q, answer);
350
+ if (rule && (rule.destinationType !== 'default' || rule.destinationQuestionId))
351
+ break;
352
+ }
353
+ if ((rule === null || rule === void 0 ? void 0 : rule.destinationType) === 'disqua') {
354
+ this.disqualified = true;
355
+ this._submitCurrentSession('disqualified');
356
+ return;
357
+ }
358
+ // Logic may jump forward to a specific question, or 'end' straight to the thank-you page.
359
+ const jumpIdx = (rule === null || rule === void 0 ? void 0 : rule.destinationType) === 'end'
360
+ ? this.survey.questions.findIndex(q => q.id === 'thank_you_auto')
361
+ : (rule === null || rule === void 0 ? void 0 : rule.destinationQuestionId)
362
+ ? this.survey.questions.findIndex(q => q.id === rule.destinationQuestionId)
363
+ : -1;
364
+ const lastOnPage = (_a = this.currentPage[this.currentPage.length - 1]) !== null && _a !== void 0 ? _a : this.currentQuestionIndex;
365
+ let next = jumpIdx > lastOnPage ? jumpIdx : lastOnPage + 1;
366
+ // Display logic: pass over questions whose criteria aren't met.
367
+ while (next < this.survey.questions.length &&
368
+ !(0, XeboNetworkService_1.isQuestionDisplayed)(this.survey.questions[next], this.survey.criteria, answers)) {
369
+ next += 1;
202
370
  }
203
- const next = this.currentQuestionIndex + 1;
204
371
  if (next < this.survey.questions.length) {
372
+ this.pageHistory.push(this.currentPage);
205
373
  this.currentQuestionIndex = next;
206
374
  this.questionStartEpoch = Date.now();
375
+ this._computePage();
207
376
  this.emit(exports.XEBO_EVENTS.QUESTION_CHANGED, this.currentQuestionIndex);
208
377
  // If this is the thank-you question, submit in the background
209
378
  const q = this.survey.questions[this.currentQuestionIndex];
@@ -212,6 +381,18 @@ class XeboSurveyManagerClass extends SimpleEventEmitter {
212
381
  }
213
382
  }
214
383
  }
384
+ /** Goes back to the page shown before this one; its answers stay recorded. */
385
+ previousPage() {
386
+ const page = this.pageHistory.pop();
387
+ if (!this.survey || !(page === null || page === void 0 ? void 0 : page.length))
388
+ return false;
389
+ this.currentQuestionIndex = page[0];
390
+ this.currentPage = page;
391
+ this.backTrackCount += 1;
392
+ this.questionStartEpoch = Date.now();
393
+ this.emit(exports.XEBO_EVENTS.QUESTION_CHANGED, this.currentQuestionIndex);
394
+ return true;
395
+ }
215
396
  // ─── Submission ────────────────────────────────────────────────────────────
216
397
  _buildQualityFlags() {
217
398
  const endEpoch = Date.now();
@@ -242,13 +423,13 @@ class XeboSurveyManagerClass extends SimpleEventEmitter {
242
423
  region: (_f = (_e = this.userData) === null || _e === void 0 ? void 0 : _e.region) !== null && _f !== void 0 ? _f : null,
243
424
  };
244
425
  }
245
- async _submitCurrentSession() {
246
- var _a, _b, _c;
426
+ async _submitCurrentSession(status = 'complete') {
427
+ var _a;
247
428
  if (!this.survey)
248
429
  return;
249
430
  const endTime = new Date().toISOString();
250
431
  try {
251
- const result = await (0, XeboNetworkService_1.submitResponse)(this.feedbackBaseURL, this.survey.id, this.resolvedCollectorUUID, this.bearerToken, this.currentAnswers, {
432
+ const result = await (0, XeboNetworkService_1.submitResponse)(this.feedbackBaseURL, this.survey.id, this.resolvedCollectorUUID, this.bearerToken, this._answersOnPath(), {
252
433
  userData: (_a = this.userData) !== null && _a !== void 0 ? _a : undefined,
253
434
  deviceModel: this.deviceModel,
254
435
  platform: react_native_1.Platform.OS,
@@ -262,22 +443,17 @@ class XeboSurveyManagerClass extends SimpleEventEmitter {
262
443
  os: react_native_1.Platform.OS === 'ios' ? 'ios' : 'android',
263
444
  browser: react_native_1.Platform.OS === 'ios' ? 'safari' : 'chrome',
264
445
  },
446
+ status,
265
447
  });
266
448
  if (!result.ok) {
267
449
  throw new Error(`HTTP ${result.status}`);
268
450
  }
269
- const respData = result.responseJson;
270
- console.log('[Xebo] Response data:', {
271
- responseId: (_b = respData === null || respData === void 0 ? void 0 : respData.data) === null || _b === void 0 ? void 0 : _b.responseId,
272
- created: (_c = respData === null || respData === void 0 ? void 0 : respData.data) === null || _c === void 0 ? void 0 : _c.created,
273
- });
274
451
  }
275
- catch (err) {
276
- console.error('[Xebo] Submission failed — queuing offline:', err);
277
- await this._enqueueOffline(endTime);
452
+ catch (_b) {
453
+ await this._enqueueOffline(endTime, status);
278
454
  }
279
455
  }
280
- async _enqueueOffline(endTime) {
456
+ async _enqueueOffline(endTime, status) {
281
457
  var _a;
282
458
  if (!this.survey)
283
459
  return;
@@ -286,10 +462,10 @@ class XeboSurveyManagerClass extends SimpleEventEmitter {
286
462
  surveyId: this.survey.id,
287
463
  collectorUUID: this.resolvedCollectorUUID,
288
464
  mode: 'React Native SDK',
289
- status: 'complete',
465
+ status,
290
466
  startTime: this.surveyStartTime,
291
467
  endTime,
292
- answers: [...this.currentAnswers],
468
+ answers: this._answersOnPath(),
293
469
  userData: (_a = this.userData) !== null && _a !== void 0 ? _a : undefined,
294
470
  deviceModel: this.deviceModel,
295
471
  platform: react_native_1.Platform.OS,
@@ -309,8 +485,6 @@ class XeboSurveyManagerClass extends SimpleEventEmitter {
309
485
  const all = await XeboOfflineQueue_1.XeboOfflineQueue.getAll();
310
486
  if (all.length === 0)
311
487
  return;
312
- console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
313
- console.log(`[Xebo Offline] Flushing ${all.length} queued response(s)`);
314
488
  const failed = [];
315
489
  for (const queued of all) {
316
490
  try {
@@ -324,19 +498,16 @@ class XeboSurveyManagerClass extends SimpleEventEmitter {
324
498
  qualityFlags: queued.qualityFlags,
325
499
  geolocation: queued.geolocation,
326
500
  deviceInfo: queued.deviceInfo,
501
+ status: queued.status,
327
502
  });
328
503
  if (!result.ok)
329
504
  throw new Error(`HTTP ${result.status}`);
330
- console.log('[Xebo Offline] Flushed response:', queued.responseId);
331
505
  }
332
- catch (err) {
333
- console.error('[Xebo Offline] Retry failed for:', queued.responseId, err);
506
+ catch (_a) {
334
507
  failed.push(queued);
335
508
  }
336
509
  }
337
510
  await XeboOfflineQueue_1.XeboOfflineQueue.saveAll(failed);
338
- console.log(`[Xebo Offline] Flush complete — ${failed.length} still pending`);
339
- console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
340
511
  }
341
512
  // ─── Modal visibility ──────────────────────────────────────────────────────
342
513
  _setVisible(visible) {
@@ -344,6 +515,9 @@ class XeboSurveyManagerClass extends SimpleEventEmitter {
344
515
  this.emit(exports.XEBO_EVENTS.SURVEY_VISIBLE, visible);
345
516
  }
346
517
  dismissSurvey() {
518
+ // Bumping the token aborts a translation that is still in flight.
519
+ this.languageLoadToken += 1;
520
+ this.languagePage = null;
347
521
  this._setVisible(false);
348
522
  this.emit(exports.XEBO_EVENTS.SURVEY_DISMISSED);
349
523
  }
@@ -0,0 +1,16 @@
1
+ import { TextStyle, ViewStyle } from 'react-native';
2
+ export declare function isRtl(): boolean;
3
+ /**
4
+ * Mirrors text inside question views when the chosen language is RTL.
5
+ * The sheet already sets `direction: 'rtl'`, under which React Native swaps
6
+ * left/right for textAlign — so 'left' here means the start (right) edge.
7
+ */
8
+ export declare function rtlText(): TextStyle | undefined;
9
+ /**
10
+ * rtlText() for TextInput. Android aligns inputs to the physical edge and ignores the
11
+ * sheet's direction, so it needs 'right'; iOS swaps like Text does.
12
+ */
13
+ export declare function rtlInput(): TextStyle | undefined;
14
+ /** Mirrors a flex row (option rows, scale rows) for RTL. */
15
+ export declare function rtlRow(): ViewStyle | undefined;
16
+ //# sourceMappingURL=XeboRtl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"XeboRtl.d.ts","sourceRoot":"","sources":["../../src/i18n/XeboRtl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAG9D,wBAAgB,KAAK,IAAI,OAAO,CAE/B;AAED;;;;GAIG;AACH,wBAAgB,OAAO,IAAI,SAAS,GAAG,SAAS,CAE/C;AAED;;;GAGG;AACH,wBAAgB,QAAQ,IAAI,SAAS,GAAG,SAAS,CAGhD;AAED,4DAA4D;AAC5D,wBAAgB,MAAM,IAAI,SAAS,GAAG,SAAS,CAE9C"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isRtl = isRtl;
4
+ exports.rtlText = rtlText;
5
+ exports.rtlInput = rtlInput;
6
+ exports.rtlRow = rtlRow;
7
+ const react_native_1 = require("react-native");
8
+ const XeboStrings_1 = require("./XeboStrings");
9
+ function isRtl() {
10
+ return (0, XeboStrings_1.getStrings)().direction === 'rtl';
11
+ }
12
+ /**
13
+ * Mirrors text inside question views when the chosen language is RTL.
14
+ * The sheet already sets `direction: 'rtl'`, under which React Native swaps
15
+ * left/right for textAlign — so 'left' here means the start (right) edge.
16
+ */
17
+ function rtlText() {
18
+ return isRtl() ? { textAlign: 'left', writingDirection: 'rtl' } : undefined;
19
+ }
20
+ /**
21
+ * rtlText() for TextInput. Android aligns inputs to the physical edge and ignores the
22
+ * sheet's direction, so it needs 'right'; iOS swaps like Text does.
23
+ */
24
+ function rtlInput() {
25
+ if (!isRtl())
26
+ return undefined;
27
+ return { textAlign: react_native_1.Platform.OS === 'android' ? 'right' : 'left', writingDirection: 'rtl' };
28
+ }
29
+ /** Mirrors a flex row (option rows, scale rows) for RTL. */
30
+ function rtlRow() {
31
+ return isRtl() ? { flexDirection: 'row-reverse' } : undefined;
32
+ }
@@ -0,0 +1,35 @@
1
+ import { APILangScript } from '../models/XeboLanguageModels';
2
+ export interface XeboStrings {
3
+ next: string;
4
+ submit: string;
5
+ /** Moves to the next question on a page that shows several. */
6
+ ok: string;
7
+ /** Scrolls back to the previous question on a page that shows several. */
8
+ previous: string;
9
+ skip: string;
10
+ close: string;
11
+ thankYouTitle: string;
12
+ thankYouMessage: string;
13
+ /** False until a non-primary language is picked; keeps English rendering byte-identical. */
14
+ localized: boolean;
15
+ direction: 'ltr' | 'rtl';
16
+ }
17
+ export interface ConfigureStringsInput {
18
+ langKey: string;
19
+ direction: 'ltr' | 'rtl';
20
+ /** The survey uuid's entry from the translation textMapping. */
21
+ surveyEntry?: Record<string, unknown>;
22
+ script?: APILangScript;
23
+ }
24
+ export declare function configureStrings(input: ConfigureStringsInput): void;
25
+ export declare function resetStrings(): void;
26
+ /** The survey's own button text for its primary language; blank values keep the defaults. */
27
+ export declare function setButtonLabels(labels: Partial<Record<'next' | 'submit' | 'ok' | 'previous', string>>): void;
28
+ export declare function getStrings(): XeboStrings;
29
+ /** The Next/Submit label every question view shows on its primary button. */
30
+ export declare function actionLabel(isLastQuestion: boolean): string;
31
+ /** A question's translated required message, falling back to the view's English text. */
32
+ export declare function requiredMessage(question: {
33
+ requiredMessage?: string;
34
+ }, fallback: string): string;
35
+ //# sourceMappingURL=XeboStrings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"XeboStrings.d.ts","sourceRoot":"","sources":["../../src/i18n/XeboStrings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAG7D,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,+DAA+D;IAC/D,EAAE,EAAE,MAAM,CAAC;IACX,0EAA0E;IAC1E,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,4FAA4F;IAC5F,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,KAAK,GAAG,KAAK,CAAC;CAC1B;AA2BD,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,KAAK,GAAG,KAAK,CAAC;IACzB,gEAAgE;IAChE,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,IAAI,CAkBnE;AAED,wBAAgB,YAAY,IAAI,IAAI,CAEnC;AAED,6FAA6F;AAC7F,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,QAAQ,GAAG,IAAI,GAAG,UAAU,EAAE,MAAM,CAAC,CAAC,GAAG,IAAI,CAK5G;AAED,wBAAgB,UAAU,IAAI,WAAW,CAExC;AAED,6EAA6E;AAC7E,wBAAgB,WAAW,CAAC,cAAc,EAAE,OAAO,GAAG,MAAM,CAE3D;AAED,yFAAyF;AACzF,wBAAgB,eAAe,CAAC,QAAQ,EAAE;IAAE,eAAe,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEhG"}
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configureStrings = configureStrings;
4
+ exports.resetStrings = resetStrings;
5
+ exports.setButtonLabels = setButtonLabels;
6
+ exports.getStrings = getStrings;
7
+ exports.actionLabel = actionLabel;
8
+ exports.requiredMessage = requiredMessage;
9
+ const XeboLanguageService_1 = require("../core/XeboLanguageService");
10
+ const defaultStrings = {
11
+ next: 'Next',
12
+ submit: 'Submit',
13
+ ok: 'Ok',
14
+ previous: 'Previous',
15
+ skip: 'Skip',
16
+ close: 'Close',
17
+ thankYouTitle: 'Thank You!',
18
+ thankYouMessage: 'Your feedback is greatly appreciated.',
19
+ localized: false,
20
+ direction: 'ltr',
21
+ };
22
+ /** The API ships no skip or thank-you translation, so the SDK carries its own. */
23
+ const builtIn = {
24
+ ar: {
25
+ skip: 'تخطي',
26
+ previous: 'السابق',
27
+ thankYouTitle: 'شكراً لك!',
28
+ thankYouMessage: 'نحن نقدّر ملاحظاتك كثيراً.',
29
+ },
30
+ };
31
+ let currentStrings = Object.assign({}, defaultStrings);
32
+ function configureStrings(input) {
33
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
34
+ const entry = (_a = input.surveyEntry) !== null && _a !== void 0 ? _a : {};
35
+ const slugs = (_c = (_b = input.script) === null || _b === void 0 ? void 0 : _b.textMapping) !== null && _c !== void 0 ? _c : {};
36
+ const fallback = (_d = builtIn[input.langKey.toLowerCase()]) !== null && _d !== void 0 ? _d : {};
37
+ const exit = (0, XeboLanguageService_1.translatedText)(entry.exit);
38
+ currentStrings = {
39
+ next: (_e = (0, XeboLanguageService_1.translatedText)(entry.next)) !== null && _e !== void 0 ? _e : defaultStrings.next,
40
+ submit: (_f = (0, XeboLanguageService_1.translatedText)(entry.submit)) !== null && _f !== void 0 ? _f : defaultStrings.submit,
41
+ ok: (_g = (0, XeboLanguageService_1.translatedText)(entry.ok)) !== null && _g !== void 0 ? _g : defaultStrings.ok,
42
+ previous: (_j = (_h = (0, XeboLanguageService_1.translatedText)(entry.prev)) !== null && _h !== void 0 ? _h : fallback.previous) !== null && _j !== void 0 ? _j : defaultStrings.previous,
43
+ skip: (_l = (_k = fallback.skip) !== null && _k !== void 0 ? _k : exit) !== null && _l !== void 0 ? _l : defaultStrings.skip,
44
+ close: (_m = (0, XeboLanguageService_1.translatedText)(slugs['close-text'])) !== null && _m !== void 0 ? _m : defaultStrings.close,
45
+ thankYouTitle: (_o = fallback.thankYouTitle) !== null && _o !== void 0 ? _o : defaultStrings.thankYouTitle,
46
+ thankYouMessage: (_p = fallback.thankYouMessage) !== null && _p !== void 0 ? _p : defaultStrings.thankYouMessage,
47
+ localized: true,
48
+ direction: input.direction,
49
+ };
50
+ }
51
+ function resetStrings() {
52
+ currentStrings = Object.assign({}, defaultStrings);
53
+ }
54
+ /** The survey's own button text for its primary language; blank values keep the defaults. */
55
+ function setButtonLabels(labels) {
56
+ for (const [key, value] of Object.entries(labels)) {
57
+ const text = (0, XeboLanguageService_1.translatedText)(value);
58
+ if (text)
59
+ currentStrings = Object.assign(Object.assign({}, currentStrings), { [key]: text });
60
+ }
61
+ }
62
+ function getStrings() {
63
+ return currentStrings;
64
+ }
65
+ /** The Next/Submit label every question view shows on its primary button. */
66
+ function actionLabel(isLastQuestion) {
67
+ return isLastQuestion ? currentStrings.submit : currentStrings.next;
68
+ }
69
+ /** A question's translated required message, falling back to the view's English text. */
70
+ function requiredMessage(question, fallback) {
71
+ var _a;
72
+ return (_a = (0, XeboLanguageService_1.translatedText)(question.requiredMessage)) !== null && _a !== void 0 ? _a : fallback;
73
+ }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export { XeboSurveyManager, XEBO_EVENTS } from './core/XeboSurveyManager';
2
2
  export { XeboSurveyModal } from './components/XeboSurveyModal';
3
- export type { XeboSurvey, XeboQuestion, XeboAnswer, XeboAnswerValue, XeboQueuedResponse, XeboConfig, XeboThemeConfig, XeboChoice, XeboNPSLabels, XeboConditionalFollowUp, XeboSurveyPage, XeboUserData, } from './models/XeboModels';
3
+ export type { XeboLanguageOption, XeboLanguagePageModel, XeboLanguagePrompt, } from './models/XeboLanguageModels';
4
+ export type { XeboStrings } from './i18n/XeboStrings';
5
+ export type { XeboSurvey, XeboQuestion, XeboAnswer, XeboAnswerValue, XeboQueuedResponse, XeboConfig, XeboStorageAdapter, XeboThemeConfig, XeboChoice, XeboNPSLabels, XeboConditionalFollowUp, XeboSurveyPage, XeboUserData, } from './models/XeboModels';
4
6
  export { XeboQuestionType } from './models/XeboModels';
5
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAG1E,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAG/D,YAAY,EACV,UAAU,EACV,YAAY,EACZ,UAAU,EACV,eAAe,EACf,kBAAkB,EAClB,UAAU,EACV,eAAe,EACf,UAAU,EACV,aAAa,EACb,uBAAuB,EACvB,cAAc,EACd,YAAY,GACb,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAG1E,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAG/D,YAAY,EACV,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,6BAA6B,CAAC;AACrC,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGtD,YAAY,EACV,UAAU,EACV,YAAY,EACZ,UAAU,EACV,eAAe,EACf,kBAAkB,EAClB,UAAU,EACV,kBAAkB,EAClB,eAAe,EACf,UAAU,EACV,aAAa,EACb,uBAAuB,EACvB,cAAc,EACd,YAAY,GACb,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC"}