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.
- package/dist/components/XeboDropdownView.d.ts +6 -2
- package/dist/components/XeboDropdownView.d.ts.map +1 -1
- package/dist/components/XeboDropdownView.js +35 -22
- 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 +4 -2
- package/dist/components/XeboMultiNPSView.d.ts.map +1 -1
- package/dist/components/XeboMultiNPSView.js +32 -23
- package/dist/components/XeboMultiRatingView.d.ts +4 -2
- package/dist/components/XeboMultiRatingView.d.ts.map +1 -1
- package/dist/components/XeboMultiRatingView.js +31 -22
- package/dist/components/XeboMultipleChoiceView.d.ts +6 -2
- package/dist/components/XeboMultipleChoiceView.d.ts.map +1 -1
- package/dist/components/XeboMultipleChoiceView.js +43 -44
- package/dist/components/XeboNPSView.d.ts +8 -2
- package/dist/components/XeboNPSView.d.ts.map +1 -1
- package/dist/components/XeboNPSView.js +315 -55
- package/dist/components/XeboPageView.d.ts +33 -0
- package/dist/components/XeboPageView.d.ts.map +1 -0
- package/dist/components/XeboPageView.js +190 -0
- package/dist/components/XeboRatingView.d.ts +20 -2
- package/dist/components/XeboRatingView.d.ts.map +1 -1
- package/dist/components/XeboRatingView.js +71 -43
- package/dist/components/XeboSingleChoiceView.d.ts +8 -2
- package/dist/components/XeboSingleChoiceView.d.ts.map +1 -1
- package/dist/components/XeboSingleChoiceView.js +50 -46
- package/dist/components/XeboSurveyModal.d.ts.map +1 -1
- package/dist/components/XeboSurveyModal.js +236 -42
- package/dist/components/XeboTextBoxView.d.ts +4 -2
- package/dist/components/XeboTextBoxView.d.ts.map +1 -1
- package/dist/components/XeboTextBoxView.js +35 -23
- 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 +267 -0
- package/dist/core/XeboNetworkService.d.ts +24 -3
- package/dist/core/XeboNetworkService.d.ts.map +1 -1
- package/dist/core/XeboNetworkService.js +202 -69
- package/dist/core/XeboOfflineQueue.d.ts +2 -1
- package/dist/core/XeboOfflineQueue.d.ts.map +1 -1
- package/dist/core/XeboOfflineQueue.js +24 -10
- package/dist/core/XeboSurveyManager.d.ts +38 -2
- package/dist/core/XeboSurveyManager.d.ts.map +1 -1
- package/dist/core/XeboSurveyManager.js +246 -72
- package/dist/i18n/XeboRtl.d.ts +16 -0
- package/dist/i18n/XeboRtl.d.ts.map +1 -0
- package/dist/i18n/XeboRtl.js +32 -0
- package/dist/i18n/XeboStrings.d.ts +35 -0
- package/dist/i18n/XeboStrings.d.ts.map +1 -0
- package/dist/i18n/XeboStrings.js +73 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/models/XeboAPIModels.d.ts +103 -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 +93 -2
- package/dist/models/XeboModels.d.ts.map +1 -1
- package/dist/models/XeboModels.js +24 -0
- package/package.json +5 -5
|
@@ -37,6 +37,7 @@ exports.XeboThankYouView = void 0;
|
|
|
37
37
|
const react_1 = __importStar(require("react"));
|
|
38
38
|
const react_native_1 = require("react-native");
|
|
39
39
|
const XeboTheme_1 = require("../theme/XeboTheme");
|
|
40
|
+
const XeboRtl_1 = require("../i18n/XeboRtl");
|
|
40
41
|
const XeboThankYouView = ({ question, onDismiss }) => {
|
|
41
42
|
const theme = (0, XeboTheme_1.getTheme)();
|
|
42
43
|
const fadeAnim = (0, react_1.useRef)(new react_native_1.Animated.Value(0)).current;
|
|
@@ -68,11 +69,11 @@ const XeboThankYouView = ({ question, onDismiss }) => {
|
|
|
68
69
|
<react_native_1.Text style={styles.checkmark}>✓</react_native_1.Text>
|
|
69
70
|
</react_native_1.View>
|
|
70
71
|
|
|
71
|
-
<react_native_1.Text style={[styles.title, { color: theme.textColor, fontFamily: theme.fontFamily }]}>
|
|
72
|
+
<react_native_1.Text style={[styles.title, { color: theme.textColor, fontFamily: theme.fontFamily }, (0, XeboRtl_1.rtlText)()]}>
|
|
72
73
|
{question.title}
|
|
73
74
|
</react_native_1.Text>
|
|
74
75
|
|
|
75
|
-
{!!question.subtitle && (<react_native_1.Text style={[styles.subtitle, { color: theme.textColor, fontFamily: theme.fontFamily }]}>
|
|
76
|
+
{!!question.subtitle && (<react_native_1.Text style={[styles.subtitle, { color: theme.textColor, fontFamily: theme.fontFamily }, (0, XeboRtl_1.rtlText)()]}>
|
|
76
77
|
{question.subtitle}
|
|
77
78
|
</react_native_1.Text>)}
|
|
78
79
|
</react_native_1.Animated.View>);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { APILangScript, APILanguageEntry, APILangSettings, APIPrimaryLang, XeboLanguageOption, XeboLanguagePageModel, XeboTextMapping } from '../models/XeboLanguageModels';
|
|
2
|
+
/** Slug the backend uses for the language-page prompt. */
|
|
3
|
+
export declare const SCREENER_PROMPT_KEY = "which-language-do-you-want-to-take-survey";
|
|
4
|
+
/** Survey JSON carrying the language blocks; kept loose so we can merge into it. */
|
|
5
|
+
export interface RawSurveyData {
|
|
6
|
+
uuid?: string;
|
|
7
|
+
primaryLang?: APIPrimaryLang | null;
|
|
8
|
+
languages?: APILanguageEntry[] | null;
|
|
9
|
+
langSettings?: APILangSettings | null;
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
}
|
|
12
|
+
/** Backend sends null or "" for untranslated values; never let "null" through. */
|
|
13
|
+
export declare function translatedText(value: unknown): string | undefined;
|
|
14
|
+
export declare function buildLanguageOptions(data: RawSurveyData): XeboLanguageOption[];
|
|
15
|
+
export declare function findLanguageOption(data: RawSurveyData, langKey: string | undefined): XeboLanguageOption | undefined;
|
|
16
|
+
/** Show the page when changing is allowed, a real alternative exists, and no valid language was passed. */
|
|
17
|
+
export declare function shouldShowLanguagePage(data: RawSurveyData, language?: string): boolean;
|
|
18
|
+
/** One prompt per screenerTextLang key; the primary uses screenerText, others their langScript. */
|
|
19
|
+
export declare function buildLanguagePage(data: RawSurveyData): XeboLanguagePageModel;
|
|
20
|
+
export interface TranslationBundle {
|
|
21
|
+
textMapping: XeboTextMapping;
|
|
22
|
+
script: APILangScript | undefined;
|
|
23
|
+
}
|
|
24
|
+
/** PUT getLanguage; works unauthenticated but we send the token when we have one. */
|
|
25
|
+
export declare function fetchTranslation(baseURL: string, surveyId: string, option: XeboLanguageOption, bearerToken?: string): Promise<TranslationBundle>;
|
|
26
|
+
/** Merge a textMapping into a copy of the raw survey, matching nodes by uuid. */
|
|
27
|
+
export declare function applyTranslation<T extends RawSurveyData>(data: T, textMapping: XeboTextMapping): T;
|
|
28
|
+
//# sourceMappingURL=XeboLanguageService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"XeboLanguageService.d.ts","sourceRoot":"","sources":["../../src/core/XeboLanguageService.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,qBAAqB,EAGrB,eAAe,EAChB,MAAM,8BAA8B,CAAC;AAEtC,0DAA0D;AAC1D,eAAO,MAAM,mBAAmB,8CAA8C,CAAC;AAE/E,oFAAoF;AACpF,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;IACpC,SAAS,CAAC,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAAC;IACtC,YAAY,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;IACtC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAID,kFAAkF;AAClF,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAKjE;AAaD,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,aAAa,GAAG,kBAAkB,EAAE,CAmC9E;AAED,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,aAAa,EACnB,OAAO,EAAE,MAAM,GAAG,SAAS,GAC1B,kBAAkB,GAAG,SAAS,CAIhC;AAED,2GAA2G;AAC3G,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,aAAa,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAKtF;AAED,mGAAmG;AACnG,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,aAAa,GAAG,qBAAqB,CAuB5E;AAID,MAAM,WAAW,iBAAiB;IAChC,WAAW,EAAE,eAAe,CAAC;IAC7B,MAAM,EAAE,aAAa,GAAG,SAAS,CAAC;CACnC;AAED,qFAAqF;AACrF,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,kBAAkB,EAC1B,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,iBAAiB,CAAC,CA+B5B;AAiGD,iFAAiF;AACjF,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,aAAa,EAAE,IAAI,EAAE,CAAC,EAAE,WAAW,EAAE,eAAe,GAAG,CAAC,CA+BlG"}
|
|
@@ -0,0 +1,267 @@
|
|
|
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
|
+
const rules = data.completionRules;
|
|
230
|
+
if (isPlainObject(rules) && isPlainObject(rules.logicMeet)) {
|
|
231
|
+
const logicMeet = translatedText(entry.logicMeet);
|
|
232
|
+
if (logicMeet !== undefined)
|
|
233
|
+
rules.logicMeet.value = logicMeet;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/** Merge a textMapping into a copy of the raw survey, matching nodes by uuid. */
|
|
237
|
+
function applyTranslation(data, textMapping) {
|
|
238
|
+
const clone = JSON.parse(JSON.stringify(data));
|
|
239
|
+
if (!textMapping || Object.keys(textMapping).length === 0)
|
|
240
|
+
return clone;
|
|
241
|
+
const surveyUuid = clone.uuid;
|
|
242
|
+
const surveyEntry = surveyUuid ? textMapping[surveyUuid] : undefined;
|
|
243
|
+
if (surveyEntry)
|
|
244
|
+
applySurveyTranslation(clone, surveyEntry);
|
|
245
|
+
const seen = new Set();
|
|
246
|
+
const walk = (node) => {
|
|
247
|
+
if (Array.isArray(node)) {
|
|
248
|
+
node.forEach(walk);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
if (!isPlainObject(node) || seen.has(node))
|
|
252
|
+
return;
|
|
253
|
+
seen.add(node);
|
|
254
|
+
const uuid = node.uuid;
|
|
255
|
+
if (typeof uuid === 'string' && uuid !== surveyUuid) {
|
|
256
|
+
const entry = textMapping[uuid];
|
|
257
|
+
if (entry)
|
|
258
|
+
applyNodeTranslation(node, entry);
|
|
259
|
+
}
|
|
260
|
+
Object.values(node).forEach(walk);
|
|
261
|
+
};
|
|
262
|
+
Object.entries(clone).forEach(([key, value]) => {
|
|
263
|
+
if (key !== 'languages' && key !== 'primaryLang' && key !== 'langSettings')
|
|
264
|
+
walk(value);
|
|
265
|
+
});
|
|
266
|
+
return clone;
|
|
267
|
+
}
|
|
@@ -1,18 +1,38 @@
|
|
|
1
|
-
import { XeboSurvey, XeboAnswer, XeboUserData, XeboQualityFlags, XeboGeolocation, XeboDeviceInfo } from '../models/XeboModels';
|
|
2
|
-
import { APISurveyResponse } from '../models/XeboAPIModels';
|
|
1
|
+
import { XeboSurvey, XeboQuestion, XeboChoice, XeboSkipRule, XeboDelayedBranchRule, XeboCriteria, XeboAnswer, XeboUserData, XeboQualityFlags, XeboGeolocation, XeboDeviceInfo, XeboQueuedResponse } from '../models/XeboModels';
|
|
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
|
+
/** The survey's own button text, used for its primary language. */
|
|
12
|
+
export declare function primaryButtonLabels(data: APISurveyData): Record<'next' | 'submit' | 'ok' | 'previous', string | undefined>;
|
|
13
|
+
export interface ParseOptions {
|
|
14
|
+
/** Only true once a translation is merged in, so English output is unchanged. */
|
|
15
|
+
localized?: boolean;
|
|
16
|
+
langKey?: string;
|
|
17
|
+
direction?: 'ltr' | 'rtl';
|
|
18
|
+
}
|
|
19
|
+
export declare function parseSurvey(data: APISurveyResponse['data'], opts?: ParseOptions): XeboSurvey;
|
|
20
|
+
/** The skip rule matching this answer, or the "any other answer" rule. */
|
|
21
|
+
export declare function resolveSkipRule(question: XeboQuestion | undefined, answer: XeboAnswer | undefined): XeboSkipRule | undefined;
|
|
22
|
+
/** The delayed-branching rule whose criteria all answers so far meet, or the "otherwise" rule. */
|
|
23
|
+
export declare function resolveDelayedBranch(question: XeboQuestion | undefined, criteria: XeboCriteria[] | undefined, answers: XeboAnswer[]): XeboDelayedBranchRule | undefined;
|
|
24
|
+
/** False when the question has display logic and none of its criteria is met. */
|
|
25
|
+
export declare function isQuestionDisplayed(question: XeboQuestion, criteria: XeboCriteria[] | undefined, answers: XeboAnswer[]): boolean;
|
|
26
|
+
/** The options to show: one named by options display logic needs one of its rules' criteria met. */
|
|
27
|
+
export declare function visibleOptions(question: XeboQuestion, criteria: XeboCriteria[] | undefined, answers: XeboAnswer[]): XeboChoice[] | undefined;
|
|
10
28
|
export interface CollectorInfo {
|
|
11
29
|
surveyId: string;
|
|
12
30
|
uuid: string;
|
|
13
31
|
mongoId: string;
|
|
14
32
|
}
|
|
15
33
|
export declare function fetchCollector(baseURL: string, collectorId: string, bearerToken: string): Promise<CollectorInfo>;
|
|
34
|
+
/** Returns the unparsed survey JSON so translations can be merged before parsing. */
|
|
35
|
+
export declare function fetchSurveyRaw(baseURL: string, surveyId: string, bearerToken: string): Promise<APISurveyData>;
|
|
16
36
|
export declare function fetchSurvey(baseURL: string, surveyId: string, bearerToken: string): Promise<XeboSurvey>;
|
|
17
37
|
export interface SubmitResult {
|
|
18
38
|
ok: boolean;
|
|
@@ -29,6 +49,7 @@ export interface SubmitMeta {
|
|
|
29
49
|
qualityFlags?: XeboQualityFlags;
|
|
30
50
|
geolocation?: XeboGeolocation;
|
|
31
51
|
deviceInfo?: XeboDeviceInfo;
|
|
52
|
+
status?: XeboQueuedResponse['status'];
|
|
32
53
|
}
|
|
33
54
|
export declare function submitResponse(feedbackBaseURL: string, surveyId: string, collectorUUID: string, bearerToken: string, answers: XeboAnswer[], meta?: SubmitMeta): Promise<SubmitResult>;
|
|
34
55
|
//# sourceMappingURL=XeboNetworkService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"XeboNetworkService.d.ts","sourceRoot":"","sources":["../../src/core/XeboNetworkService.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,
|
|
1
|
+
{"version":3,"file":"XeboNetworkService.d.ts","sourceRoot":"","sources":["../../src/core/XeboNetworkService.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV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