react-native-my-survey-sdk 3.1.2 → 3.1.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/dist/components/XeboDropdownView.d.ts.map +1 -1
- package/dist/components/XeboDropdownView.js +10 -6
- package/dist/components/XeboIntroView.d.ts.map +1 -1
- package/dist/components/XeboIntroView.js +3 -2
- package/dist/components/XeboLanguageView.d.ts +11 -0
- package/dist/components/XeboLanguageView.d.ts.map +1 -0
- package/dist/components/XeboLanguageView.js +90 -0
- package/dist/components/XeboMultiNPSView.d.ts.map +1 -1
- package/dist/components/XeboMultiNPSView.js +9 -7
- package/dist/components/XeboMultiRatingView.d.ts.map +1 -1
- package/dist/components/XeboMultiRatingView.js +9 -7
- package/dist/components/XeboMultipleChoiceView.d.ts.map +1 -1
- package/dist/components/XeboMultipleChoiceView.js +10 -8
- package/dist/components/XeboNPSView.d.ts.map +1 -1
- package/dist/components/XeboNPSView.js +15 -13
- package/dist/components/XeboRatingView.d.ts.map +1 -1
- package/dist/components/XeboRatingView.js +10 -8
- package/dist/components/XeboSingleChoiceView.d.ts.map +1 -1
- package/dist/components/XeboSingleChoiceView.js +10 -8
- package/dist/components/XeboSurveyModal.d.ts.map +1 -1
- package/dist/components/XeboSurveyModal.js +96 -18
- package/dist/components/XeboTextBoxView.d.ts.map +1 -1
- package/dist/components/XeboTextBoxView.js +10 -7
- package/dist/components/XeboThankYouView.d.ts.map +1 -1
- package/dist/components/XeboThankYouView.js +3 -2
- package/dist/core/XeboLanguageService.d.ts +28 -0
- package/dist/core/XeboLanguageService.d.ts.map +1 -0
- package/dist/core/XeboLanguageService.js +261 -0
- package/dist/core/XeboNetworkService.d.ts +12 -2
- package/dist/core/XeboNetworkService.d.ts.map +1 -1
- package/dist/core/XeboNetworkService.js +27 -11
- package/dist/core/XeboSurveyManager.d.ts +22 -1
- package/dist/core/XeboSurveyManager.d.ts.map +1 -1
- package/dist/core/XeboSurveyManager.js +140 -39
- package/dist/i18n/XeboRtl.d.ts +11 -0
- package/dist/i18n/XeboRtl.d.ts.map +1 -0
- package/dist/i18n/XeboRtl.js +21 -0
- package/dist/i18n/XeboStrings.d.ts +29 -0
- package/dist/i18n/XeboStrings.d.ts.map +1 -0
- package/dist/i18n/XeboStrings.js +59 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/models/XeboAPIModels.d.ts +10 -1
- package/dist/models/XeboAPIModels.d.ts.map +1 -1
- package/dist/models/XeboLanguageModels.d.ts +62 -0
- package/dist/models/XeboLanguageModels.d.ts.map +1 -0
- package/dist/models/XeboLanguageModels.js +3 -0
- package/dist/models/XeboModels.d.ts +7 -0
- package/dist/models/XeboModels.d.ts.map +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SCREENER_PROMPT_KEY = void 0;
|
|
4
|
+
exports.translatedText = translatedText;
|
|
5
|
+
exports.buildLanguageOptions = buildLanguageOptions;
|
|
6
|
+
exports.findLanguageOption = findLanguageOption;
|
|
7
|
+
exports.shouldShowLanguagePage = shouldShowLanguagePage;
|
|
8
|
+
exports.buildLanguagePage = buildLanguagePage;
|
|
9
|
+
exports.fetchTranslation = fetchTranslation;
|
|
10
|
+
exports.applyTranslation = applyTranslation;
|
|
11
|
+
/** Slug the backend uses for the language-page prompt. */
|
|
12
|
+
exports.SCREENER_PROMPT_KEY = 'which-language-do-you-want-to-take-survey';
|
|
13
|
+
// ─── "Not translated" handling ────────────────────────────────────────────────
|
|
14
|
+
/** Backend sends null or "" for untranslated values; never let "null" through. */
|
|
15
|
+
function translatedText(value) {
|
|
16
|
+
if (typeof value !== 'string')
|
|
17
|
+
return undefined;
|
|
18
|
+
const trimmed = value.trim();
|
|
19
|
+
if (!trimmed || trimmed === 'null' || trimmed === 'undefined')
|
|
20
|
+
return undefined;
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
function normalizeDirection(dir) {
|
|
24
|
+
return String(dir !== null && dir !== void 0 ? dir : '').toLowerCase() === 'rtl' ? 'rtl' : 'ltr';
|
|
25
|
+
}
|
|
26
|
+
// ─── Language options ─────────────────────────────────────────────────────────
|
|
27
|
+
/** A survey with no translations still returns `languages: [{}]`, so require a langKey. */
|
|
28
|
+
function isUsableLanguage(entry) {
|
|
29
|
+
return !!entry && !!translatedText(entry.langKey) && entry.isHidden !== true;
|
|
30
|
+
}
|
|
31
|
+
function buildLanguageOptions(data) {
|
|
32
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
33
|
+
const options = [];
|
|
34
|
+
const primary = data.primaryLang;
|
|
35
|
+
const primaryKey = translatedText(primary === null || primary === void 0 ? void 0 : primary.langKey);
|
|
36
|
+
if (primary && primaryKey && primary.isHidden !== true) {
|
|
37
|
+
options.push({
|
|
38
|
+
langKey: primaryKey,
|
|
39
|
+
name: (_a = primary.name) !== null && _a !== void 0 ? _a : primaryKey,
|
|
40
|
+
nativeText: (_c = (_b = translatedText(primary.nativeText)) !== null && _b !== void 0 ? _b : primary.name) !== null && _c !== void 0 ? _c : primaryKey,
|
|
41
|
+
direction: normalizeDirection(primary.dir),
|
|
42
|
+
langId: primary.langId,
|
|
43
|
+
isPrimary: true,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
for (const entry of (_d = data.languages) !== null && _d !== void 0 ? _d : []) {
|
|
47
|
+
if (!isUsableLanguage(entry))
|
|
48
|
+
continue;
|
|
49
|
+
const langKey = translatedText(entry.langKey);
|
|
50
|
+
if (options.some(o => o.langKey.toLowerCase() === langKey.toLowerCase()))
|
|
51
|
+
continue;
|
|
52
|
+
const script = (_e = entry.langScript) !== null && _e !== void 0 ? _e : undefined;
|
|
53
|
+
options.push({
|
|
54
|
+
langKey,
|
|
55
|
+
name: (_f = entry.name) !== null && _f !== void 0 ? _f : langKey,
|
|
56
|
+
nativeText: (_h = (_g = translatedText(script === null || script === void 0 ? void 0 : script.nativeText)) !== null && _g !== void 0 ? _g : translatedText(entry.name)) !== null && _h !== void 0 ? _h : langKey,
|
|
57
|
+
direction: normalizeDirection(script === null || script === void 0 ? void 0 : script.direction),
|
|
58
|
+
langId: entry.langId,
|
|
59
|
+
translationId: entry.translations,
|
|
60
|
+
isPrimary: false,
|
|
61
|
+
scriptStrings: (_j = script === null || script === void 0 ? void 0 : script.textMapping) !== null && _j !== void 0 ? _j : undefined,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return options;
|
|
65
|
+
}
|
|
66
|
+
function findLanguageOption(data, langKey) {
|
|
67
|
+
var _a;
|
|
68
|
+
const wanted = (_a = translatedText(langKey)) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
69
|
+
if (!wanted)
|
|
70
|
+
return undefined;
|
|
71
|
+
return buildLanguageOptions(data).find(o => o.langKey.toLowerCase() === wanted);
|
|
72
|
+
}
|
|
73
|
+
/** Show the page when changing is allowed, a real alternative exists, and no valid language was passed. */
|
|
74
|
+
function shouldShowLanguagePage(data, language) {
|
|
75
|
+
var _a;
|
|
76
|
+
if (((_a = data.langSettings) === null || _a === void 0 ? void 0 : _a.allowChange) !== true)
|
|
77
|
+
return false;
|
|
78
|
+
const options = buildLanguageOptions(data);
|
|
79
|
+
if (options.filter(o => !o.isPrimary).length === 0)
|
|
80
|
+
return false;
|
|
81
|
+
return !findLanguageOption(data, language);
|
|
82
|
+
}
|
|
83
|
+
/** One prompt per screenerTextLang key; the primary uses screenerText, others their langScript. */
|
|
84
|
+
function buildLanguagePage(data) {
|
|
85
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
86
|
+
const options = buildLanguageOptions(data);
|
|
87
|
+
const screenerText = translatedText((_a = data.langSettings) === null || _a === void 0 ? void 0 : _a.screenerText);
|
|
88
|
+
const keys = (_c = (_b = data.langSettings) === null || _b === void 0 ? void 0 : _b.screenerTextLang) !== null && _c !== void 0 ? _c : [];
|
|
89
|
+
const prompts = [];
|
|
90
|
+
for (const key of keys) {
|
|
91
|
+
const normalized = (_d = translatedText(key)) === null || _d === void 0 ? void 0 : _d.toLowerCase();
|
|
92
|
+
if (!normalized)
|
|
93
|
+
continue;
|
|
94
|
+
const option = options.find(o => o.langKey.toLowerCase() === normalized);
|
|
95
|
+
const text = (option === null || option === void 0 ? void 0 : option.isPrimary)
|
|
96
|
+
? screenerText
|
|
97
|
+
: translatedText((_e = option === null || option === void 0 ? void 0 : option.scriptStrings) === null || _e === void 0 ? void 0 : _e[exports.SCREENER_PROMPT_KEY]);
|
|
98
|
+
if (!text)
|
|
99
|
+
continue;
|
|
100
|
+
if (prompts.some(p => p.text === text))
|
|
101
|
+
continue;
|
|
102
|
+
prompts.push({ langKey: (_f = option === null || option === void 0 ? void 0 : option.langKey) !== null && _f !== void 0 ? _f : normalized, text, direction: (_g = option === null || option === void 0 ? void 0 : option.direction) !== null && _g !== void 0 ? _g : 'ltr' });
|
|
103
|
+
}
|
|
104
|
+
if (prompts.length === 0 && screenerText) {
|
|
105
|
+
prompts.push({ langKey: (_j = (_h = options[0]) === null || _h === void 0 ? void 0 : _h.langKey) !== null && _j !== void 0 ? _j : 'en', text: screenerText, direction: 'ltr' });
|
|
106
|
+
}
|
|
107
|
+
return { prompts, options };
|
|
108
|
+
}
|
|
109
|
+
/** PUT getLanguage; works unauthenticated but we send the token when we have one. */
|
|
110
|
+
async function fetchTranslation(baseURL, surveyId, option, bearerToken) {
|
|
111
|
+
var _a, _b, _c, _d, _e, _f;
|
|
112
|
+
const url = `${baseURL}/v3/survey-participation/getLanguage`;
|
|
113
|
+
const headers = {
|
|
114
|
+
'Content-Type': 'application/json',
|
|
115
|
+
'X-SERVICE-NAME': 'survey-frontend-service',
|
|
116
|
+
};
|
|
117
|
+
if (bearerToken)
|
|
118
|
+
headers.Authorization = `Bearer ${bearerToken}`;
|
|
119
|
+
const res = await fetch(url, {
|
|
120
|
+
method: 'PUT',
|
|
121
|
+
headers,
|
|
122
|
+
body: JSON.stringify({
|
|
123
|
+
languageId: (_a = option.langId) !== null && _a !== void 0 ? _a : '',
|
|
124
|
+
translationId: (_b = option.translationId) !== null && _b !== void 0 ? _b : '',
|
|
125
|
+
langKey: option.langKey,
|
|
126
|
+
surveyId,
|
|
127
|
+
responseId: '',
|
|
128
|
+
emdid: '',
|
|
129
|
+
}),
|
|
130
|
+
});
|
|
131
|
+
if (!res.ok) {
|
|
132
|
+
throw new Error(`[Xebo] getLanguage failed — HTTP ${res.status}`);
|
|
133
|
+
}
|
|
134
|
+
const json = await res.json();
|
|
135
|
+
const language = (_c = json === null || json === void 0 ? void 0 : json.language) !== null && _c !== void 0 ? _c : undefined;
|
|
136
|
+
return {
|
|
137
|
+
textMapping: (_e = (_d = language === null || language === void 0 ? void 0 : language.languageTranslation) === null || _d === void 0 ? void 0 : _d.textMapping) !== null && _e !== void 0 ? _e : {},
|
|
138
|
+
script: (_f = language === null || language === void 0 ? void 0 : language.languageScript) !== null && _f !== void 0 ? _f : undefined,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
// ─── Merging translations into the raw survey JSON ────────────────────────────
|
|
142
|
+
function isPlainObject(value) {
|
|
143
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
144
|
+
}
|
|
145
|
+
/** Options that collect free text keep their original label. */
|
|
146
|
+
function skipsOptionText(node) {
|
|
147
|
+
return node.hasAddTextAnswer === true || node.addText === true;
|
|
148
|
+
}
|
|
149
|
+
function setPlaceholder(node, value) {
|
|
150
|
+
if (isPlainObject(node.placeholder)) {
|
|
151
|
+
node.placeholder.text = value;
|
|
152
|
+
}
|
|
153
|
+
else if (typeof node.placeholder === 'string' || node.placeholder === null) {
|
|
154
|
+
node.placeholder = value;
|
|
155
|
+
}
|
|
156
|
+
const settings = node.settings;
|
|
157
|
+
if (isPlainObject(settings) && isPlainObject(settings.placeholder)) {
|
|
158
|
+
settings.placeholder.text = value;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/** Apply a uuid's translation entry to one question / option / column node. */
|
|
162
|
+
function applyNodeTranslation(node, entry) {
|
|
163
|
+
const title = translatedText(entry.title);
|
|
164
|
+
if (title !== undefined && 'title' in node) {
|
|
165
|
+
node.title = title;
|
|
166
|
+
if ('rawTitle' in node)
|
|
167
|
+
node.rawTitle = title;
|
|
168
|
+
}
|
|
169
|
+
const text = translatedText(entry.text);
|
|
170
|
+
if (text !== undefined && 'text' in node && !skipsOptionText(node)) {
|
|
171
|
+
node.text = text;
|
|
172
|
+
if ('rawText' in node)
|
|
173
|
+
node.rawText = text;
|
|
174
|
+
}
|
|
175
|
+
const desc = translatedText(entry.desc);
|
|
176
|
+
if (desc !== undefined && isPlainObject(node.description))
|
|
177
|
+
node.description.text = desc;
|
|
178
|
+
const helper = translatedText(entry.helperText);
|
|
179
|
+
if (helper !== undefined && isPlainObject(node.helperText))
|
|
180
|
+
node.helperText.text = helper;
|
|
181
|
+
const reqMsg = translatedText(entry.reqMsg);
|
|
182
|
+
if (reqMsg !== undefined && isPlainObject(node.required))
|
|
183
|
+
node.required.errMsg = reqMsg;
|
|
184
|
+
const placeholder = translatedText(entry.placeholder);
|
|
185
|
+
if (placeholder !== undefined)
|
|
186
|
+
setPlaceholder(node, placeholder);
|
|
187
|
+
const settings = node.settings;
|
|
188
|
+
if (isPlainObject(settings)) {
|
|
189
|
+
const nps = settings.nps;
|
|
190
|
+
if (isPlainObject(nps)) {
|
|
191
|
+
const left = translatedText(entry.leftLabel);
|
|
192
|
+
const right = translatedText(entry.rightLabel);
|
|
193
|
+
if (left !== undefined)
|
|
194
|
+
nps.leftLabel = left;
|
|
195
|
+
if (right !== undefined)
|
|
196
|
+
nps.rightLabel = right;
|
|
197
|
+
}
|
|
198
|
+
const slider = settings.slider;
|
|
199
|
+
if (isPlainObject(slider)) {
|
|
200
|
+
const min = translatedText(entry.minLabel);
|
|
201
|
+
const max = translatedText(entry.maxLabel);
|
|
202
|
+
if (min !== undefined)
|
|
203
|
+
slider.minLabel = min;
|
|
204
|
+
if (max !== undefined)
|
|
205
|
+
slider.maxLabel = max;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/** Survey-level keys live under the survey's own uuid. */
|
|
210
|
+
function applySurveyTranslation(data, entry) {
|
|
211
|
+
const title = translatedText(entry.title);
|
|
212
|
+
if (title !== undefined) {
|
|
213
|
+
data.title = title;
|
|
214
|
+
data.displayTitle = title;
|
|
215
|
+
}
|
|
216
|
+
if (isPlainObject(data.introPage)) {
|
|
217
|
+
const introText = translatedText(entry.introText);
|
|
218
|
+
const buttonText = translatedText(entry.buttonText);
|
|
219
|
+
if (introText !== undefined)
|
|
220
|
+
data.introPage.content = introText;
|
|
221
|
+
if (buttonText !== undefined)
|
|
222
|
+
data.introPage.buttonText = buttonText;
|
|
223
|
+
}
|
|
224
|
+
if (isPlainObject(data.thankYouPage)) {
|
|
225
|
+
const content = translatedText(entry.content);
|
|
226
|
+
if (content !== undefined)
|
|
227
|
+
data.thankYouPage.content = content;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/** Merge a textMapping into a copy of the raw survey, matching nodes by uuid. */
|
|
231
|
+
function applyTranslation(data, textMapping) {
|
|
232
|
+
const clone = JSON.parse(JSON.stringify(data));
|
|
233
|
+
if (!textMapping || Object.keys(textMapping).length === 0)
|
|
234
|
+
return clone;
|
|
235
|
+
const surveyUuid = clone.uuid;
|
|
236
|
+
const surveyEntry = surveyUuid ? textMapping[surveyUuid] : undefined;
|
|
237
|
+
if (surveyEntry)
|
|
238
|
+
applySurveyTranslation(clone, surveyEntry);
|
|
239
|
+
const seen = new Set();
|
|
240
|
+
const walk = (node) => {
|
|
241
|
+
if (Array.isArray(node)) {
|
|
242
|
+
node.forEach(walk);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
if (!isPlainObject(node) || seen.has(node))
|
|
246
|
+
return;
|
|
247
|
+
seen.add(node);
|
|
248
|
+
const uuid = node.uuid;
|
|
249
|
+
if (typeof uuid === 'string' && uuid !== surveyUuid) {
|
|
250
|
+
const entry = textMapping[uuid];
|
|
251
|
+
if (entry)
|
|
252
|
+
applyNodeTranslation(node, entry);
|
|
253
|
+
}
|
|
254
|
+
Object.values(node).forEach(walk);
|
|
255
|
+
};
|
|
256
|
+
Object.entries(clone).forEach(([key, value]) => {
|
|
257
|
+
if (key !== 'languages' && key !== 'primaryLang' && key !== 'langSettings')
|
|
258
|
+
walk(value);
|
|
259
|
+
});
|
|
260
|
+
return clone;
|
|
261
|
+
}
|
|
@@ -1,18 +1,28 @@
|
|
|
1
1
|
import { XeboSurvey, XeboAnswer, XeboUserData, XeboQualityFlags, XeboGeolocation, XeboDeviceInfo } from '../models/XeboModels';
|
|
2
|
-
import { APISurveyResponse } from '../models/XeboAPIModels';
|
|
2
|
+
import { APISurveyResponse, APISurveyData, APIQuestion } from '../models/XeboAPIModels';
|
|
3
3
|
export declare function resolveZone(zone: string): string;
|
|
4
4
|
export declare function buildBaseURL(resolvedZone: string): string;
|
|
5
5
|
export declare function buildFeedbackBaseURL(resolvedZone: string): string;
|
|
6
6
|
export declare function buildVerifyURL(): string;
|
|
7
7
|
export declare function verifyApiKey(verifyURL: string, zone: string, apiKey: string): Promise<string>;
|
|
8
8
|
export declare function stripHTML(raw: string | undefined): string;
|
|
9
|
-
|
|
9
|
+
/** Placeholders live on the question or under settings, as an object or a plain string. */
|
|
10
|
+
export declare function resolvePlaceholder(q: APIQuestion): string;
|
|
11
|
+
export interface ParseOptions {
|
|
12
|
+
/** Only true once a translation is merged in, so English output is unchanged. */
|
|
13
|
+
localized?: boolean;
|
|
14
|
+
langKey?: string;
|
|
15
|
+
direction?: 'ltr' | 'rtl';
|
|
16
|
+
}
|
|
17
|
+
export declare function parseSurvey(data: APISurveyResponse['data'], opts?: ParseOptions): XeboSurvey;
|
|
10
18
|
export interface CollectorInfo {
|
|
11
19
|
surveyId: string;
|
|
12
20
|
uuid: string;
|
|
13
21
|
mongoId: string;
|
|
14
22
|
}
|
|
15
23
|
export declare function fetchCollector(baseURL: string, collectorId: string, bearerToken: string): Promise<CollectorInfo>;
|
|
24
|
+
/** Returns the unparsed survey JSON so translations can be merged before parsing. */
|
|
25
|
+
export declare function fetchSurveyRaw(baseURL: string, surveyId: string, bearerToken: string): Promise<APISurveyData>;
|
|
16
26
|
export declare function fetchSurvey(baseURL: string, surveyId: string, bearerToken: string): Promise<XeboSurvey>;
|
|
17
27
|
export interface SubmitResult {
|
|
18
28
|
ok: boolean;
|
|
@@ -1 +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,
|
|
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,EACjB,aAAa,EACb,WAAW,EAEZ,MAAM,yBAAyB,CAAC;AAKjC,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,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AAC,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"}
|
|
@@ -6,11 +6,14 @@ exports.buildFeedbackBaseURL = buildFeedbackBaseURL;
|
|
|
6
6
|
exports.buildVerifyURL = buildVerifyURL;
|
|
7
7
|
exports.verifyApiKey = verifyApiKey;
|
|
8
8
|
exports.stripHTML = stripHTML;
|
|
9
|
+
exports.resolvePlaceholder = resolvePlaceholder;
|
|
9
10
|
exports.parseSurvey = parseSurvey;
|
|
10
11
|
exports.fetchCollector = fetchCollector;
|
|
12
|
+
exports.fetchSurveyRaw = fetchSurveyRaw;
|
|
11
13
|
exports.fetchSurvey = fetchSurvey;
|
|
12
14
|
exports.submitResponse = submitResponse;
|
|
13
15
|
const XeboModels_1 = require("../models/XeboModels");
|
|
16
|
+
const XeboStrings_1 = require("../i18n/XeboStrings");
|
|
14
17
|
// ─── URL helpers ──────────────────────────────────────────────────────────────
|
|
15
18
|
function resolveZone(zone) {
|
|
16
19
|
return zone;
|
|
@@ -63,6 +66,12 @@ function stripHTML(raw) {
|
|
|
63
66
|
.replace(/'/g, "'")
|
|
64
67
|
.trim();
|
|
65
68
|
}
|
|
69
|
+
/** Placeholders live on the question or under settings, as an object or a plain string. */
|
|
70
|
+
function resolvePlaceholder(q) {
|
|
71
|
+
var _a, _b, _c;
|
|
72
|
+
const own = typeof q.placeholder === 'string' ? q.placeholder : (_a = q.placeholder) === null || _a === void 0 ? void 0 : _a.text;
|
|
73
|
+
return stripHTML(own || ((_c = (_b = q.settings) === null || _b === void 0 ? void 0 : _b.placeholder) === null || _c === void 0 ? void 0 : _c.text) || undefined);
|
|
74
|
+
}
|
|
66
75
|
// ─── Question type mapping ────────────────────────────────────────────────────
|
|
67
76
|
function mapRatingStyle(apiType) {
|
|
68
77
|
const normalized = (apiType !== null && apiType !== void 0 ? apiType : '').toLowerCase().replace(/^animated_/, '');
|
|
@@ -102,8 +111,7 @@ function mapQuestionType(apiType) {
|
|
|
102
111
|
default: return XeboModels_1.XeboQuestionType.singleChoice;
|
|
103
112
|
}
|
|
104
113
|
}
|
|
105
|
-
|
|
106
|
-
function parseSurvey(data) {
|
|
114
|
+
function parseSurvey(data, opts = {}) {
|
|
107
115
|
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;
|
|
108
116
|
// Collect all follow-up question IDs (from NPS Pro configScale)
|
|
109
117
|
const followUpQuestionIds = new Set();
|
|
@@ -194,17 +202,17 @@ function parseSurvey(data) {
|
|
|
194
202
|
type,
|
|
195
203
|
title: stripHTML(q.title),
|
|
196
204
|
subtitle: stripHTML((_u = q.helperText) === null || _u === void 0 ? void 0 : _u.text),
|
|
197
|
-
placeholder:
|
|
198
|
-
isRequired: (
|
|
205
|
+
placeholder: resolvePlaceholder(q),
|
|
206
|
+
isRequired: (_w = (_v = q.required) === null || _v === void 0 ? void 0 : _v.enabled) !== null && _w !== void 0 ? _w : false,
|
|
199
207
|
options: rows.length > 0 ? rows : undefined,
|
|
200
208
|
columns: cols.length > 0 ? cols : undefined,
|
|
201
209
|
npsLabels: npsSettings
|
|
202
210
|
? {
|
|
203
211
|
lower: npsSettings.leftLabel,
|
|
204
212
|
upper: npsSettings.rightLabel,
|
|
205
|
-
detractorColor: (
|
|
206
|
-
passiveColor: (
|
|
207
|
-
promoterColor: (
|
|
213
|
+
detractorColor: (_x = npsSettings.colors) === null || _x === void 0 ? void 0 : _x.detractor,
|
|
214
|
+
passiveColor: (_y = npsSettings.colors) === null || _y === void 0 ? void 0 : _y.passive,
|
|
215
|
+
promoterColor: (_z = npsSettings.colors) === null || _z === void 0 ? void 0 : _z.promoter,
|
|
208
216
|
}
|
|
209
217
|
: undefined,
|
|
210
218
|
followUpQuestion: undefined,
|
|
@@ -212,19 +220,21 @@ function parseSurvey(data) {
|
|
|
212
220
|
ratingStyle: ratingSettings ? mapRatingStyle(ratingSettings.type) : undefined,
|
|
213
221
|
showColLabels: ratingSettings === null || ratingSettings === void 0 ? void 0 : ratingSettings.colLabel,
|
|
214
222
|
ratingColor: ratingSettings === null || ratingSettings === void 0 ? void 0 : ratingSettings.color,
|
|
223
|
+
requiredMessage: opts.localized ? stripHTML((_0 = q.required) === null || _0 === void 0 ? void 0 : _0.errMsg) || undefined : undefined,
|
|
215
224
|
};
|
|
216
225
|
console.log(`[Xebo] Parsed question [${type}]:`, JSON.stringify(parsed, null, 2));
|
|
217
226
|
questions.push(parsed);
|
|
218
227
|
}
|
|
219
228
|
}
|
|
220
229
|
// Append auto thank-you question
|
|
230
|
+
const strings = (0, XeboStrings_1.getStrings)();
|
|
221
231
|
const tyPage = data.thankYouPage;
|
|
222
232
|
const tyTitle = (tyPage === null || tyPage === void 0 ? void 0 : tyPage.enabled) && tyPage.content
|
|
223
233
|
? stripHTML(tyPage.content)
|
|
224
|
-
: 'Thank You!';
|
|
234
|
+
: (opts.localized ? strings.thankYouTitle : 'Thank You!');
|
|
225
235
|
const tySubtitle = (tyPage === null || tyPage === void 0 ? void 0 : tyPage.enabled) && tyPage.content
|
|
226
236
|
? undefined
|
|
227
|
-
: 'Your feedback is greatly appreciated.';
|
|
237
|
+
: (opts.localized ? strings.thankYouMessage : 'Your feedback is greatly appreciated.');
|
|
228
238
|
questions.push({
|
|
229
239
|
id: 'thank_you_auto',
|
|
230
240
|
type: XeboModels_1.XeboQuestionType.thankYou,
|
|
@@ -239,6 +249,8 @@ function parseSurvey(data) {
|
|
|
239
249
|
id: data.uuid,
|
|
240
250
|
name: data.displayTitle,
|
|
241
251
|
projectId: data.projectId,
|
|
252
|
+
langKey: opts.langKey,
|
|
253
|
+
direction: opts.direction,
|
|
242
254
|
questions,
|
|
243
255
|
introPage: introPageRaw
|
|
244
256
|
? {
|
|
@@ -284,7 +296,8 @@ async function fetchCollector(baseURL, collectorId, bearerToken) {
|
|
|
284
296
|
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
|
285
297
|
return info;
|
|
286
298
|
}
|
|
287
|
-
|
|
299
|
+
/** Returns the unparsed survey JSON so translations can be merged before parsing. */
|
|
300
|
+
async function fetchSurveyRaw(baseURL, surveyId, bearerToken) {
|
|
288
301
|
var _a, _b, _c;
|
|
289
302
|
const url = `${baseURL}/v3/survey-management/surveys/${surveyId}`;
|
|
290
303
|
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
|
@@ -302,7 +315,10 @@ async function fetchSurvey(baseURL, surveyId, bearerToken) {
|
|
|
302
315
|
if (!Array.isArray(json.data.blocks)) {
|
|
303
316
|
throw new Error(`[Xebo] fetchSurvey — 'blocks' missing. Keys: ${Object.keys(json.data)}`);
|
|
304
317
|
}
|
|
305
|
-
return
|
|
318
|
+
return json.data;
|
|
319
|
+
}
|
|
320
|
+
async function fetchSurvey(baseURL, surveyId, bearerToken) {
|
|
321
|
+
return parseSurvey(await fetchSurveyRaw(baseURL, surveyId, bearerToken));
|
|
306
322
|
}
|
|
307
323
|
async function submitResponse(feedbackBaseURL, surveyId, collectorUUID, bearerToken, answers, meta) {
|
|
308
324
|
var _a;
|
|
@@ -7,11 +7,14 @@ declare class SimpleEventEmitter {
|
|
|
7
7
|
removeAllListeners(event?: string): this;
|
|
8
8
|
}
|
|
9
9
|
import { XeboSurvey, XeboAnswer, XeboConfig, XeboThemeConfig, XeboUserData } from '../models/XeboModels';
|
|
10
|
+
import { XeboLanguagePageModel } from '../models/XeboLanguageModels';
|
|
10
11
|
export declare const XEBO_EVENTS: {
|
|
11
12
|
readonly SURVEY_LOADED: "survey_loaded";
|
|
12
13
|
readonly QUESTION_CHANGED: "question_changed";
|
|
13
14
|
readonly SURVEY_VISIBLE: "survey_visible";
|
|
14
15
|
readonly SURVEY_DISMISSED: "survey_dismissed";
|
|
16
|
+
readonly LANGUAGE_PAGE: "language_page";
|
|
17
|
+
readonly LANGUAGE_SELECTED: "language_selected";
|
|
15
18
|
};
|
|
16
19
|
declare class XeboSurveyManagerClass extends SimpleEventEmitter {
|
|
17
20
|
private apiKey;
|
|
@@ -31,6 +34,12 @@ declare class XeboSurveyManagerClass extends SimpleEventEmitter {
|
|
|
31
34
|
resolvedCollectorUUID: string;
|
|
32
35
|
resolvedCollectorMongoId: string;
|
|
33
36
|
surveyVisible: boolean;
|
|
37
|
+
private rawSurveyData;
|
|
38
|
+
private resolvedSurveyId;
|
|
39
|
+
private onLanguageSelected?;
|
|
40
|
+
languagePage: XeboLanguagePageModel | null;
|
|
41
|
+
/** Bumped on dismiss and on each pick, so a stale translation never opens the survey. */
|
|
42
|
+
private languageLoadToken;
|
|
34
43
|
private surveyStartEpoch;
|
|
35
44
|
private questionStartEpoch;
|
|
36
45
|
private timePerQues;
|
|
@@ -43,7 +52,19 @@ declare class XeboSurveyManagerClass extends SimpleEventEmitter {
|
|
|
43
52
|
private _startNetworkMonitoring;
|
|
44
53
|
private _verifyAndGetToken;
|
|
45
54
|
private _prefetchSurvey;
|
|
46
|
-
|
|
55
|
+
/** Resolves token + collector + raw survey JSON, and parses the primary language. */
|
|
56
|
+
private _loadSurveyData;
|
|
57
|
+
/** Collector-driven flow; `language` (e.g. "ar") skips the language page. */
|
|
58
|
+
fetchAndPresentSurvey(language?: string): Promise<void>;
|
|
59
|
+
/** Same flow for an explicit survey, still using the configured collector to submit. */
|
|
60
|
+
fetchAndPresentSurveyById(surveyId: string, language?: string): Promise<void>;
|
|
61
|
+
private _present;
|
|
62
|
+
private _presentLanguagePage;
|
|
63
|
+
/** Called by the language page; loads the translation then swaps in the first question. */
|
|
64
|
+
selectLanguage(langKey: string): Promise<void>;
|
|
65
|
+
private _presentInLanguage;
|
|
66
|
+
private _resolveDirection;
|
|
67
|
+
private _resetSession;
|
|
47
68
|
recordAnswer(answer: XeboAnswer): void;
|
|
48
69
|
nextQuestion(): void;
|
|
49
70
|
private _buildQualityFlags;
|
|
@@ -1 +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;
|
|
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,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