react-native-my-survey-sdk 3.0.0 → 3.0.1

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 (75) hide show
  1. package/dist/components/XeboDropdownView.d.ts +10 -0
  2. package/dist/components/XeboDropdownView.d.ts.map +1 -0
  3. package/dist/components/XeboDropdownView.js +190 -0
  4. package/dist/components/XeboIntroView.d.ts +9 -0
  5. package/dist/components/XeboIntroView.d.ts.map +1 -0
  6. package/dist/components/XeboIntroView.js +54 -0
  7. package/dist/components/XeboMultiNPSView.d.ts +10 -0
  8. package/dist/components/XeboMultiNPSView.d.ts.map +1 -0
  9. package/dist/components/XeboMultiNPSView.js +170 -0
  10. package/dist/components/XeboMultiRatingView.d.ts +10 -0
  11. package/dist/components/XeboMultiRatingView.d.ts.map +1 -0
  12. package/dist/components/XeboMultiRatingView.js +154 -0
  13. package/dist/components/XeboMultipleChoiceView.d.ts +10 -0
  14. package/dist/components/XeboMultipleChoiceView.d.ts.map +1 -0
  15. package/dist/components/XeboMultipleChoiceView.js +188 -0
  16. package/dist/components/XeboNPSView.d.ts +10 -0
  17. package/dist/components/XeboNPSView.d.ts.map +1 -0
  18. package/dist/components/XeboNPSView.js +269 -0
  19. package/dist/components/XeboRatingView.d.ts +10 -0
  20. package/dist/components/XeboRatingView.d.ts.map +1 -0
  21. package/dist/components/XeboRatingView.js +248 -0
  22. package/dist/components/XeboSingleChoiceView.d.ts +10 -0
  23. package/dist/components/XeboSingleChoiceView.d.ts.map +1 -0
  24. package/dist/components/XeboSingleChoiceView.js +172 -0
  25. package/dist/components/XeboSurveyModal.d.ts +3 -0
  26. package/dist/components/XeboSurveyModal.d.ts.map +1 -0
  27. package/dist/components/XeboSurveyModal.js +345 -0
  28. package/dist/components/XeboTextBoxView.d.ts +10 -0
  29. package/dist/components/XeboTextBoxView.d.ts.map +1 -0
  30. package/dist/components/XeboTextBoxView.js +176 -0
  31. package/dist/components/XeboThankYouView.d.ts +9 -0
  32. package/dist/components/XeboThankYouView.d.ts.map +1 -0
  33. package/dist/components/XeboThankYouView.js +115 -0
  34. package/dist/core/XeboNetworkService.d.ts +34 -0
  35. package/dist/core/XeboNetworkService.d.ts.map +1 -0
  36. package/dist/core/XeboNetworkService.js +367 -0
  37. package/dist/core/XeboOfflineQueue.d.ts +8 -0
  38. package/dist/core/XeboOfflineQueue.d.ts.map +1 -0
  39. package/dist/core/XeboOfflineQueue.js +35 -0
  40. package/dist/core/XeboSurveyManager.d.ts +59 -0
  41. package/dist/core/XeboSurveyManager.d.ts.map +1 -0
  42. package/dist/core/XeboSurveyManager.js +351 -0
  43. package/dist/index.d.ts +5 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +12 -0
  46. package/dist/models/XeboAPIModels.d.ts +82 -0
  47. package/dist/models/XeboAPIModels.d.ts.map +1 -0
  48. package/dist/models/XeboAPIModels.js +4 -0
  49. package/dist/models/XeboModels.d.ts +141 -0
  50. package/dist/models/XeboModels.d.ts.map +1 -0
  51. package/dist/models/XeboModels.js +17 -0
  52. package/dist/theme/XeboTheme.d.ts +11 -0
  53. package/dist/theme/XeboTheme.d.ts.map +1 -0
  54. package/dist/theme/XeboTheme.js +25 -0
  55. package/package.json +10 -3
  56. package/babel.config.js +0 -4
  57. package/src/components/XeboDropdownView.tsx +0 -197
  58. package/src/components/XeboIntroView.tsx +0 -68
  59. package/src/components/XeboMultiNPSView.tsx +0 -166
  60. package/src/components/XeboMultiRatingView.tsx +0 -165
  61. package/src/components/XeboMultipleChoiceView.tsx +0 -183
  62. package/src/components/XeboNPSView.tsx +0 -315
  63. package/src/components/XeboRatingView.tsx +0 -267
  64. package/src/components/XeboSingleChoiceView.tsx +0 -168
  65. package/src/components/XeboSurveyModal.tsx +0 -360
  66. package/src/components/XeboTextBoxView.tsx +0 -188
  67. package/src/components/XeboThankYouView.tsx +0 -100
  68. package/src/core/XeboNetworkService.ts +0 -476
  69. package/src/core/XeboOfflineQueue.ts +0 -33
  70. package/src/core/XeboSurveyManager.ts +0 -422
  71. package/src/index.ts +0 -23
  72. package/src/models/XeboAPIModels.ts +0 -80
  73. package/src/models/XeboModels.ts +0 -169
  74. package/src/theme/XeboTheme.ts +0 -33
  75. package/tsconfig.json +0 -17
@@ -0,0 +1,34 @@
1
+ import { XeboSurvey, XeboAnswer, XeboUserData, XeboQualityFlags, XeboGeolocation, XeboDeviceInfo } from '../models/XeboModels';
2
+ import { APISurveyResponse } from '../models/XeboAPIModels';
3
+ export declare function resolveZone(zone: string): string;
4
+ export declare function buildBaseURL(resolvedZone: string): string;
5
+ export declare function buildFeedbackBaseURL(resolvedZone: string): string;
6
+ export declare function buildVerifyURL(): string;
7
+ export declare function verifyApiKey(verifyURL: string, zone: string, apiKey: string): Promise<string>;
8
+ export declare function stripHTML(raw: string | undefined): string;
9
+ export declare function parseSurvey(data: APISurveyResponse['data']): XeboSurvey;
10
+ export interface CollectorInfo {
11
+ surveyId: string;
12
+ uuid: string;
13
+ mongoId: string;
14
+ }
15
+ export declare function fetchCollector(baseURL: string, collectorId: string, bearerToken: string): Promise<CollectorInfo>;
16
+ export declare function fetchSurvey(baseURL: string, surveyId: string, bearerToken: string): Promise<XeboSurvey>;
17
+ export interface SubmitResult {
18
+ ok: boolean;
19
+ status: number;
20
+ responseJson: unknown;
21
+ }
22
+ export interface SubmitMeta {
23
+ userData?: XeboUserData;
24
+ deviceModel?: string;
25
+ platform?: string;
26
+ osVersion?: string;
27
+ startTime?: string;
28
+ endTime?: string;
29
+ qualityFlags?: XeboQualityFlags;
30
+ geolocation?: XeboGeolocation;
31
+ deviceInfo?: XeboDeviceInfo;
32
+ }
33
+ export declare function submitResponse(feedbackBaseURL: string, surveyId: string, collectorUUID: string, bearerToken: string, answers: XeboAnswer[], meta?: SubmitMeta): Promise<SubmitResult>;
34
+ //# sourceMappingURL=XeboNetworkService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"XeboNetworkService.d.ts","sourceRoot":"","sources":["../../src/core/XeboNetworkService.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EAKV,UAAU,EACV,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,cAAc,EACf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAEL,iBAAiB,EAGlB,MAAM,yBAAyB,CAAC;AAIjC,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,wBAAgB,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAID,wBAAsB,YAAY,CAChC,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,CAqCjB;AAID,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAWzD;AAuCD,wBAAgB,WAAW,CAAC,IAAI,EAAE,iBAAiB,CAAC,MAAM,CAAC,GAAG,UAAU,CA6JvE;AAID,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAsB,cAAc,CAClC,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,aAAa,CAAC,CAgCxB;AAED,wBAAsB,WAAW,CAC/B,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,UAAU,CAAC,CAsBrB;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,gBAAgB,CAAC;IAChC,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B;AAED,wBAAsB,cAAc,CAClC,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,UAAU,EAAE,EACrB,IAAI,CAAC,EAAE,UAAU,GAChB,OAAO,CAAC,YAAY,CAAC,CAmFvB"}
@@ -0,0 +1,367 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveZone = resolveZone;
4
+ exports.buildBaseURL = buildBaseURL;
5
+ exports.buildFeedbackBaseURL = buildFeedbackBaseURL;
6
+ exports.buildVerifyURL = buildVerifyURL;
7
+ exports.verifyApiKey = verifyApiKey;
8
+ exports.stripHTML = stripHTML;
9
+ exports.parseSurvey = parseSurvey;
10
+ exports.fetchCollector = fetchCollector;
11
+ exports.fetchSurvey = fetchSurvey;
12
+ exports.submitResponse = submitResponse;
13
+ const XeboModels_1 = require("../models/XeboModels");
14
+ // ─── URL helpers ──────────────────────────────────────────────────────────────
15
+ function resolveZone(zone) {
16
+ return zone;
17
+ }
18
+ function buildBaseURL(resolvedZone) {
19
+ return `https://${resolvedZone}-api.xebo.ai`;
20
+ }
21
+ function buildFeedbackBaseURL(resolvedZone) {
22
+ return `https://${resolvedZone}-feedback-api.xebo.ai`;
23
+ }
24
+ function buildVerifyURL() {
25
+ return 'https://api.xebo.ai/api/v1/api-key/verify';
26
+ }
27
+ // ─── Step 0: API key verification → bearer token ─────────────────────────────
28
+ async function verifyApiKey(verifyURL, zone, apiKey) {
29
+ var _a, _b, _c, _d, _e, _f;
30
+ const url = `${verifyURL}?zone=${encodeURIComponent(zone)}`;
31
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
32
+ console.log('[Xebo Step 0] Verifying API key');
33
+ console.log('URL:', url);
34
+ const res = await fetch(url, {
35
+ method: 'GET',
36
+ headers: { 'x-api-key': apiKey },
37
+ });
38
+ const json = await res.json();
39
+ console.log('[Xebo] Verify response status:', res.status);
40
+ console.log('[Xebo] Verify response:', JSON.stringify(json));
41
+ if (!res.ok) {
42
+ throw new Error(`[Xebo] verifyApiKey failed — HTTP ${res.status}: ${JSON.stringify(json)}`);
43
+ }
44
+ const token = (_e = (_d = (_b = (_a = json === null || json === void 0 ? void 0 : json.access_token) !== null && _a !== void 0 ? _a : json === null || json === void 0 ? void 0 : json.token) !== null && _b !== void 0 ? _b : (_c = json === null || json === void 0 ? void 0 : json.data) === null || _c === void 0 ? void 0 : _c.token) !== null && _d !== void 0 ? _d : json === null || json === void 0 ? void 0 : json.bearerToken) !== null && _e !== void 0 ? _e : (_f = json === null || json === void 0 ? void 0 : json.data) === null || _f === void 0 ? void 0 : _f.access_token;
45
+ if (!token) {
46
+ throw new Error(`[Xebo] verifyApiKey — bearer token not found in response: ${JSON.stringify(json)}`);
47
+ }
48
+ console.log('[Xebo] Bearer token obtained successfully');
49
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
50
+ return token;
51
+ }
52
+ // ─── HTML stripping ───────────────────────────────────────────────────────────
53
+ function stripHTML(raw) {
54
+ if (!raw)
55
+ return '';
56
+ return raw
57
+ .replace(/<[^>]*>/g, '')
58
+ .replace(/&amp;/g, '&')
59
+ .replace(/&lt;/g, '<')
60
+ .replace(/&gt;/g, '>')
61
+ .replace(/&nbsp;/g, ' ')
62
+ .replace(/&quot;/g, '"')
63
+ .replace(/&#39;/g, "'")
64
+ .trim();
65
+ }
66
+ // ─── Question type mapping ────────────────────────────────────────────────────
67
+ function mapRatingStyle(apiType) {
68
+ switch (apiType === null || apiType === void 0 ? void 0 : apiType.toLowerCase()) {
69
+ case 'star':
70
+ case 'stars': return 'star';
71
+ case 'heart':
72
+ case 'hearts': return 'heart';
73
+ case 'circle':
74
+ case 'circles': return 'circle';
75
+ case 'tile':
76
+ case 'tiles': return 'tile';
77
+ case 'emoji':
78
+ case 'emojis': return 'emoji';
79
+ default: return 'star';
80
+ }
81
+ }
82
+ function mapQuestionType(apiType) {
83
+ switch (apiType) {
84
+ case 'single_choice': return XeboModels_1.XeboQuestionType.singleChoice;
85
+ case 'multi_choice': return XeboModels_1.XeboQuestionType.multipleChoice;
86
+ case 'dropdown': return XeboModels_1.XeboQuestionType.dropdown;
87
+ case 'single_text': return XeboModels_1.XeboQuestionType.singleTextBox;
88
+ case 'multi_text': return XeboModels_1.XeboQuestionType.multipleTextBox;
89
+ case 'nps':
90
+ case 'nps_pro': return XeboModels_1.XeboQuestionType.nps;
91
+ case 'multi_nps': return XeboModels_1.XeboQuestionType.multiNps;
92
+ case 'rating':
93
+ case 'rating_pro': return XeboModels_1.XeboQuestionType.rating;
94
+ case 'multi_rating': return XeboModels_1.XeboQuestionType.multiRating;
95
+ default: return XeboModels_1.XeboQuestionType.singleChoice;
96
+ }
97
+ }
98
+ // ─── Survey parsing ───────────────────────────────────────────────────────────
99
+ function parseSurvey(data) {
100
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2;
101
+ // Collect all follow-up question IDs (from NPS Pro configScale)
102
+ const followUpQuestionIds = new Set();
103
+ for (const block of data.blocks) {
104
+ for (const item of block.questions) {
105
+ const q = item.question;
106
+ const scales = (_b = (_a = q.settings) === null || _a === void 0 ? void 0 : _a.configScale) !== null && _b !== void 0 ? _b : [];
107
+ for (const scale of scales) {
108
+ for (const qid of (_c = scale.qId) !== null && _c !== void 0 ? _c : []) {
109
+ followUpQuestionIds.add(qid);
110
+ }
111
+ }
112
+ }
113
+ }
114
+ const questions = [];
115
+ for (const block of data.blocks) {
116
+ for (const item of block.questions) {
117
+ const q = item.question;
118
+ // Skip follow-up questions (they're embedded inline)
119
+ if (followUpQuestionIds.has(q.uuid))
120
+ continue;
121
+ const type = mapQuestionType(q.quesType);
122
+ if (type === XeboModels_1.XeboQuestionType.dropdown) {
123
+ console.log('[Xebo] Dropdown raw options keys:', JSON.stringify(Object.keys((_d = q.options) !== null && _d !== void 0 ? _d : {})));
124
+ console.log('[Xebo] Dropdown options.row:', JSON.stringify((_e = q.options) === null || _e === void 0 ? void 0 : _e.row));
125
+ console.log('[Xebo] Full dropdown q.options:', JSON.stringify(q.options));
126
+ }
127
+ const rawOptions = q.options;
128
+ const rowSource = Array.isArray(rawOptions)
129
+ ? rawOptions
130
+ : ((_h = (_g = (_f = rawOptions === null || rawOptions === void 0 ? void 0 : rawOptions.row) !== null && _f !== void 0 ? _f : rawOptions === null || rawOptions === void 0 ? void 0 : rawOptions.items) !== null && _g !== void 0 ? _g : rawOptions === null || rawOptions === void 0 ? void 0 : rawOptions.choices) !== null && _h !== void 0 ? _h : []);
131
+ const rows = rowSource.map((r) => {
132
+ var _a, _b, _c, _d, _e;
133
+ return ({
134
+ id: (_a = r.uuid) !== null && _a !== void 0 ? _a : r.id,
135
+ text: stripHTML((_d = (_c = (_b = r.text) !== null && _b !== void 0 ? _b : r.label) !== null && _c !== void 0 ? _c : r.value) !== null && _d !== void 0 ? _d : ''),
136
+ value: (_e = r.uuid) !== null && _e !== void 0 ? _e : r.id,
137
+ });
138
+ });
139
+ const cols = ((_k = (_j = rawOptions === null || rawOptions === void 0 ? void 0 : rawOptions.col) !== null && _j !== void 0 ? _j : rawOptions === null || rawOptions === void 0 ? void 0 : rawOptions.columns) !== null && _k !== void 0 ? _k : []).map((c) => {
140
+ var _a, _b, _c, _d;
141
+ return ({
142
+ id: (_a = c.uuid) !== null && _a !== void 0 ? _a : c.id,
143
+ text: stripHTML((_c = (_b = c.text) !== null && _b !== void 0 ? _b : c.label) !== null && _c !== void 0 ? _c : ''),
144
+ value: (_d = c.uuid) !== null && _d !== void 0 ? _d : c.id,
145
+ });
146
+ });
147
+ // Build conditional follow-ups for NPS Pro
148
+ const conditionalFollowUps = [];
149
+ const scales = (_m = (_l = q.settings) === null || _l === void 0 ? void 0 : _l.configScale) !== null && _m !== void 0 ? _m : [];
150
+ for (const scale of scales) {
151
+ if (scale.enabled === false)
152
+ continue;
153
+ const followUpQId = (_o = scale.qId) === null || _o === void 0 ? void 0 : _o[0];
154
+ if (!followUpQId)
155
+ continue;
156
+ // Find the follow-up question in all blocks
157
+ let followUpApiQ;
158
+ for (const b of data.blocks) {
159
+ for (const bi of b.questions) {
160
+ if (bi.question.uuid === followUpQId) {
161
+ followUpApiQ = bi.question;
162
+ break;
163
+ }
164
+ }
165
+ if (followUpApiQ)
166
+ break;
167
+ }
168
+ const followUpOptions = ((_q = (_p = followUpApiQ === null || followUpApiQ === void 0 ? void 0 : followUpApiQ.options) === null || _p === void 0 ? void 0 : _p.row) !== null && _q !== void 0 ? _q : []).map(r => ({
169
+ id: r.uuid,
170
+ text: stripHTML(r.text),
171
+ value: r.uuid,
172
+ }));
173
+ conditionalFollowUps.push({
174
+ minRating: Number(scale.scale.min),
175
+ maxRating: Number(scale.scale.max),
176
+ followUpQuestion: stripHTML((_r = followUpApiQ === null || followUpApiQ === void 0 ? void 0 : followUpApiQ.title) !== null && _r !== void 0 ? _r : ''),
177
+ followUpType: followUpApiQ ? mapQuestionType(followUpApiQ.quesType) : XeboModels_1.XeboQuestionType.singleTextBox,
178
+ followUpOptions,
179
+ questionId: followUpQId,
180
+ });
181
+ }
182
+ const npsSettings = (_s = q.settings) === null || _s === void 0 ? void 0 : _s.nps;
183
+ const ratingSettings = (_t = q.settings) === null || _t === void 0 ? void 0 : _t.rating;
184
+ const parsed = {
185
+ id: q.uuid,
186
+ type,
187
+ title: stripHTML(q.title),
188
+ subtitle: stripHTML((_u = q.helperText) === null || _u === void 0 ? void 0 : _u.text),
189
+ placeholder: stripHTML((_v = q.placeholder) === null || _v === void 0 ? void 0 : _v.text),
190
+ isRequired: (_x = (_w = q.required) === null || _w === void 0 ? void 0 : _w.enabled) !== null && _x !== void 0 ? _x : false,
191
+ options: rows.length > 0 ? rows : undefined,
192
+ columns: cols.length > 0 ? cols : undefined,
193
+ npsLabels: npsSettings
194
+ ? {
195
+ lower: npsSettings.leftLabel,
196
+ upper: npsSettings.rightLabel,
197
+ detractorColor: (_y = npsSettings.colors) === null || _y === void 0 ? void 0 : _y.detractor,
198
+ passiveColor: (_z = npsSettings.colors) === null || _z === void 0 ? void 0 : _z.passive,
199
+ promoterColor: (_0 = npsSettings.colors) === null || _0 === void 0 ? void 0 : _0.promoter,
200
+ }
201
+ : undefined,
202
+ followUpQuestion: undefined,
203
+ conditionalFollowUps: conditionalFollowUps.length > 0 ? conditionalFollowUps : undefined,
204
+ ratingStyle: mapRatingStyle(ratingSettings === null || ratingSettings === void 0 ? void 0 : ratingSettings.type),
205
+ showColLabels: ratingSettings === null || ratingSettings === void 0 ? void 0 : ratingSettings.colLabel,
206
+ ratingColor: ratingSettings === null || ratingSettings === void 0 ? void 0 : ratingSettings.color,
207
+ };
208
+ questions.push(parsed);
209
+ }
210
+ }
211
+ // Append auto thank-you question
212
+ const tyPage = data.thankYouPage;
213
+ const tyTitle = (tyPage === null || tyPage === void 0 ? void 0 : tyPage.enabled) && tyPage.content
214
+ ? stripHTML(tyPage.content)
215
+ : 'Thank You!';
216
+ const tySubtitle = (tyPage === null || tyPage === void 0 ? void 0 : tyPage.enabled) && tyPage.content
217
+ ? undefined
218
+ : 'Your feedback is greatly appreciated.';
219
+ questions.push({
220
+ id: 'thank_you_auto',
221
+ type: XeboModels_1.XeboQuestionType.thankYou,
222
+ title: tyTitle,
223
+ subtitle: tySubtitle,
224
+ isRequired: false,
225
+ redirectURL: tyPage === null || tyPage === void 0 ? void 0 : tyPage.links,
226
+ });
227
+ const introPageRaw = data.introPage;
228
+ const thankYouPageRaw = data.thankYouPage;
229
+ const survey = {
230
+ id: data.uuid,
231
+ name: data.displayTitle,
232
+ projectId: data.projectId,
233
+ questions,
234
+ introPage: introPageRaw
235
+ ? {
236
+ enabled: (_1 = introPageRaw.enabled) !== null && _1 !== void 0 ? _1 : false,
237
+ content: stripHTML(introPageRaw.content),
238
+ buttonText: introPageRaw.buttonText,
239
+ }
240
+ : undefined,
241
+ thankYouPage: thankYouPageRaw
242
+ ? {
243
+ enabled: (_2 = thankYouPageRaw.enabled) !== null && _2 !== void 0 ? _2 : false,
244
+ content: stripHTML(thankYouPageRaw.content),
245
+ links: thankYouPageRaw.links,
246
+ }
247
+ : undefined,
248
+ };
249
+ console.log('[Xebo] Full parsed survey:', JSON.stringify(survey, null, 2));
250
+ return survey;
251
+ }
252
+ async function fetchCollector(baseURL, collectorId, bearerToken) {
253
+ var _a;
254
+ const url = `${baseURL}/v3/collectors/collect/${collectorId}`;
255
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
256
+ console.log('[Xebo Step 1] Fetching collector');
257
+ console.log('URL:', url);
258
+ console.log('Collector ID:', collectorId);
259
+ const res = await fetch(url, { headers: { 'Authorization': `Bearer ${bearerToken}` } });
260
+ const json = await res.json();
261
+ // The API may return the collector object directly at the root OR wrapped in a `data` key
262
+ const payload = (_a = json === null || json === void 0 ? void 0 : json.data) !== null && _a !== void 0 ? _a : json;
263
+ if (!res.ok || !(payload === null || payload === void 0 ? void 0 : payload.surveyId)) {
264
+ throw new Error(`[Xebo] fetchCollector failed — HTTP ${res.status}. ` +
265
+ `Check your apiKey, collectorId and zone. Response: ${JSON.stringify(json)}`);
266
+ }
267
+ const info = {
268
+ surveyId: payload.surveyId,
269
+ uuid: payload.uuid,
270
+ mongoId: payload._id,
271
+ };
272
+ console.log('Collector UUID:', info.uuid);
273
+ console.log('Collector MongoId:', info.mongoId);
274
+ console.log('Survey ID:', info.surveyId);
275
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
276
+ return info;
277
+ }
278
+ async function fetchSurvey(baseURL, surveyId, bearerToken) {
279
+ var _a, _b, _c;
280
+ const url = `${baseURL}/v3/survey-management/surveys/${surveyId}`;
281
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
282
+ console.log('[Xebo Step 2] Fetching survey');
283
+ console.log('URL:', url);
284
+ const res = await fetch(url, { headers: { 'Authorization': `Bearer ${bearerToken}` } });
285
+ const json = await res.json();
286
+ console.log('[Xebo] Survey HTTP status:', res.status);
287
+ console.log('[Xebo] Survey data keys:', Object.keys((_a = json === null || json === void 0 ? void 0 : json.data) !== null && _a !== void 0 ? _a : {}));
288
+ console.log('[Xebo] blocks:', JSON.stringify((_c = (_b = json === null || json === void 0 ? void 0 : json.data) === null || _b === void 0 ? void 0 : _b.blocks) === null || _c === void 0 ? void 0 : _c.length));
289
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
290
+ if (!(json === null || json === void 0 ? void 0 : json.data)) {
291
+ throw new Error(`[Xebo] fetchSurvey — no data in response. HTTP ${res.status}`);
292
+ }
293
+ if (!Array.isArray(json.data.blocks)) {
294
+ throw new Error(`[Xebo] fetchSurvey — 'blocks' missing. Keys: ${Object.keys(json.data)}`);
295
+ }
296
+ return parseSurvey(json.data);
297
+ }
298
+ async function submitResponse(feedbackBaseURL, surveyId, collectorUUID, bearerToken, answers, meta) {
299
+ var _a;
300
+ const url = `${feedbackBaseURL}/v3/survey-participation/${surveyId}/response/create-response`;
301
+ // Filter out auto thank-you answer
302
+ const filteredAnswers = answers.filter(a => a.questionId !== 'thank_you_auto');
303
+ // Build custom_variables — the platform maps these to Name, Email, Mobile, Unique Id fields
304
+ const customVariables = {};
305
+ if (meta === null || meta === void 0 ? void 0 : meta.userData) {
306
+ if (meta.userData.name)
307
+ customVariables.fName = meta.userData.name;
308
+ if (meta.userData.email)
309
+ customVariables.email = meta.userData.email;
310
+ if (meta.userData.phone)
311
+ customVariables.mobile = meta.userData.phone;
312
+ if (meta.userData.uniqueId)
313
+ customVariables.unique_id = meta.userData.uniqueId;
314
+ if (meta.userData.country)
315
+ customVariables.country = meta.userData.country;
316
+ if (meta.userData.city)
317
+ customVariables.city = meta.userData.city;
318
+ if (meta.userData.eData) {
319
+ Object.entries(meta.userData.eData).forEach(([key, value]) => {
320
+ if (key && value)
321
+ customVariables[key] = value;
322
+ });
323
+ }
324
+ }
325
+ // time_spent in whole seconds, derived from netTimeDuration (minutes)
326
+ const timeTakenSecs = (meta === null || meta === void 0 ? void 0 : meta.qualityFlags)
327
+ ? Math.round(meta.qualityFlags.data.survey.netTimeDuration * 60)
328
+ : undefined;
329
+ const osVersion = ((_a = meta === null || meta === void 0 ? void 0 : meta.osVersion) !== null && _a !== void 0 ? _a : '').replace(/^(ios|android)\s*/i, '');
330
+ const userAgent = (meta === null || meta === void 0 ? void 0 : meta.platform) === 'ios'
331
+ ? `Mozilla/5.0 (iPhone; CPU iPhone OS ${osVersion.replace(/\./g, '_')} like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148`
332
+ : `Mozilla/5.0 (Linux; Android ${osVersion}; Mobile) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36`;
333
+ const payload = {
334
+ collector_id: collectorUUID,
335
+ responses: [
336
+ Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ response_status: 'complete', mode: 'React Native SDK', userAgent }, ((meta === null || meta === void 0 ? void 0 : meta.startTime) && { start_time: meta.startTime })), ((meta === null || meta === void 0 ? void 0 : meta.endTime) && { end_time: meta.endTime })), (timeTakenSecs !== undefined && { time_spent: timeTakenSecs })), (Object.keys(customVariables).length > 0 && { custom_variables: customVariables })), ((meta === null || meta === void 0 ? void 0 : meta.qualityFlags) && { qualityFlags: meta.qualityFlags })), ((meta === null || meta === void 0 ? void 0 : meta.deviceInfo) && { deviceInfo: meta.deviceInfo })), ((meta === null || meta === void 0 ? void 0 : meta.geolocation) && { geoLocation: meta.geolocation })), { questions: filteredAnswers.map(a => ({
337
+ uuid: a.questionId,
338
+ answer: a.value.map(v => ({
339
+ row_id: v.rowId || null,
340
+ col_id: v.colId || null,
341
+ text: v.text || null,
342
+ })),
343
+ })) }),
344
+ ],
345
+ };
346
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
347
+ console.log('[Xebo Step 3] Submitting response');
348
+ console.log('URL:', url);
349
+ console.log('Survey ID:', surveyId);
350
+ console.log('Collector ID:', collectorUUID);
351
+ console.log('Question count:', filteredAnswers.length);
352
+ console.log('Payload:', JSON.stringify(payload, null, 2));
353
+ const res = await fetch(url, {
354
+ method: 'POST',
355
+ headers: {
356
+ 'Authorization': `Bearer ${bearerToken}`,
357
+ 'Content-Type': 'application/json',
358
+ 'User-Agent': userAgent,
359
+ },
360
+ body: JSON.stringify(payload),
361
+ });
362
+ const responseJson = await res.json();
363
+ console.log('HTTP Status:', res.status);
364
+ console.log('Response JSON:', JSON.stringify(responseJson, null, 2));
365
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
366
+ return { ok: res.ok, status: res.status, responseJson };
367
+ }
@@ -0,0 +1,8 @@
1
+ import { XeboQueuedResponse } from '../models/XeboModels';
2
+ export declare const XeboOfflineQueue: {
3
+ enqueue(response: XeboQueuedResponse): Promise<void>;
4
+ getAll(): Promise<XeboQueuedResponse[]>;
5
+ saveAll(responses: XeboQueuedResponse[]): Promise<void>;
6
+ clear(): Promise<void>;
7
+ };
8
+ //# sourceMappingURL=XeboOfflineQueue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"XeboOfflineQueue.d.ts","sourceRoot":"","sources":["../../src/core/XeboOfflineQueue.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAI1D,eAAO,MAAM,gBAAgB;sBACH,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;cAS1C,OAAO,CAAC,kBAAkB,EAAE,CAAC;uBAUpB,kBAAkB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;aAI9C,OAAO,CAAC,IAAI,CAAC;CAG7B,CAAC"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.XeboOfflineQueue = void 0;
7
+ const async_storage_1 = __importDefault(require("@react-native-async-storage/async-storage"));
8
+ const STORAGE_KEY = 'com.xebo.offline_responses';
9
+ exports.XeboOfflineQueue = {
10
+ async enqueue(response) {
11
+ const existing = await this.getAll();
12
+ existing.push(response);
13
+ await this.saveAll(existing);
14
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
15
+ console.log('[Xebo Offline Queue] Enqueued response:', response.responseId);
16
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
17
+ },
18
+ async getAll() {
19
+ try {
20
+ const raw = await async_storage_1.default.getItem(STORAGE_KEY);
21
+ if (!raw)
22
+ return [];
23
+ return JSON.parse(raw);
24
+ }
25
+ catch (_a) {
26
+ return [];
27
+ }
28
+ },
29
+ async saveAll(responses) {
30
+ await async_storage_1.default.setItem(STORAGE_KEY, JSON.stringify(responses));
31
+ },
32
+ async clear() {
33
+ await async_storage_1.default.removeItem(STORAGE_KEY);
34
+ },
35
+ };
@@ -0,0 +1,59 @@
1
+ type Listener = (...args: any[]) => void;
2
+ declare class SimpleEventEmitter {
3
+ private _listeners;
4
+ emit(event: string, ...args: any[]): boolean;
5
+ on(event: string, listener: Listener): this;
6
+ off(event: string, listener: Listener): this;
7
+ removeAllListeners(event?: string): this;
8
+ }
9
+ import { XeboSurvey, XeboAnswer, XeboConfig, XeboThemeConfig, XeboUserData } from '../models/XeboModels';
10
+ export declare const XEBO_EVENTS: {
11
+ readonly SURVEY_LOADED: "survey_loaded";
12
+ readonly QUESTION_CHANGED: "question_changed";
13
+ readonly SURVEY_VISIBLE: "survey_visible";
14
+ readonly SURVEY_DISMISSED: "survey_dismissed";
15
+ };
16
+ declare class XeboSurveyManagerClass extends SimpleEventEmitter {
17
+ private apiKey;
18
+ private collectorId;
19
+ private resolvedZone;
20
+ private baseURL;
21
+ private feedbackBaseURL;
22
+ private verifyURL;
23
+ private bearerToken;
24
+ private userData;
25
+ private deviceModel;
26
+ private osVersion;
27
+ survey: XeboSurvey | null;
28
+ currentAnswers: XeboAnswer[];
29
+ currentQuestionIndex: number;
30
+ surveyStartTime: string;
31
+ resolvedCollectorUUID: string;
32
+ resolvedCollectorMongoId: string;
33
+ surveyVisible: boolean;
34
+ private surveyStartEpoch;
35
+ private questionStartEpoch;
36
+ private timePerQues;
37
+ private backTrackCount;
38
+ private netInfoUnsubscribe;
39
+ configure(config: XeboConfig): void;
40
+ configureTheme(config: XeboThemeConfig): void;
41
+ setUser(data: XeboUserData): void;
42
+ clearUser(): void;
43
+ private _startNetworkMonitoring;
44
+ private _verifyAndGetToken;
45
+ private _prefetchSurvey;
46
+ fetchAndPresentSurvey(): Promise<void>;
47
+ recordAnswer(answer: XeboAnswer): void;
48
+ nextQuestion(): void;
49
+ private _buildQualityFlags;
50
+ private _buildGeolocation;
51
+ private _submitCurrentSession;
52
+ private _enqueueOffline;
53
+ flushQueue(): Promise<void>;
54
+ private _setVisible;
55
+ dismissSurvey(): void;
56
+ }
57
+ export declare const XeboSurveyManager: XeboSurveyManagerClass;
58
+ export {};
59
+ //# sourceMappingURL=XeboSurveyManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"XeboSurveyManager.d.ts","sourceRoot":"","sources":["../../src/core/XeboSurveyManager.ts"],"names":[],"mappings":"AAKA,KAAK,QAAQ,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;AACzC,cAAM,kBAAkB;IACtB,OAAO,CAAC,UAAU,CAAsC;IACxD,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO;IAK5C,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAI3C,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAI5C,kBAAkB,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI;CAIzC;AAQD,OAAO,EACL,UAAU,EACV,UAAU,EACV,UAAU,EACV,eAAe,EAEf,YAAY,EAGb,MAAM,sBAAsB,CAAC;AAe9B,eAAO,MAAM,WAAW;;;;;CAKd,CAAC;AAIX,cAAM,sBAAuB,SAAQ,kBAAkB;IAErD,OAAO,CAAC,MAAM,CAAM;IACpB,OAAO,CAAC,WAAW,CAAM;IACzB,OAAO,CAAC,YAAY,CAAM;IAC1B,OAAO,CAAC,OAAO,CAAM;IACrB,OAAO,CAAC,eAAe,CAAM;IAC7B,OAAO,CAAC,SAAS,CAAM;IACvB,OAAO,CAAC,WAAW,CAAM;IAGzB,OAAO,CAAC,QAAQ,CAA6B;IAC7C,OAAO,CAAC,WAAW,CAAM;IACzB,OAAO,CAAC,SAAS,CAAM;IAGvB,MAAM,EAAE,UAAU,GAAG,IAAI,CAAQ;IACjC,cAAc,EAAE,UAAU,EAAE,CAAM;IAClC,oBAAoB,SAAK;IACzB,eAAe,SAAM;IACrB,qBAAqB,SAAM;IAC3B,wBAAwB,SAAM;IAC9B,aAAa,UAAS;IAGtB,OAAO,CAAC,gBAAgB,CAAK;IAC7B,OAAO,CAAC,kBAAkB,CAAK;IAC/B,OAAO,CAAC,WAAW,CAA8B;IACjD,OAAO,CAAC,cAAc,CAAK;IAG3B,OAAO,CAAC,kBAAkB,CAA6B;IAIvD,SAAS,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAkBnC,cAAc,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI;IAM7C,OAAO,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IAIjC,SAAS,IAAI,IAAI;IAMjB,OAAO,CAAC,uBAAuB;YAmBjB,kBAAkB;YAMlB,eAAe;IAkBvB,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC;IA8C5C,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAWtC,YAAY,IAAI,IAAI;IAyBpB,OAAO,CAAC,kBAAkB;IAsB1B,OAAO,CAAC,iBAAiB;YAUX,qBAAqB;YA4CrB,eAAe;IA8BvB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IA4CjC,OAAO,CAAC,WAAW;IAKnB,aAAa,IAAI,IAAI;CAItB;AAED,eAAO,MAAM,iBAAiB,wBAA+B,CAAC"}