@magicfeedback/popup-sdk 1.0.10 → 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
@@ -12,29 +12,33 @@ interface DeepdotsInitParams {
12
12
  debug?: boolean;
13
13
  /** Lista de definiciones de popups precargadas */
14
14
  popups?: PopupDefinition[];
15
+ /** Optional user id to send with popup events */
16
+ userId?: string;
15
17
  }
16
18
  interface DeepdotsConfig {
17
19
  /** API key for authentication */
18
20
  apiKey?: string;
19
- /** Base url to contact with the api */
20
- baseUrl?: string;
21
21
  /** Execution mode: 'server' or 'client' */
22
22
  mode?: 'server' | 'client';
23
23
  /** Enable debug logging */
24
24
  debug?: boolean;
25
25
  /** Lista de definiciones de popups precargadas */
26
26
  popups?: PopupDefinition[];
27
+ /** Optional user id to send with popup events */
28
+ userId?: string;
27
29
  }
28
30
  /**
29
31
  * Options for configuring survey triggers
30
32
  */
31
33
  interface TriggerConfig {
32
- /** Trigger type: 'time' (delay), 'scroll' (scroll percentage), 'exit' (exit intent) */
33
- type: 'time' | 'scroll' | 'exit';
34
- /** Value for the trigger (milliseconds for time, percentage for scroll) */
35
- value?: number;
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
+ value?: number | string;
36
38
  /** Survey ID to show when triggered */
37
39
  surveyId: string;
40
+ /** Optional popup definition id (used to disambiguate repeated survey ids) */
41
+ popupId?: string;
38
42
  }
39
43
  /**
40
44
  * Options for showing a popup
@@ -65,17 +69,18 @@ interface DeepdotsEvent {
65
69
  */
66
70
  type EventListener = (event: DeepdotsEvent) => void;
67
71
  /** Tipo de trigger específico para definiciones de popup remotas */
68
- type PopupTriggerType = 'time_on_page' | 'scroll' | 'exit';
72
+ type PopupTriggerType = 'time_on_page' | 'scroll' | 'exit' | 'click' | 'event';
73
+ type PopupTriggerConditionStatus = 'SHOWED' | 'PARTIAL' | 'COMPLETED';
74
+ declare const POPUP_TRIGGER_CONDITION_STATUSES: PopupTriggerConditionStatus[];
69
75
  /** Condición adicional para la activación del popup */
70
76
  interface PopupTriggerCondition {
71
- answered: boolean;
77
+ answered: PopupTriggerConditionStatus;
72
78
  cooldownDays: number;
73
79
  }
74
80
  /** Trigger asociado a la definición del popup */
75
81
  interface PopupTrigger {
76
82
  type: PopupTriggerType;
77
- value: number;
78
- condition?: PopupTriggerCondition[];
83
+ value: number | string;
79
84
  }
80
85
  /** Acción de aceptar (abrir encuesta) */
81
86
  interface PopupActionAccept {
@@ -123,7 +128,8 @@ interface PopupDefinition {
123
128
  id: string;
124
129
  title: string;
125
130
  message: string;
126
- trigger: PopupTrigger;
131
+ triggers: PopupTrigger[];
132
+ cooldown?: PopupTriggerCondition[];
127
133
  actions?: PopupActions;
128
134
  surveyId: string;
129
135
  productId: string;
@@ -135,7 +141,7 @@ interface PopupRenderer {
135
141
  /** Preparar recursos si aplica */
136
142
  init?(): void;
137
143
  /** Mostrar popup */
138
- show(surveyId: string, productId: string, actions: PopupActions | undefined, emit: (type: DeepdotsEventType, surveyId: string, data?: Record<string, unknown>) => void, onClose: () => void): void;
144
+ show(surveyId: string, productId: string, actions: PopupActions | undefined, emit: (type: DeepdotsEventType, surveyId: string, data?: Record<string, unknown>) => void, onClose: () => void, env?: string): void;
139
145
  /** Ocultar popup */
140
146
  hide(): void;
141
147
  }
@@ -154,7 +160,12 @@ declare class DeepdotsPopups {
154
160
  private popupsLoaded;
155
161
  private pendingAutoLaunch;
156
162
  private answeredSurveys;
163
+ private surveyProgress;
157
164
  private lastShown;
165
+ private surveyToPopupId;
166
+ private deferredExitTimers;
167
+ private baseUrl;
168
+ private env;
158
169
  /** Initialize the SDK with configuration */
159
170
  init(config: DeepdotsInitParams): void;
160
171
  /** Enable auto-launch functionality with configured triggers */
@@ -174,15 +185,30 @@ declare class DeepdotsPopups {
174
185
  /** Deriva triggers desde las definiciones de popup */
175
186
  private configureTriggersFromDefinitions;
176
187
  /** Lógica para evaluar condiciones antes de mostrar una encuesta */
177
- 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;
178
192
  private shouldShow;
179
- private evaluateCondition;
193
+ private matchesSegmentsPath;
194
+ private evaluateCooldown;
195
+ private evaluateLegacyCondition;
196
+ private hasCooldownElapsed;
180
197
  /** Marcar encuesta como contestada externamente */
181
198
  markSurveyAnswered(surveyId: string): void;
182
- /** Simula fetch al servidor para obtener popups */
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;
208
+ /** Fetch al servidor para obtener popups */
183
209
  private fetchPopupsFromServer;
184
- /** Genera datos fake para pruebas en modo server */
185
- private generateFakePopups;
210
+ /** Notifica eventos de popup a la API */
211
+ private postPopupEvent;
186
212
  /** Add an event listener */
187
213
  on(eventType: DeepdotsEventType, listener: EventListener): void;
188
214
  /** Remove an event listener */
@@ -201,8 +227,20 @@ declare class DeepdotsPopups {
201
227
  debug(...args: unknown[]): void;
202
228
  /** Set a custom renderer */
203
229
  setRenderer(renderer: PopupRenderer): void;
230
+ private normalizeUrl;
231
+ private safeParseUrl;
232
+ private mapPopupTriggerType;
233
+ private markSurveyProgress;
204
234
  private isPopupDefinition;
235
+ private isPopupTrigger;
236
+ private isPopupTriggerType;
237
+ private isPopupTriggerCondition;
238
+ private isLegacyPopupTriggerCondition;
239
+ private normalizeTriggers;
240
+ private normalizeCooldown;
241
+ private normalizeLegacyConditions;
242
+ private normalizePopupDefinition;
205
243
  private validatePopupDefinitions;
206
244
  }
207
245
 
208
- 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
@@ -12,29 +12,33 @@ interface DeepdotsInitParams {
12
12
  debug?: boolean;
13
13
  /** Lista de definiciones de popups precargadas */
14
14
  popups?: PopupDefinition[];
15
+ /** Optional user id to send with popup events */
16
+ userId?: string;
15
17
  }
16
18
  interface DeepdotsConfig {
17
19
  /** API key for authentication */
18
20
  apiKey?: string;
19
- /** Base url to contact with the api */
20
- baseUrl?: string;
21
21
  /** Execution mode: 'server' or 'client' */
22
22
  mode?: 'server' | 'client';
23
23
  /** Enable debug logging */
24
24
  debug?: boolean;
25
25
  /** Lista de definiciones de popups precargadas */
26
26
  popups?: PopupDefinition[];
27
+ /** Optional user id to send with popup events */
28
+ userId?: string;
27
29
  }
28
30
  /**
29
31
  * Options for configuring survey triggers
30
32
  */
31
33
  interface TriggerConfig {
32
- /** Trigger type: 'time' (delay), 'scroll' (scroll percentage), 'exit' (exit intent) */
33
- type: 'time' | 'scroll' | 'exit';
34
- /** Value for the trigger (milliseconds for time, percentage for scroll) */
35
- value?: number;
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
+ value?: number | string;
36
38
  /** Survey ID to show when triggered */
37
39
  surveyId: string;
40
+ /** Optional popup definition id (used to disambiguate repeated survey ids) */
41
+ popupId?: string;
38
42
  }
39
43
  /**
40
44
  * Options for showing a popup
@@ -65,17 +69,18 @@ interface DeepdotsEvent {
65
69
  */
66
70
  type EventListener = (event: DeepdotsEvent) => void;
67
71
  /** Tipo de trigger específico para definiciones de popup remotas */
68
- type PopupTriggerType = 'time_on_page' | 'scroll' | 'exit';
72
+ type PopupTriggerType = 'time_on_page' | 'scroll' | 'exit' | 'click' | 'event';
73
+ type PopupTriggerConditionStatus = 'SHOWED' | 'PARTIAL' | 'COMPLETED';
74
+ declare const POPUP_TRIGGER_CONDITION_STATUSES: PopupTriggerConditionStatus[];
69
75
  /** Condición adicional para la activación del popup */
70
76
  interface PopupTriggerCondition {
71
- answered: boolean;
77
+ answered: PopupTriggerConditionStatus;
72
78
  cooldownDays: number;
73
79
  }
74
80
  /** Trigger asociado a la definición del popup */
75
81
  interface PopupTrigger {
76
82
  type: PopupTriggerType;
77
- value: number;
78
- condition?: PopupTriggerCondition[];
83
+ value: number | string;
79
84
  }
80
85
  /** Acción de aceptar (abrir encuesta) */
81
86
  interface PopupActionAccept {
@@ -123,7 +128,8 @@ interface PopupDefinition {
123
128
  id: string;
124
129
  title: string;
125
130
  message: string;
126
- trigger: PopupTrigger;
131
+ triggers: PopupTrigger[];
132
+ cooldown?: PopupTriggerCondition[];
127
133
  actions?: PopupActions;
128
134
  surveyId: string;
129
135
  productId: string;
@@ -135,7 +141,7 @@ interface PopupRenderer {
135
141
  /** Preparar recursos si aplica */
136
142
  init?(): void;
137
143
  /** Mostrar popup */
138
- show(surveyId: string, productId: string, actions: PopupActions | undefined, emit: (type: DeepdotsEventType, surveyId: string, data?: Record<string, unknown>) => void, onClose: () => void): void;
144
+ show(surveyId: string, productId: string, actions: PopupActions | undefined, emit: (type: DeepdotsEventType, surveyId: string, data?: Record<string, unknown>) => void, onClose: () => void, env?: string): void;
139
145
  /** Ocultar popup */
140
146
  hide(): void;
141
147
  }
@@ -154,7 +160,12 @@ declare class DeepdotsPopups {
154
160
  private popupsLoaded;
155
161
  private pendingAutoLaunch;
156
162
  private answeredSurveys;
163
+ private surveyProgress;
157
164
  private lastShown;
165
+ private surveyToPopupId;
166
+ private deferredExitTimers;
167
+ private baseUrl;
168
+ private env;
158
169
  /** Initialize the SDK with configuration */
159
170
  init(config: DeepdotsInitParams): void;
160
171
  /** Enable auto-launch functionality with configured triggers */
@@ -174,15 +185,30 @@ declare class DeepdotsPopups {
174
185
  /** Deriva triggers desde las definiciones de popup */
175
186
  private configureTriggersFromDefinitions;
176
187
  /** Lógica para evaluar condiciones antes de mostrar una encuesta */
177
- 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;
178
192
  private shouldShow;
179
- private evaluateCondition;
193
+ private matchesSegmentsPath;
194
+ private evaluateCooldown;
195
+ private evaluateLegacyCondition;
196
+ private hasCooldownElapsed;
180
197
  /** Marcar encuesta como contestada externamente */
181
198
  markSurveyAnswered(surveyId: string): void;
182
- /** Simula fetch al servidor para obtener popups */
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;
208
+ /** Fetch al servidor para obtener popups */
183
209
  private fetchPopupsFromServer;
184
- /** Genera datos fake para pruebas en modo server */
185
- private generateFakePopups;
210
+ /** Notifica eventos de popup a la API */
211
+ private postPopupEvent;
186
212
  /** Add an event listener */
187
213
  on(eventType: DeepdotsEventType, listener: EventListener): void;
188
214
  /** Remove an event listener */
@@ -201,8 +227,20 @@ declare class DeepdotsPopups {
201
227
  debug(...args: unknown[]): void;
202
228
  /** Set a custom renderer */
203
229
  setRenderer(renderer: PopupRenderer): void;
230
+ private normalizeUrl;
231
+ private safeParseUrl;
232
+ private mapPopupTriggerType;
233
+ private markSurveyProgress;
204
234
  private isPopupDefinition;
235
+ private isPopupTrigger;
236
+ private isPopupTriggerType;
237
+ private isPopupTriggerCondition;
238
+ private isLegacyPopupTriggerCondition;
239
+ private normalizeTriggers;
240
+ private normalizeCooldown;
241
+ private normalizeLegacyConditions;
242
+ private normalizePopupDefinition;
205
243
  private validatePopupDefinitions;
206
244
  }
207
245
 
208
- 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 };