@product7/feedback-sdk 1.6.6 → 1.6.7
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/feedback-sdk.js +116 -9
- package/dist/feedback-sdk.js.map +1 -1
- package/dist/feedback-sdk.min.js +1 -1
- package/dist/feedback-sdk.min.js.map +1 -1
- package/package.json +1 -1
- package/src/api/services/ChangelogService.js +1 -1
- package/src/api/services/HelpService.js +1 -1
- package/src/api/services/MessengerService.js +1 -1
- package/src/api/services/SurveyService.js +1 -1
- package/src/core/BaseAPIService.js +36 -4
- package/src/core/FeedbackSDK.js +60 -5
- package/src/widgets/BaseWidget.js +9 -0
- package/src/widgets/SurveyWidget.js +11 -0
- package/types/index.d.ts +7 -0
package/dist/feedback-sdk.js
CHANGED
|
@@ -921,15 +921,19 @@
|
|
|
921
921
|
body: JSON.stringify(payload),
|
|
922
922
|
headers: { 'Content-Type': 'application/json' },
|
|
923
923
|
});
|
|
924
|
+
const initData = this._extractInitResponseData(response);
|
|
924
925
|
|
|
925
|
-
this.sessionToken =
|
|
926
|
-
this.sessionExpiry = new Date(Date.now() +
|
|
926
|
+
this.sessionToken = initData.sessionToken;
|
|
927
|
+
this.sessionExpiry = new Date(Date.now() + initData.expiresIn * 1000);
|
|
927
928
|
this._storeSession();
|
|
928
929
|
|
|
929
930
|
return {
|
|
930
931
|
sessionToken: this.sessionToken,
|
|
931
|
-
config:
|
|
932
|
-
expiresIn:
|
|
932
|
+
config: initData.config,
|
|
933
|
+
expiresIn: initData.expiresIn,
|
|
934
|
+
status: initData.status,
|
|
935
|
+
message: initData.message,
|
|
936
|
+
configVersion: initData.configVersion,
|
|
933
937
|
};
|
|
934
938
|
} catch (error) {
|
|
935
939
|
throw new APIError$1(
|
|
@@ -940,6 +944,34 @@
|
|
|
940
944
|
}
|
|
941
945
|
}
|
|
942
946
|
|
|
947
|
+
_extractInitResponseData(response) {
|
|
948
|
+
const payload =
|
|
949
|
+
response && typeof response.data === 'object' ? response.data : response || {};
|
|
950
|
+
|
|
951
|
+
const sessionToken = payload.session_token || payload.sessionToken;
|
|
952
|
+
const expiresIn = Number(payload.expires_in ?? payload.expiresIn);
|
|
953
|
+
|
|
954
|
+
if (!sessionToken) {
|
|
955
|
+
throw new APIError$1(500, 'Invalid init response: missing session_token');
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
if (!Number.isFinite(expiresIn) || expiresIn <= 0) {
|
|
959
|
+
throw new APIError$1(500, 'Invalid init response: missing expires_in');
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
return {
|
|
963
|
+
sessionToken,
|
|
964
|
+
expiresIn,
|
|
965
|
+
config:
|
|
966
|
+
payload.config && typeof payload.config === 'object'
|
|
967
|
+
? payload.config
|
|
968
|
+
: {},
|
|
969
|
+
configVersion: payload.config_version ?? payload.configVersion ?? null,
|
|
970
|
+
status: response?.status ?? payload?.status ?? true,
|
|
971
|
+
message: response?.message ?? payload?.message ?? null,
|
|
972
|
+
};
|
|
973
|
+
}
|
|
974
|
+
|
|
943
975
|
async _ensureSession() {
|
|
944
976
|
if (!this.isSessionValid()) {
|
|
945
977
|
await this.init();
|
|
@@ -1725,6 +1757,15 @@
|
|
|
1725
1757
|
mount(container) {
|
|
1726
1758
|
if (this.mounted || this.destroyed) return this;
|
|
1727
1759
|
|
|
1760
|
+
if (this.options.enabled === false) {
|
|
1761
|
+
this.sdk.eventBus.emit('widget:suppressed', {
|
|
1762
|
+
widget: this,
|
|
1763
|
+
type: this.type,
|
|
1764
|
+
reason: 'disabled',
|
|
1765
|
+
});
|
|
1766
|
+
return this;
|
|
1767
|
+
}
|
|
1768
|
+
|
|
1728
1769
|
if (this.options.suppressAfterSubmission && this._hasRecentlySubmitted()) {
|
|
1729
1770
|
this.sdk.eventBus.emit('widget:suppressed', {
|
|
1730
1771
|
widget: this,
|
|
@@ -6824,6 +6865,8 @@
|
|
|
6824
6865
|
surveyId: options.surveyId || null,
|
|
6825
6866
|
surveyType: options.surveyType || 'nps',
|
|
6826
6867
|
position: options.position || 'bottom-right',
|
|
6868
|
+
enabled:
|
|
6869
|
+
typeof options.enabled === 'boolean' ? options.enabled : undefined,
|
|
6827
6870
|
title: options.title || null,
|
|
6828
6871
|
description: options.description || null,
|
|
6829
6872
|
lowLabel: options.lowLabel || null,
|
|
@@ -6877,6 +6920,15 @@
|
|
|
6877
6920
|
}
|
|
6878
6921
|
|
|
6879
6922
|
show() {
|
|
6923
|
+
if (this.options.enabled === false || this.surveyOptions.enabled === false) {
|
|
6924
|
+
this.sdk.eventBus.emit('survey:suppressed', {
|
|
6925
|
+
widget: this,
|
|
6926
|
+
surveyId: this.surveyOptions.surveyId,
|
|
6927
|
+
reason: 'disabled',
|
|
6928
|
+
});
|
|
6929
|
+
return this;
|
|
6930
|
+
}
|
|
6931
|
+
|
|
6880
6932
|
this._renderSurvey();
|
|
6881
6933
|
this.surveyState.isVisible = true;
|
|
6882
6934
|
this.sdk.eventBus.emit('survey:shown', {
|
|
@@ -8160,6 +8212,10 @@
|
|
|
8160
8212
|
const widgetId = generateId('widget');
|
|
8161
8213
|
const widgetConfig = this._getWidgetTypeConfig(type);
|
|
8162
8214
|
const explicitOptions = this._omitUndefined(options);
|
|
8215
|
+
const widgetEnabled = this._isWidgetEnabled(type, {
|
|
8216
|
+
...widgetConfig,
|
|
8217
|
+
...explicitOptions,
|
|
8218
|
+
});
|
|
8163
8219
|
const widgetOptions = {
|
|
8164
8220
|
id: widgetId,
|
|
8165
8221
|
sdk: this,
|
|
@@ -8167,6 +8223,7 @@
|
|
|
8167
8223
|
...this.config,
|
|
8168
8224
|
...widgetConfig,
|
|
8169
8225
|
...explicitOptions,
|
|
8226
|
+
enabled: widgetEnabled,
|
|
8170
8227
|
};
|
|
8171
8228
|
|
|
8172
8229
|
try {
|
|
@@ -8257,6 +8314,7 @@
|
|
|
8257
8314
|
surveyConfig.showDescription ?? surveyConfig.show_description,
|
|
8258
8315
|
customQuestions: surveyConfig.customQuestions || surveyConfig.questions,
|
|
8259
8316
|
pages: surveyConfig.pages,
|
|
8317
|
+
enabled: surveyConfig.enabled,
|
|
8260
8318
|
...displayOptions,
|
|
8261
8319
|
});
|
|
8262
8320
|
}
|
|
@@ -8279,6 +8337,17 @@
|
|
|
8279
8337
|
|
|
8280
8338
|
const normalizedOptions = this._normalizeSurveyConfig(options);
|
|
8281
8339
|
const surveyConfigDefaults = this._getWidgetTypeConfig('survey');
|
|
8340
|
+
const surveyEnabled = this._isWidgetEnabled('survey', normalizedOptions);
|
|
8341
|
+
|
|
8342
|
+
if (!surveyEnabled) {
|
|
8343
|
+
this.eventBus.emit('survey:suppressed', {
|
|
8344
|
+
surveyId:
|
|
8345
|
+
normalizedOptions.surveyId || normalizedOptions.id || options.id || null,
|
|
8346
|
+
reason: 'disabled',
|
|
8347
|
+
survey: normalizedOptions,
|
|
8348
|
+
});
|
|
8349
|
+
return null;
|
|
8350
|
+
}
|
|
8282
8351
|
|
|
8283
8352
|
const surveyWidget = this.createWidget('survey', {
|
|
8284
8353
|
surveyId: normalizedOptions.surveyId,
|
|
@@ -8310,6 +8379,7 @@
|
|
|
8310
8379
|
email: normalizedOptions.email,
|
|
8311
8380
|
onSubmit: normalizedOptions.onSubmit,
|
|
8312
8381
|
onDismiss: normalizedOptions.onDismiss,
|
|
8382
|
+
enabled: surveyEnabled,
|
|
8313
8383
|
});
|
|
8314
8384
|
|
|
8315
8385
|
surveyWidget.mount();
|
|
@@ -8403,13 +8473,19 @@
|
|
|
8403
8473
|
: {};
|
|
8404
8474
|
|
|
8405
8475
|
const inferredType =
|
|
8406
|
-
survey.
|
|
8476
|
+
survey.surveyType ||
|
|
8477
|
+
survey.survey_type ||
|
|
8478
|
+
survey.type ||
|
|
8479
|
+
this._inferSurveyTypeFromPage(firstPage) ||
|
|
8480
|
+
'nps';
|
|
8407
8481
|
|
|
8408
8482
|
return {
|
|
8409
8483
|
...survey,
|
|
8410
|
-
surveyId: survey.surveyId || survey.id || null,
|
|
8411
|
-
surveyType: survey.surveyType || inferredType,
|
|
8412
|
-
type: survey.type || inferredType,
|
|
8484
|
+
surveyId: survey.surveyId || survey.survey_id || survey.id || null,
|
|
8485
|
+
surveyType: survey.surveyType || survey.survey_type || inferredType,
|
|
8486
|
+
type: survey.type || survey.survey_type || inferredType,
|
|
8487
|
+
enabled:
|
|
8488
|
+
typeof survey.enabled === 'boolean' ? survey.enabled : undefined,
|
|
8413
8489
|
should_show:
|
|
8414
8490
|
survey.should_show ??
|
|
8415
8491
|
(survey.eligibility ? survey.eligibility.should_show : undefined),
|
|
@@ -8438,7 +8514,11 @@
|
|
|
8438
8514
|
showTitle: survey.showTitle ?? survey.show_title ?? null,
|
|
8439
8515
|
showDescription:
|
|
8440
8516
|
survey.showDescription ?? survey.show_description ?? null,
|
|
8441
|
-
customQuestions:
|
|
8517
|
+
customQuestions:
|
|
8518
|
+
survey.customQuestions ||
|
|
8519
|
+
survey.custom_questions ||
|
|
8520
|
+
survey.questions ||
|
|
8521
|
+
[],
|
|
8442
8522
|
pages: this._normalizeSurveyPages(survey.pages || []),
|
|
8443
8523
|
};
|
|
8444
8524
|
}
|
|
@@ -8513,6 +8593,23 @@
|
|
|
8513
8593
|
return this._toCamelCaseObject(mergedTypeConfig);
|
|
8514
8594
|
}
|
|
8515
8595
|
|
|
8596
|
+
_isWidgetEnabled(type, options = {}) {
|
|
8597
|
+
const typeConfig = this._getWidgetTypeConfig(type);
|
|
8598
|
+
if (typeConfig.enabled === false) {
|
|
8599
|
+
return false;
|
|
8600
|
+
}
|
|
8601
|
+
|
|
8602
|
+
if (typeof options.enabled === 'boolean') {
|
|
8603
|
+
return options.enabled;
|
|
8604
|
+
}
|
|
8605
|
+
|
|
8606
|
+
if (typeof typeConfig.enabled === 'boolean') {
|
|
8607
|
+
return typeConfig.enabled;
|
|
8608
|
+
}
|
|
8609
|
+
|
|
8610
|
+
return true;
|
|
8611
|
+
}
|
|
8612
|
+
|
|
8516
8613
|
_isPlainObject(value) {
|
|
8517
8614
|
return Object.prototype.toString.call(value) === '[object Object]';
|
|
8518
8615
|
}
|
|
@@ -8566,11 +8663,21 @@
|
|
|
8566
8663
|
|
|
8567
8664
|
const configDefaults = this._getWidgetTypeConfig('changelog');
|
|
8568
8665
|
const explicitOptions = this._omitUndefined(options);
|
|
8666
|
+
const changelogEnabled = this._isWidgetEnabled('changelog', explicitOptions);
|
|
8667
|
+
|
|
8668
|
+
if (!changelogEnabled) {
|
|
8669
|
+
this.eventBus.emit('widget:suppressed', {
|
|
8670
|
+
type: 'changelog',
|
|
8671
|
+
reason: 'disabled',
|
|
8672
|
+
});
|
|
8673
|
+
return null;
|
|
8674
|
+
}
|
|
8569
8675
|
|
|
8570
8676
|
const changelogWidget = this.createWidget('changelog', {
|
|
8571
8677
|
...defaults,
|
|
8572
8678
|
...configDefaults,
|
|
8573
8679
|
...explicitOptions,
|
|
8680
|
+
enabled: changelogEnabled,
|
|
8574
8681
|
});
|
|
8575
8682
|
|
|
8576
8683
|
changelogWidget.mount();
|