@magicfeedback/popup-sdk 1.0.11 → 1.0.12

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/index.d.mts CHANGED
@@ -31,12 +31,14 @@ interface DeepdotsConfig {
31
31
  * Options for configuring survey triggers
32
32
  */
33
33
  interface TriggerConfig {
34
- /** Trigger type: 'time' (delay), 'scroll' (scroll percentage), 'exit' (exit intent), 'click' (element id) */
35
- type: 'time' | 'scroll' | 'exit' | 'click';
36
- /** Value for the trigger (milliseconds for time, percentage for scroll, element id for click) */
34
+ /** Trigger type: 'time' (delay), 'scroll' (scroll percentage), 'exit' (route exit), 'click' (element id), 'event' (host event) */
35
+ type: 'time' | 'scroll' | 'exit' | 'click' | 'event';
36
+ /** Value for the trigger (milliseconds for time, percentage for scroll, seconds for exit, element id for click, event name for event) */
37
37
  value?: number | string;
38
38
  /** Survey ID to show when triggered */
39
39
  surveyId: string;
40
+ /** Optional popup definition id (used to disambiguate repeated survey ids) */
41
+ popupId?: string;
40
42
  }
41
43
  /**
42
44
  * Options for showing a popup
@@ -67,17 +69,18 @@ interface DeepdotsEvent {
67
69
  */
68
70
  type EventListener = (event: DeepdotsEvent) => void;
69
71
  /** Tipo de trigger específico para definiciones de popup remotas */
70
- type PopupTriggerType = 'time_on_page' | 'scroll' | 'exit' | 'click';
72
+ type PopupTriggerType = 'time_on_page' | 'scroll' | 'exit' | 'click' | 'event';
73
+ type PopupTriggerConditionStatus = 'SHOWED' | 'PARTIAL' | 'COMPLETED';
74
+ declare const POPUP_TRIGGER_CONDITION_STATUSES: PopupTriggerConditionStatus[];
71
75
  /** Condición adicional para la activación del popup */
72
76
  interface PopupTriggerCondition {
73
- answered: boolean;
77
+ answered: PopupTriggerConditionStatus;
74
78
  cooldownDays: number;
75
79
  }
76
80
  /** Trigger asociado a la definición del popup */
77
81
  interface PopupTrigger {
78
82
  type: PopupTriggerType;
79
83
  value: number | string;
80
- condition?: PopupTriggerCondition[];
81
84
  }
82
85
  /** Acción de aceptar (abrir encuesta) */
83
86
  interface PopupActionAccept {
@@ -125,7 +128,8 @@ interface PopupDefinition {
125
128
  id: string;
126
129
  title: string;
127
130
  message: string;
128
- triggers: PopupTrigger;
131
+ triggers: PopupTrigger[];
132
+ cooldown?: PopupTriggerCondition[];
129
133
  actions?: PopupActions;
130
134
  surveyId: string;
131
135
  productId: string;
@@ -156,8 +160,10 @@ declare class DeepdotsPopups {
156
160
  private popupsLoaded;
157
161
  private pendingAutoLaunch;
158
162
  private answeredSurveys;
163
+ private surveyProgress;
159
164
  private lastShown;
160
165
  private surveyToPopupId;
166
+ private deferredExitTimers;
161
167
  private baseUrl;
162
168
  private env;
163
169
  /** Initialize the SDK with configuration */
@@ -179,12 +185,26 @@ declare class DeepdotsPopups {
179
185
  /** Deriva triggers desde las definiciones de popup */
180
186
  private configureTriggersFromDefinitions;
181
187
  /** Lógica para evaluar condiciones antes de mostrar una encuesta */
182
- triggerSurvey(surveyId: string): void;
188
+ triggerSurvey(surveyId: string, popupId?: string): void;
189
+ /** Trigger popups configured with trigger.type = 'event' and matching trigger.value */
190
+ triggerEvent(eventName: string): void;
191
+ private showDefinition;
183
192
  private shouldShow;
184
193
  private matchesSegmentsPath;
185
- private evaluateCondition;
194
+ private evaluateCooldown;
195
+ private evaluateLegacyCondition;
196
+ private hasCooldownElapsed;
186
197
  /** Marcar encuesta como contestada externamente */
187
198
  markSurveyAnswered(surveyId: string): void;
199
+ /** Queue an exit popup so it can render after navigation */
200
+ queueExitPopup(surveyId: string, delaySeconds: number, sourceUrl?: string, popupId?: string): void;
201
+ private processDeferredExitQueue;
202
+ private scheduleDeferredExitPopup;
203
+ private tryShowDeferredExitPopup;
204
+ private findPopupDefinition;
205
+ private removeDeferredExitPopup;
206
+ private getDeferredExitQueue;
207
+ private setDeferredExitQueue;
188
208
  /** Fetch al servidor para obtener popups */
189
209
  private fetchPopupsFromServer;
190
210
  /** Notifica eventos de popup a la API */
@@ -207,9 +227,20 @@ declare class DeepdotsPopups {
207
227
  debug(...args: unknown[]): void;
208
228
  /** Set a custom renderer */
209
229
  setRenderer(renderer: PopupRenderer): void;
230
+ private normalizeUrl;
231
+ private safeParseUrl;
232
+ private mapPopupTriggerType;
233
+ private markSurveyProgress;
210
234
  private isPopupDefinition;
235
+ private isPopupTrigger;
236
+ private isPopupTriggerType;
237
+ private isPopupTriggerCondition;
238
+ private isLegacyPopupTriggerCondition;
239
+ private normalizeTriggers;
240
+ private normalizeCooldown;
241
+ private normalizeLegacyConditions;
211
242
  private normalizePopupDefinition;
212
243
  private validatePopupDefinitions;
213
244
  }
214
245
 
215
- export { type DeepdotsConfig, type DeepdotsEvent, type DeepdotsEventType, DeepdotsPopups, type EventListener, type ShowOptions, type TriggerConfig };
246
+ export { type DeepdotsConfig, type DeepdotsEvent, type DeepdotsEventType, DeepdotsPopups, type EventListener, POPUP_TRIGGER_CONDITION_STATUSES, type PopupDefinition, type PopupTrigger, type PopupTriggerCondition, type PopupTriggerConditionStatus, type ShowOptions, type TriggerConfig };
package/dist/index.d.ts CHANGED
@@ -31,12 +31,14 @@ interface DeepdotsConfig {
31
31
  * Options for configuring survey triggers
32
32
  */
33
33
  interface TriggerConfig {
34
- /** Trigger type: 'time' (delay), 'scroll' (scroll percentage), 'exit' (exit intent), 'click' (element id) */
35
- type: 'time' | 'scroll' | 'exit' | 'click';
36
- /** Value for the trigger (milliseconds for time, percentage for scroll, element id for click) */
34
+ /** Trigger type: 'time' (delay), 'scroll' (scroll percentage), 'exit' (route exit), 'click' (element id), 'event' (host event) */
35
+ type: 'time' | 'scroll' | 'exit' | 'click' | 'event';
36
+ /** Value for the trigger (milliseconds for time, percentage for scroll, seconds for exit, element id for click, event name for event) */
37
37
  value?: number | string;
38
38
  /** Survey ID to show when triggered */
39
39
  surveyId: string;
40
+ /** Optional popup definition id (used to disambiguate repeated survey ids) */
41
+ popupId?: string;
40
42
  }
41
43
  /**
42
44
  * Options for showing a popup
@@ -67,17 +69,18 @@ interface DeepdotsEvent {
67
69
  */
68
70
  type EventListener = (event: DeepdotsEvent) => void;
69
71
  /** Tipo de trigger específico para definiciones de popup remotas */
70
- type PopupTriggerType = 'time_on_page' | 'scroll' | 'exit' | 'click';
72
+ type PopupTriggerType = 'time_on_page' | 'scroll' | 'exit' | 'click' | 'event';
73
+ type PopupTriggerConditionStatus = 'SHOWED' | 'PARTIAL' | 'COMPLETED';
74
+ declare const POPUP_TRIGGER_CONDITION_STATUSES: PopupTriggerConditionStatus[];
71
75
  /** Condición adicional para la activación del popup */
72
76
  interface PopupTriggerCondition {
73
- answered: boolean;
77
+ answered: PopupTriggerConditionStatus;
74
78
  cooldownDays: number;
75
79
  }
76
80
  /** Trigger asociado a la definición del popup */
77
81
  interface PopupTrigger {
78
82
  type: PopupTriggerType;
79
83
  value: number | string;
80
- condition?: PopupTriggerCondition[];
81
84
  }
82
85
  /** Acción de aceptar (abrir encuesta) */
83
86
  interface PopupActionAccept {
@@ -125,7 +128,8 @@ interface PopupDefinition {
125
128
  id: string;
126
129
  title: string;
127
130
  message: string;
128
- triggers: PopupTrigger;
131
+ triggers: PopupTrigger[];
132
+ cooldown?: PopupTriggerCondition[];
129
133
  actions?: PopupActions;
130
134
  surveyId: string;
131
135
  productId: string;
@@ -156,8 +160,10 @@ declare class DeepdotsPopups {
156
160
  private popupsLoaded;
157
161
  private pendingAutoLaunch;
158
162
  private answeredSurveys;
163
+ private surveyProgress;
159
164
  private lastShown;
160
165
  private surveyToPopupId;
166
+ private deferredExitTimers;
161
167
  private baseUrl;
162
168
  private env;
163
169
  /** Initialize the SDK with configuration */
@@ -179,12 +185,26 @@ declare class DeepdotsPopups {
179
185
  /** Deriva triggers desde las definiciones de popup */
180
186
  private configureTriggersFromDefinitions;
181
187
  /** Lógica para evaluar condiciones antes de mostrar una encuesta */
182
- triggerSurvey(surveyId: string): void;
188
+ triggerSurvey(surveyId: string, popupId?: string): void;
189
+ /** Trigger popups configured with trigger.type = 'event' and matching trigger.value */
190
+ triggerEvent(eventName: string): void;
191
+ private showDefinition;
183
192
  private shouldShow;
184
193
  private matchesSegmentsPath;
185
- private evaluateCondition;
194
+ private evaluateCooldown;
195
+ private evaluateLegacyCondition;
196
+ private hasCooldownElapsed;
186
197
  /** Marcar encuesta como contestada externamente */
187
198
  markSurveyAnswered(surveyId: string): void;
199
+ /** Queue an exit popup so it can render after navigation */
200
+ queueExitPopup(surveyId: string, delaySeconds: number, sourceUrl?: string, popupId?: string): void;
201
+ private processDeferredExitQueue;
202
+ private scheduleDeferredExitPopup;
203
+ private tryShowDeferredExitPopup;
204
+ private findPopupDefinition;
205
+ private removeDeferredExitPopup;
206
+ private getDeferredExitQueue;
207
+ private setDeferredExitQueue;
188
208
  /** Fetch al servidor para obtener popups */
189
209
  private fetchPopupsFromServer;
190
210
  /** Notifica eventos de popup a la API */
@@ -207,9 +227,20 @@ declare class DeepdotsPopups {
207
227
  debug(...args: unknown[]): void;
208
228
  /** Set a custom renderer */
209
229
  setRenderer(renderer: PopupRenderer): void;
230
+ private normalizeUrl;
231
+ private safeParseUrl;
232
+ private mapPopupTriggerType;
233
+ private markSurveyProgress;
210
234
  private isPopupDefinition;
235
+ private isPopupTrigger;
236
+ private isPopupTriggerType;
237
+ private isPopupTriggerCondition;
238
+ private isLegacyPopupTriggerCondition;
239
+ private normalizeTriggers;
240
+ private normalizeCooldown;
241
+ private normalizeLegacyConditions;
211
242
  private normalizePopupDefinition;
212
243
  private validatePopupDefinitions;
213
244
  }
214
245
 
215
- export { type DeepdotsConfig, type DeepdotsEvent, type DeepdotsEventType, DeepdotsPopups, type EventListener, type ShowOptions, type TriggerConfig };
246
+ export { type DeepdotsConfig, type DeepdotsEvent, type DeepdotsEventType, DeepdotsPopups, type EventListener, POPUP_TRIGGER_CONDITION_STATUSES, type PopupDefinition, type PopupTrigger, type PopupTriggerCondition, type PopupTriggerConditionStatus, type ShowOptions, type TriggerConfig };