@product7/feedback-sdk 1.4.9 → 1.5.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.
@@ -720,11 +720,20 @@
720
720
  return { success: true, data: MOCK_SURVEYS };
721
721
  }
722
722
 
723
+ const respondent = this._getRespondentContext(context);
724
+
723
725
  const params = {
724
726
  url:
725
727
  context.url ||
726
728
  (typeof window !== 'undefined' ? window.location.href : ''),
727
729
  ...getDeviceInfo(),
730
+ ...(respondent.respondent_id && {
731
+ respondent_id: respondent.respondent_id,
732
+ }),
733
+ ...(respondent.email && { email: respondent.email }),
734
+ ...(context.includeEligibility !== undefined && {
735
+ include_eligibility: context.includeEligibility,
736
+ }),
728
737
  ...(context.userProperties && {
729
738
  user_properties: context.userProperties,
730
739
  }),
@@ -742,6 +751,19 @@
742
751
  });
743
752
  }
744
753
 
754
+ _getRespondentContext(context = {}) {
755
+ const userContext =
756
+ typeof this.api.getUserContext === 'function'
757
+ ? this.api.getUserContext() || {}
758
+ : {};
759
+
760
+ return {
761
+ respondent_id:
762
+ context.respondentId || context.userId || userContext.user_id || null,
763
+ email: context.email || userContext.email || null,
764
+ };
765
+ }
766
+
745
767
  async submitSurveyResponse(surveyId, responseData) {
746
768
  if (!surveyId) throw new APIError$1(400, 'Survey ID is required');
747
769
 
@@ -760,10 +782,16 @@
760
782
  };
761
783
  }
762
784
 
785
+ const respondent = this._getRespondentContext(responseData);
786
+
763
787
  const payload = {
764
788
  rating: responseData.rating,
765
789
  feedback: responseData.feedback || '',
766
790
  answers: responseData.answers || {},
791
+ ...(respondent.respondent_id && {
792
+ respondent_id: respondent.respondent_id,
793
+ }),
794
+ ...(respondent.email && { email: respondent.email }),
767
795
  };
768
796
 
769
797
  return this.api._handleAuthRetry(async () => {
@@ -3499,7 +3527,10 @@
3499
3527
  }
3500
3528
 
3501
3529
  _getMessageAttachmentsSignature(message) {
3502
- if (!Array.isArray(message?.attachments) || message.attachments.length === 0) {
3530
+ if (
3531
+ !Array.isArray(message?.attachments) ||
3532
+ message.attachments.length === 0
3533
+ ) {
3503
3534
  return '';
3504
3535
  }
3505
3536
 
@@ -4402,7 +4433,7 @@
4402
4433
 
4403
4434
  <div class="messenger-chat-compose">
4404
4435
  <button class="sdk-btn-icon messenger-compose-attach" aria-label="Attach file">
4405
- <i class="ph ph-paperclip"></i>
4436
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256"><rect width="16" height="16" fill="none"/><path d="M160,80,76.69,164.69a16,16,0,0,0,22.63,22.62L198.63,86.63a32,32,0,0,0-45.26-45.26L54.06,142.06a48,48,0,0,0,67.88,67.88L204,128" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"/></svg>
4406
4437
  </button>
4407
4438
  <div class="messenger-compose-input-wrapper">
4408
4439
  <textarea class="messenger-compose-input" placeholder="${placeholder}" rows="1"></textarea>
@@ -7392,7 +7423,11 @@
7392
7423
 
7393
7424
  try {
7394
7425
  const result = await this.apiService.getActiveSurveys(context);
7395
- return result.data || [];
7426
+ const surveys = result.data || [];
7427
+ if (context.includeIneligible) {
7428
+ return surveys;
7429
+ }
7430
+ return surveys.filter((survey) => this._isSurveyEligible(survey));
7396
7431
  } catch (error) {
7397
7432
  this.eventBus.emit('sdk:error', { error });
7398
7433
  throw new SDKError(
@@ -7409,7 +7444,12 @@
7409
7444
  );
7410
7445
  }
7411
7446
 
7412
- const surveys = await this.getActiveSurveys();
7447
+ const { context = {}, ...displayOptions } = options;
7448
+ const surveys = await this.getActiveSurveys({
7449
+ ...context,
7450
+ includeEligibility: true,
7451
+ includeIneligible: true,
7452
+ });
7413
7453
  const surveyConfig = surveys.find((s) => s.id === surveyId);
7414
7454
 
7415
7455
  if (!surveyConfig) {
@@ -7418,6 +7458,15 @@
7418
7458
  );
7419
7459
  }
7420
7460
 
7461
+ if (!this._isSurveyEligible(surveyConfig)) {
7462
+ this.eventBus.emit('survey:suppressed', {
7463
+ surveyId,
7464
+ reason: this._getSurveyIneligibilityReason(surveyConfig),
7465
+ survey: surveyConfig,
7466
+ });
7467
+ return null;
7468
+ }
7469
+
7421
7470
  return this.showSurvey({
7422
7471
  surveyId: surveyConfig.id,
7423
7472
  surveyType: surveyConfig.type,
@@ -7426,7 +7475,7 @@
7426
7475
  lowLabel: surveyConfig.low_label,
7427
7476
  highLabel: surveyConfig.high_label,
7428
7477
  customQuestions: surveyConfig.questions,
7429
- ...options,
7478
+ ...displayOptions,
7430
7479
  });
7431
7480
  }
7432
7481
 
@@ -7437,6 +7486,15 @@
7437
7486
  );
7438
7487
  }
7439
7488
 
7489
+ if (!this._isSurveyEligible(options)) {
7490
+ this.eventBus.emit('survey:suppressed', {
7491
+ surveyId: options.surveyId || options.id || null,
7492
+ reason: this._getSurveyIneligibilityReason(options),
7493
+ survey: options,
7494
+ });
7495
+ return null;
7496
+ }
7497
+
7440
7498
  const surveyWidget = this.createWidget('survey', {
7441
7499
  surveyId: options.surveyId,
7442
7500
  surveyType: options.surveyType || options.type || 'nps',
@@ -7457,6 +7515,56 @@
7457
7515
  return surveyWidget;
7458
7516
  }
7459
7517
 
7518
+ _isSurveyEligible(survey = {}) {
7519
+ const shouldShow = this._getSurveyField(survey, ['shouldShow', 'should_show']);
7520
+ if (typeof shouldShow === 'boolean') {
7521
+ return shouldShow;
7522
+ }
7523
+
7524
+ const eligible = this._getSurveyField(survey, [
7525
+ 'eligible',
7526
+ 'isEligible',
7527
+ 'is_eligible',
7528
+ ]);
7529
+ if (typeof eligible === 'boolean') {
7530
+ return eligible;
7531
+ }
7532
+
7533
+ const isAnswered = this._getSurveyField(survey, ['isAnswered', 'is_answered']);
7534
+ if (typeof isAnswered === 'boolean') {
7535
+ return !isAnswered;
7536
+ }
7537
+
7538
+ return true;
7539
+ }
7540
+
7541
+ _getSurveyIneligibilityReason(survey = {}) {
7542
+ const explicitReason = this._getSurveyField(survey, [
7543
+ 'reason',
7544
+ 'suppressionReason',
7545
+ 'suppression_reason',
7546
+ ]);
7547
+ if (explicitReason) {
7548
+ return explicitReason;
7549
+ }
7550
+
7551
+ const isAnswered = this._getSurveyField(survey, ['isAnswered', 'is_answered']);
7552
+ if (isAnswered === true) {
7553
+ return 'already_answered';
7554
+ }
7555
+
7556
+ return 'ineligible';
7557
+ }
7558
+
7559
+ _getSurveyField(survey, fields) {
7560
+ for (const field of fields) {
7561
+ if (survey[field] !== undefined && survey[field] !== null) {
7562
+ return survey[field];
7563
+ }
7564
+ }
7565
+ return null;
7566
+ }
7567
+
7460
7568
  showChangelog(options = {}) {
7461
7569
  if (!this.initialized) {
7462
7570
  throw new SDKError(