@sprig-technologies/sprig-browser 2.21.2 → 2.21.4

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.
Files changed (63) hide show
  1. package/LICENSE.md +176 -0
  2. package/dist/index.cjs +10 -10
  3. package/dist/index.d.ts +1049 -3
  4. package/dist/index.js +1145 -1098
  5. package/package.json +11 -7
  6. package/dist/sprig-browser/index.d.ts +0 -168
  7. package/dist/src/constants/css.d.ts +0 -43
  8. package/dist/src/constants/sprigEvents.d.ts +0 -62
  9. package/dist/src/constants/sprigRecordingEvents.d.ts +0 -40
  10. package/dist/src/controller/OptimizelyIntegration.d.ts +0 -40
  11. package/dist/src/controller/Queue.d.ts +0 -18
  12. package/dist/src/controller/controller.d.ts +0 -9
  13. package/dist/src/controller/iframe.d.ts +0 -17
  14. package/dist/src/helpers/Deferred.d.ts +0 -9
  15. package/dist/src/helpers/conflicting_widgets/index.d.ts +0 -4
  16. package/dist/src/helpers/conflicting_widgets/intercom.d.ts +0 -2
  17. package/dist/src/helpers/document.d.ts +0 -6
  18. package/dist/src/helpers/eventEmitter.d.ts +0 -85
  19. package/dist/src/helpers/general.d.ts +0 -9
  20. package/dist/src/helpers/network.d.ts +0 -15
  21. package/dist/src/types/card.d.ts +0 -297
  22. package/dist/src/types/config.d.ts +0 -233
  23. package/dist/src/types/event.d.ts +0 -18
  24. package/dist/src/types/global.d.ts +0 -260
  25. package/dist/src/view/app.d.ts +0 -3
  26. package/dist/src/view/cards/consentLegalCard.d.ts +0 -6
  27. package/dist/src/view/cards/index.d.ts +0 -10
  28. package/dist/src/view/cards/likertCard/index.d.ts +0 -1
  29. package/dist/src/view/cards/likertCard/likertCard.d.ts +0 -6
  30. package/dist/src/view/cards/likertCard/likertOption.d.ts +0 -16
  31. package/dist/src/view/cards/multipleChoice/baseMultiChoiceCard.d.ts +0 -15
  32. package/dist/src/view/cards/multipleChoice/index.d.ts +0 -2
  33. package/dist/src/view/cards/multipleChoice/multiSelectCard.d.ts +0 -5
  34. package/dist/src/view/cards/multipleChoice/singleSelectCard.d.ts +0 -5
  35. package/dist/src/view/cards/npsCard.d.ts +0 -8
  36. package/dist/src/view/cards/openTextCard.d.ts +0 -6
  37. package/dist/src/view/cards/recordedTask/actions.d.ts +0 -21
  38. package/dist/src/view/cards/recordedTask/card.d.ts +0 -5
  39. package/dist/src/view/cards/recordedTask/components.d.ts +0 -30
  40. package/dist/src/view/cards/recordedTask/constants.d.ts +0 -5
  41. package/dist/src/view/cards/recordedTask/helpers.d.ts +0 -6
  42. package/dist/src/view/cards/recordedTask/index.d.ts +0 -1
  43. package/dist/src/view/cards/recordedTask/store.d.ts +0 -24
  44. package/dist/src/view/cards/textUrlPromptCard.d.ts +0 -6
  45. package/dist/src/view/cards/thanksCard.d.ts +0 -5
  46. package/dist/src/view/cards/types.d.ts +0 -34
  47. package/dist/src/view/cards/uploadingCard.d.ts +0 -5
  48. package/dist/src/view/cards/videoVoiceCard.d.ts +0 -6
  49. package/dist/src/view/components/button.d.ts +0 -3
  50. package/dist/src/view/components/header.d.ts +0 -8
  51. package/dist/src/view/components/index.d.ts +0 -4
  52. package/dist/src/view/components/mobileEmbedView.d.ts +0 -16
  53. package/dist/src/view/components/option.d.ts +0 -22
  54. package/dist/src/view/footer.d.ts +0 -2
  55. package/dist/src/view/helpers/card.d.ts +0 -6
  56. package/dist/src/view/helpers/getAttributedUrl.d.ts +0 -6
  57. package/dist/src/view/helpers/skipLogicHelpers.d.ts +0 -34
  58. package/dist/src/view/hooks/index.d.ts +0 -1
  59. package/dist/src/view/hooks/useAutoSize.d.ts +0 -2
  60. package/dist/src/view/logo.d.ts +0 -5
  61. package/dist/src/view/recorder/recorder.d.ts +0 -2
  62. package/dist/src/view/store.d.ts +0 -2
  63. package/dist/src/view/view.d.ts +0 -6
package/dist/index.d.ts CHANGED
@@ -1,3 +1,1049 @@
1
- export * from './sprig-browser/index'
2
- import _default from './sprig-browser/index'
3
- export default _default
1
+ import { StrictEventEmitter } from 'strict-event-emitter';
2
+
3
+ declare enum DismissReason {
4
+ Closed = "close.click",
5
+ Complete = "survey.completed",
6
+ PageChange = "page.change",
7
+ API = "api",
8
+ Override = "override"
9
+ }
10
+ declare enum SprigEvent {
11
+ SDKReady = "sdk.ready",
12
+ SurveyAppeared = "survey.appeared",
13
+ SurveyClosed = "survey.closed",
14
+ SurveyDimensions = "survey.dimensions",
15
+ SurveyFadingOut = "survey.fadingOut",
16
+ SurveyHeight = "survey.height",
17
+ SurveyPresented = "survey.presented",
18
+ SurveyLifeCycle = "survey.lifeCycle",
19
+ SurveyWillClose = "survey.willClose",
20
+ SurveyWillPresent = "survey.will.present",
21
+ CloseSurveyOnOverlayClick = "close.survey.overlayClick",
22
+ VisitorIDUpdated = "visitor.id.updated"
23
+ }
24
+ declare enum SprigEventData {
25
+ SurveyId = "survey.id"
26
+ }
27
+ declare const EVENTS: {
28
+ SDK_READY: SprigEvent;
29
+ SURVEY_APPEARED: SprigEvent;
30
+ SURVEY_CLOSED: SprigEvent;
31
+ SURVEY_DIMENSIONS: SprigEvent;
32
+ SURVEY_FADING_OUT: SprigEvent;
33
+ SURVEY_HEIGHT: SprigEvent;
34
+ SURVEY_PRESENTED: SprigEvent;
35
+ SURVEY_LIFE_CYCLE: SprigEvent;
36
+ SURVEY_WILL_CLOSE: SprigEvent;
37
+ SURVEY_WILL_PRESENT: SprigEvent;
38
+ CLOSE_SURVEY_ON_OVERLAY_CLICK: SprigEvent;
39
+ VISITOR_ID_UPDATED: SprigEvent;
40
+ DATA: {
41
+ DISMISS_REASONS: {
42
+ API: DismissReason;
43
+ CLOSED: DismissReason;
44
+ COMPLETE: DismissReason;
45
+ PAGE_CHANGE: DismissReason;
46
+ OVERRIDE: DismissReason;
47
+ };
48
+ SURVEY_ID: SprigEventData;
49
+ };
50
+ };
51
+ declare const enum InternalEventName {
52
+ VerifyViewVersion = "verify.view.version",
53
+ CurrentQuestion = "survey.question",
54
+ ViewPrototypeClick = "question.prototype.click",
55
+ ViewAgreementClick = "question.agreement.click",
56
+ RecordedTaskStart = "recorded.task.start",
57
+ RecordedTaskPermissionScreen = "recorded.task.permission.screen",
58
+ SurveyComplete = "survey.complete"
59
+ }
60
+ declare const enum InternalEventData {
61
+ ViewVersion = "view.version",
62
+ QuestionId = "qid",
63
+ Props = "props"
64
+ }
65
+
66
+ declare const enum MediaType {
67
+ Video = "video",
68
+ Audio = "audio",
69
+ Screen = "screen"
70
+ }
71
+ declare const enum SprigRecordingEvent {
72
+ PermissionStatus = "permission.status",
73
+ AvPermission = "av.permission",
74
+ ScreenPermission = "screen.permission",
75
+ BeginRecording = "begin.recording",
76
+ StartTask = "start.task",
77
+ FinishTask = "finish.task"
78
+ }
79
+ declare const enum TaskStatus {
80
+ Abandoned = "abandoned",
81
+ GivenUp = "given.up",
82
+ Completed = "completed"
83
+ }
84
+ declare const enum SprigRecordingEventData {
85
+ PermissionDescriptors = "permission.descriptors",
86
+ PermissionStatusCallback = "permission.status.callback",
87
+ StreamReadyCallback = "stream.ready.callback",
88
+ StreamCanceledCallback = "stream.canceled.callback",
89
+ TaskCompleteCallback = "task.complete.callback",
90
+ TaskResponse = "task.response",
91
+ TaskStatus = "task.status",
92
+ RecordingMediaTypes = "recording.media.types",
93
+ StartRecordingCallback = "start.recording.callback",
94
+ PassthroughData = "passthrough.data",
95
+ CurrentIndex = "current.index",
96
+ UploadCallback = "upload.callback",
97
+ ProgressCallback = "progress.callback",
98
+ BeginCallback = "begin.callback"
99
+ }
100
+ interface PassthroughData {
101
+ questionId: number;
102
+ surveyId: number;
103
+ visitorId: string | null;
104
+ responseGroupUid: UUID;
105
+ }
106
+
107
+ declare const enum CardType {
108
+ ConsentLegal = "consentlegal",
109
+ Likert = "likert",
110
+ MultipleChoice = "multiplechoice",
111
+ MultipleSelect = "multipleselect",
112
+ NPS = "nps",
113
+ Open = "open",
114
+ RecordedTask = "recordedtask",
115
+ TextUrlPrompt = "texturlprompt",
116
+ Thanks = "thanks",
117
+ Uploading = "uploading",
118
+ VideoVoice = "videovoice"
119
+ }
120
+ declare type ConceptUrl = string | null;
121
+ interface BaseCard {
122
+ name: number;
123
+ surveyId: number;
124
+ updatedAt: string;
125
+ value?: unknown;
126
+ }
127
+ declare const enum Comparator {
128
+ Answered = "answered",
129
+ Equal = "eq",
130
+ NotEqual = "neq",
131
+ Skipped = "skipped",
132
+ LessThan = "lt",
133
+ LessThanOrEqual = "lte",
134
+ GivenUp = "given_up",
135
+ GreaterThan = "gt",
136
+ GreaterThanOrEqual = "gte",
137
+ ListAll = "list_all",
138
+ ListAtLeastOne = "list_alo",
139
+ ListExact = "list_exact"
140
+ }
141
+ declare type DefaultComparator = Comparator.Answered | Comparator.Skipped;
142
+ interface RoutingOption<C extends Comparator = DefaultComparator> {
143
+ comparator: C;
144
+ target: number;
145
+ /** @example '', 'option_2', ['option_1'] */
146
+ value: number | string | string[];
147
+ }
148
+ declare type RoutingOptions<C extends Comparator = DefaultComparator> = RoutingOption<C | DefaultComparator>[] | null;
149
+ /** @example <p>Body</p> */
150
+ declare type RichTextBody = string;
151
+ declare const enum PromptActionType {
152
+ Continue = "CONTINUE",
153
+ External = "EXTERNAL"
154
+ }
155
+ interface TextUrlPromptCard extends BaseCard {
156
+ props: {
157
+ message: string;
158
+ options: [];
159
+ properties: {
160
+ body: string;
161
+ buttonText?: string;
162
+ skipButtonText?: string;
163
+ buttonUrl?: string;
164
+ conceptUrl: ConceptUrl;
165
+ promptActionType: PromptActionType;
166
+ required: boolean;
167
+ richTextBody: RichTextBody;
168
+ };
169
+ routingOptions: RoutingOptions;
170
+ };
171
+ type: CardType.TextUrlPrompt;
172
+ }
173
+ declare const enum AvPermission {
174
+ Camera = "camera",
175
+ Microphone = "microphone",
176
+ Screen = "screen"
177
+ }
178
+ interface ConsentLegalCard extends BaseCard {
179
+ props: {
180
+ message: string;
181
+ options: [];
182
+ properties: {
183
+ body: string;
184
+ captionText: string;
185
+ collectName: boolean;
186
+ conceptUrl: ConceptUrl;
187
+ consentDocument?: {
188
+ originalFilename: string;
189
+ url: string;
190
+ };
191
+ consentText: string;
192
+ nameLabelText: string;
193
+ required: boolean;
194
+ richTextBody: RichTextBody;
195
+ skipButtonText: string;
196
+ submitButtonText: string;
197
+ };
198
+ routingOptions: RoutingOptions;
199
+ };
200
+ type: CardType.ConsentLegal;
201
+ }
202
+ interface BaseTaskPage {
203
+ buttonText: string;
204
+ headline: string;
205
+ }
206
+ declare const enum RecordedTaskPageType {
207
+ AvPermission = "av_permission",
208
+ ScreenPermission = "screen_permission",
209
+ StartTask = "start_task",
210
+ CompleteTask = "complete_task"
211
+ }
212
+ interface PermissionTaskPage extends BaseTaskPage {
213
+ captionText: string;
214
+ headline: string;
215
+ permissionDeniedBody: string;
216
+ permissionDeniedHeadline: string;
217
+ permissionDescriptors: AvPermission[];
218
+ permissionGrantedCaptionText?: string;
219
+ permissionGrantedHeadline?: string;
220
+ skipButtonText?: string;
221
+ svg: string;
222
+ tryAgainButtonText: string;
223
+ type: RecordedTaskPageType.AvPermission;
224
+ }
225
+ interface ScreenTaskPage extends BaseTaskPage {
226
+ captionText: string;
227
+ permissionDeniedCaptionText: string;
228
+ permissionDeniedHeadline: string;
229
+ selectTabText: string;
230
+ skipButtonText: string;
231
+ type: RecordedTaskPageType.ScreenPermission;
232
+ }
233
+ interface StartTaskPage extends BaseTaskPage {
234
+ captionText?: string;
235
+ taskDetail: string;
236
+ type: RecordedTaskPageType.StartTask;
237
+ }
238
+ interface CompleteTaskPage extends BaseTaskPage {
239
+ captionText?: string;
240
+ skipButtonText: string;
241
+ taskDetail: string;
242
+ type: RecordedTaskPageType.CompleteTask;
243
+ }
244
+ declare type RecordedTaskPage = PermissionTaskPage | ScreenTaskPage | StartTaskPage | CompleteTaskPage;
245
+ interface RecordedTaskCardProperties {
246
+ captionText: string;
247
+ conceptUrl: ConceptUrl;
248
+ pages: RecordedTaskPage[];
249
+ permissions: AvPermission[];
250
+ required: boolean;
251
+ taskDetail: string;
252
+ }
253
+ interface RecordedTaskCard extends BaseCard {
254
+ props: {
255
+ message: string;
256
+ options: [];
257
+ properties: RecordedTaskCardProperties;
258
+ routingOptions: RoutingOptions<Comparator.GivenUp>;
259
+ };
260
+ type: CardType.RecordedTask;
261
+ }
262
+ interface Labels {
263
+ left: string;
264
+ right: string;
265
+ }
266
+ interface RatingIcon {
267
+ idx?: number;
268
+ svg: string;
269
+ }
270
+ declare enum ScaleLabelType {
271
+ Number = "number",
272
+ Smiley = "smiley",
273
+ Star = "star"
274
+ }
275
+ interface LikertCard extends BaseCard {
276
+ props: {
277
+ labels: Labels;
278
+ message: string;
279
+ options: [];
280
+ properties: {
281
+ captionText: string;
282
+ buttonText?: string;
283
+ conceptUrl: ConceptUrl;
284
+ labels: Labels;
285
+ range: string;
286
+ ratingIcons: RatingIcon[];
287
+ scaleLabelType: ScaleLabelType;
288
+ required: boolean;
289
+ };
290
+ routingOptions: RoutingOptions<Comparator.Equal | Comparator.GivenUp | Comparator.GreaterThan | Comparator.GreaterThanOrEqual | Comparator.LessThan | Comparator.LessThanOrEqual | Comparator.NotEqual>;
291
+ };
292
+ type: CardType.Likert;
293
+ }
294
+ interface OpenTextCard extends BaseCard {
295
+ props: {
296
+ message: string;
297
+ options: [];
298
+ properties: {
299
+ body: string;
300
+ buttonText?: string;
301
+ captionText?: string;
302
+ conceptUrl: ConceptUrl;
303
+ openTextPlaceholder?: string;
304
+ required: boolean;
305
+ richTextBody: RichTextBody;
306
+ skipButtonText?: string;
307
+ };
308
+ routingOptions: RoutingOptions;
309
+ };
310
+ type: CardType.Open;
311
+ }
312
+ interface MultipleChoiceOption {
313
+ createdAt: string;
314
+ deletedAt: null;
315
+ id: number;
316
+ label: string;
317
+ optionProperties: null | {
318
+ allowsTextEntry: boolean;
319
+ };
320
+ order: number;
321
+ productId: number;
322
+ surveyId: number;
323
+ surveyQuestionId: number;
324
+ updatedAt: string;
325
+ value: string;
326
+ }
327
+ interface CommonMultipleChoiceProps {
328
+ message: string;
329
+ options: MultipleChoiceOption[];
330
+ properties: {
331
+ buttonText?: string;
332
+ captionText: string;
333
+ conceptUrl: ConceptUrl;
334
+ randomize: "none" | "keeplast" | "all";
335
+ required: boolean;
336
+ };
337
+ }
338
+ interface MultiChoiceCard<C extends Comparator = DefaultComparator> extends BaseCard {
339
+ props: CommonMultipleChoiceProps & {
340
+ routingOptions: RoutingOptions<C>;
341
+ };
342
+ }
343
+ interface MultipleChoiceSingleSelectCard extends MultiChoiceCard<Comparator.Equal | Comparator.NotEqual> {
344
+ type: CardType.MultipleChoice;
345
+ }
346
+ interface MultipleChoiceMultiSelectCard extends MultiChoiceCard<Comparator.ListAll | Comparator.ListAtLeastOne | Comparator.ListExact> {
347
+ type: CardType.MultipleSelect;
348
+ }
349
+ interface NPSCard extends BaseCard {
350
+ props: {
351
+ labels: {
352
+ left: string;
353
+ right: string;
354
+ };
355
+ message: string;
356
+ options: [];
357
+ properties: {
358
+ buttonText?: string;
359
+ captionText: string;
360
+ conceptUrl: null;
361
+ labels: {
362
+ left: string;
363
+ right: string;
364
+ };
365
+ required: boolean;
366
+ };
367
+ routingOptions: RoutingOptions<Comparator.Equal | Comparator.GreaterThan | Comparator.GreaterThanOrEqual | Comparator.LessThan | Comparator.LessThanOrEqual | Comparator.NotEqual>;
368
+ };
369
+ type: CardType.NPS;
370
+ }
371
+ interface VideoVoiceCard extends BaseCard {
372
+ props: {
373
+ message: string;
374
+ options: [];
375
+ properties: {
376
+ buttonText: string;
377
+ captionText: string;
378
+ conceptUrl: null;
379
+ mediaType: "video" | "audio";
380
+ required: boolean;
381
+ skipButtonText: string;
382
+ uploadId: string;
383
+ videoUrl: string;
384
+ };
385
+ routingOptions: RoutingOptions;
386
+ };
387
+ type: CardType.VideoVoice;
388
+ }
389
+ declare type Card = TextUrlPromptCard | ConsentLegalCard | RecordedTaskCard | LikertCard | OpenTextCard | MultipleChoiceSingleSelectCard | MultipleChoiceMultiSelectCard | NPSCard | VideoVoiceCard;
390
+
391
+ interface RecordedTaskResponseValueType {
392
+ mediaRecordingUids?: string[] | null;
393
+ taskDurationMillisecond?: number;
394
+ taskStatus: TaskStatus;
395
+ }
396
+
397
+ interface RecordedTaskResponseType {
398
+ questionId: number;
399
+ type: CardType;
400
+ value: RecordedTaskResponseValueType;
401
+ }
402
+
403
+ interface SprigEventMap {
404
+ [InternalEventName.CurrentQuestion]: (data: {
405
+ [InternalEventData.QuestionId]: number;
406
+ [InternalEventData.Props]: unknown;
407
+ }) => void;
408
+ [InternalEventName.RecordedTaskPermissionScreen]: () => void;
409
+ [InternalEventName.RecordedTaskStart]: () => void;
410
+ [InternalEventName.SurveyComplete]: () => void;
411
+ [InternalEventName.VerifyViewVersion]: (data: {
412
+ [InternalEventData.ViewVersion]: string;
413
+ }) => void;
414
+ [SprigEvent.CloseSurveyOnOverlayClick]: () => void;
415
+ [SprigEvent.SDKReady]: () => void;
416
+ [SprigEvent.SurveyAppeared]: () => void;
417
+ [SprigEvent.SurveyDimensions]: (data: {
418
+ contentFrameHeight: number;
419
+ contentFrameWidth: number;
420
+ name: string;
421
+ }) => void;
422
+ [SprigEvent.SurveyClosed]: (data: {
423
+ initiator?: unknown;
424
+ name: string;
425
+ }) => void;
426
+ [SprigEvent.SurveyFadingOut]: () => void;
427
+ [SprigEvent.SurveyHeight]: (data: {
428
+ name: string;
429
+ contentFrameHeight: number;
430
+ }) => void;
431
+ [SprigEvent.SurveyLifeCycle]: (data: {
432
+ state: string;
433
+ }) => void;
434
+ [SprigEvent.SurveyPresented]: (data: {
435
+ name: string;
436
+ }) => void;
437
+ [SprigEvent.SurveyWillClose]: (data: {
438
+ initiator: DismissReason;
439
+ name?: string;
440
+ }) => void;
441
+ [SprigEvent.SurveyWillPresent]: (data: {
442
+ name: string;
443
+ "survey.id": number;
444
+ }) => void;
445
+ [SprigEvent.VisitorIDUpdated]: (data: {
446
+ visitorId: string | null;
447
+ }) => void;
448
+ [SprigRecordingEvent.AvPermission]: (data: {
449
+ [SprigRecordingEventData.StreamCanceledCallback]: () => void;
450
+ [SprigRecordingEventData.StreamReadyCallback]: (avStream: MediaStream | null, captureStream?: MediaStream | null) => void;
451
+ [SprigRecordingEventData.PermissionDescriptors]: AvPermission[];
452
+ }) => void;
453
+ [SprigRecordingEvent.BeginRecording]: (data: {
454
+ [SprigRecordingEventData.RecordingMediaTypes]: MediaType[];
455
+ [SprigRecordingEventData.StartRecordingCallback]: (mediaRecordingUids: UUID[]) => void;
456
+ }) => void;
457
+ [SprigRecordingEvent.FinishTask]: (data: {
458
+ [SprigRecordingEventData.BeginCallback]: (mediaRecordingUid: UUID) => void;
459
+ [SprigRecordingEventData.CurrentIndex]: number;
460
+ [SprigRecordingEventData.PassthroughData]: PassthroughData;
461
+ [SprigRecordingEventData.ProgressCallback]: (mediaRecordingUid: UUID, data: {
462
+ detail: number;
463
+ }) => void;
464
+ [SprigRecordingEventData.TaskCompleteCallback]: (taskDurationMillisecond: number) => void;
465
+ [SprigRecordingEventData.TaskResponse]: RecordedTaskResponseType;
466
+ [SprigRecordingEventData.UploadCallback]: (mediaRecordingUid: UUID | null, successOrError: true | unknown) => void;
467
+ }) => void;
468
+ [SprigRecordingEvent.PermissionStatus]: (data: {
469
+ [SprigRecordingEventData.PermissionStatusCallback]: (avStream: MediaStream | undefined, hasVideoPermission: boolean, hasScreenPermission: boolean) => void;
470
+ }) => void;
471
+ [SprigRecordingEvent.ScreenPermission]: (data: {
472
+ [SprigRecordingEventData.StreamCanceledCallback]: () => void;
473
+ [SprigRecordingEventData.StreamReadyCallback]: (avStream: MediaStream | null, captureStream: MediaStream | null) => void;
474
+ }) => void;
475
+ [SprigRecordingEvent.StartTask]: () => void;
476
+ }
477
+ declare type SprigEventEmitter = StrictEventEmitter<SprigEventMap>;
478
+
479
+ declare type MatchType = "exactly" | "legacy";
480
+ interface InteractiveEvent {
481
+ id: number;
482
+ matchType: MatchType;
483
+ name: string;
484
+ pattern: string;
485
+ properties: {
486
+ innerText: string;
487
+ selector?: string;
488
+ type?: "click";
489
+ };
490
+ }
491
+ interface PageUrlEvent {
492
+ id: number;
493
+ matchType: MatchType | "contains" | "notContains" | "regex" | "startsWith";
494
+ pattern: string;
495
+ }
496
+
497
+ declare const enum FramePosition {
498
+ BottomLeft = "bottomLeft",
499
+ BottomRight = "bottomRight",
500
+ Center = "center",
501
+ TopLeft = "topLeft",
502
+ TopRight = "topRight"
503
+ }
504
+ declare const enum HttpHeader {
505
+ Error = "x-ul-error",
506
+ EnvironmentID = "x-ul-environment-id",
507
+ InstallationMethod = "x-ul-installation-method",
508
+ PartnerAnonymousId = "x-ul-anonymous-id",
509
+ Platform = "userleap-platform",
510
+ PreviewMode = "x-ul-preview-mode",
511
+ UserID = "x-ul-user-id",
512
+ VisitorID = "x-ul-visitor-id"
513
+ }
514
+ declare const enum Platform {
515
+ Email = "email",
516
+ Link = "link",
517
+ Web = "web"
518
+ }
519
+ declare const enum InstallationMethod {
520
+ Npm = "web-npm",
521
+ Gtm = "web-gtm",
522
+ Segment = "web-segment",
523
+ SegmentAndroid = "android-segment",
524
+ SegmentReactNative = "react-native-segment",
525
+ SegmentIOS = "ios-segment",
526
+ Snippet = "web-snippet"
527
+ }
528
+ interface Answer {
529
+ questionId: number;
530
+ value: unknown;
531
+ }
532
+ interface Config {
533
+ answers?: Answer[];
534
+ apiURL: string;
535
+ /** @example "#000000" */
536
+ border: string;
537
+ cards: Card[];
538
+ configureExitOnOverlayClick: (cb: () => void) => void;
539
+ context: {
540
+ outcome: string;
541
+ product: {
542
+ name: string;
543
+ };
544
+ visitor: {
545
+ outcome: string;
546
+ };
547
+ };
548
+ customMetadata?: Record<string, unknown>;
549
+ customStyles: string;
550
+ dismissOnPageChange: boolean;
551
+ endCard?: {
552
+ headline: string;
553
+ subheader?: string;
554
+ };
555
+ /** @example "SJcVfq-7QQ" */
556
+ envId: string;
557
+ environmentId?: string;
558
+ eventEmitFn: SprigEventEmitter["emit"];
559
+ fontFamily?: string;
560
+ fontFamilyURL: undefined;
561
+ frame: HTMLIFrameElement & {
562
+ eventEmitter?: SprigEventEmitter;
563
+ setHeight?: (height: number) => void;
564
+ };
565
+ framePosition: FramePosition;
566
+ headers: {
567
+ "accept-language"?: string;
568
+ /** @example "Bearer 123" */
569
+ Authorization?: string;
570
+ "Content-Type": string;
571
+ "userleap-platform": Platform;
572
+ /** @example "SJcVfq-7QQ" */
573
+ [HttpHeader.EnvironmentID]?: string;
574
+ [HttpHeader.InstallationMethod]: InstallationMethod;
575
+ [HttpHeader.PartnerAnonymousId]?: string;
576
+ [HttpHeader.PreviewMode]?: string;
577
+ /** @example "2.18.0" */
578
+ "x-ul-sdk-version": string;
579
+ [HttpHeader.UserID]?: string;
580
+ [HttpHeader.VisitorID]?: UUID;
581
+ };
582
+ installationMethod?: InstallationMethod;
583
+ interactiveEvents: InteractiveEvent[];
584
+ interactiveEventsHandler?: (e: MouseEvent) => void;
585
+ isPreview?: boolean;
586
+ locale: string;
587
+ marketingUrl?: string;
588
+ maxAttrNameLength: number;
589
+ maxAttrValueLength: number;
590
+ maxEmailLength: number;
591
+ maxEventLength: number;
592
+ maxUserIdLength: number;
593
+ mobileSDKVersion: undefined;
594
+ mode?: string;
595
+ mute?: boolean;
596
+ optimizelyEnabled: boolean;
597
+ overlayStyle: "light";
598
+ overlayStyleMobile: "none";
599
+ pageUrlEvents: PageUrlEvent[];
600
+ path?: string;
601
+ platform?: Platform;
602
+ requireUserIdForTracking: boolean;
603
+ responseGroupUid: UUID;
604
+ showStripes: boolean;
605
+ showSurveyBrand: boolean;
606
+ slugName: null;
607
+ startingQuestionIdx?: number | null;
608
+ styleNonce?: string;
609
+ surveyId: number;
610
+ tabTitle: string;
611
+ ulEvents: typeof SprigEvent;
612
+ UpChunk: Window["UpChunk"];
613
+ useDesktopPrototype?: boolean;
614
+ useMobileStyling: boolean;
615
+ userId: UUID | null;
616
+ visitorId: UUID | null;
617
+ viewDocument: Document;
618
+ viewWindow: Window;
619
+ visitorAttributes: {
620
+ email?: string;
621
+ externalUserId?: string;
622
+ };
623
+ }
624
+
625
+ declare enum SurveyState {
626
+ Ready = "ready",
627
+ NoSurvey = "no survey"
628
+ }
629
+
630
+ declare type QueueItem = [string, ...unknown[]] | (() => void);
631
+ declare class SprigQueue {
632
+ paused: boolean;
633
+ queue: QueueItem[];
634
+ ul: WindowSprig;
635
+ constructor(ul: WindowSprig, queue: QueueItem[]);
636
+ flush(queue: QueueItem[]): void;
637
+ isPaused(): boolean;
638
+ pause(): void;
639
+ unpause(): void;
640
+ push(action: QueueItem): void;
641
+ perform(func: () => void): void | Promise<unknown>;
642
+ /**
643
+ * Removes all queued items
644
+ */
645
+ empty(): void;
646
+ }
647
+
648
+ declare namespace optimizely {
649
+ interface Optimizely {
650
+ get?: (key: "state") => {
651
+ getExperimentStates: (options: {
652
+ filter?: unknown;
653
+ isActive?: boolean;
654
+ }) => Record<string, OptimizelyExperimentState>;
655
+ };
656
+ }
657
+
658
+ // Ref: https://docs.developers.optimizely.com/web/docs/state#return-value-2
659
+ interface OptimizelyExperimentState {
660
+ /** Audiences the visitor was in when the experiment was activated.
661
+ * @example { "id": "6672770135", "name": "Chrome users" }
662
+ */
663
+ audiences: { id: number; name: string }[];
664
+ /** The name of the experiment
665
+ * @example OptimizelyExperimentState
666
+ * */
667
+ experimentName: string;
668
+ /** The ID of the experiment
669
+ * @example OptimizelyExperimentState
670
+ * */
671
+ id: string;
672
+ /** Indicates if the experiment is currently active */
673
+ isActive: boolean;
674
+ /** Indicates if the visitor is in the holdback (i.e., is excluded due traffic allocation) */
675
+ isInExperimentHoldback: boolean;
676
+ /** The name of the object. Required */
677
+ name: string;
678
+ /** An object with the name and the ID of the variation the visitor is bucketed in, or null if the visitor was not bucketed
679
+ * @example { "id": "6626731852", "name": "Variation #1" }
680
+ */
681
+ variation: { id: number; name: string } | null;
682
+ /** Indicates if the visitor was redirected due to this experiment */
683
+ visitorRedirected: boolean;
684
+ }
685
+ }
686
+
687
+ declare namespace upchunk {
688
+ type AllowedMethods = "PUT" | "POST" | "PATCH";
689
+
690
+ //Adapted from here: https://github.com/muxinc/upchunk/blob/master/src/upchunk.ts
691
+ interface UpChunkOptions {
692
+ endpoint: string | ((file?: File) => Promise<string>);
693
+ file: File;
694
+ method?: AllowedMethods;
695
+ headers?: Headers;
696
+ maxFileSize?: number;
697
+ chunkSize?: number;
698
+ attempts?: number;
699
+ delayBeforeAttempt?: number;
700
+ retryCodes?: number[];
701
+ dynamicChunkSize?: boolean;
702
+ maxChunkSize?: number;
703
+ minChunkSize?: number;
704
+ }
705
+
706
+ type UpChunkEventName =
707
+ | "attempt"
708
+ | "attemptFailure"
709
+ | "chunkSuccess"
710
+ | "error"
711
+ | "offline"
712
+ | "online"
713
+ | "progress"
714
+ | "success";
715
+
716
+ interface UpChunk {
717
+ startTime: number;
718
+ on: (eventName: UpChunkEventName, fn: (event: CustomEvent) => void) => void;
719
+ }
720
+ interface UpChunkModule {
721
+ createUpload: (options: UpChunkOptions) => UpChunk;
722
+ }
723
+ }
724
+
725
+ declare namespace sprigConfig {
726
+ type IdentifyResult = Promise<
727
+ { success: boolean; message?: string } | undefined
728
+ >;
729
+
730
+ interface TrackPayload {
731
+ anonymousId?: string;
732
+ metadata?: SprigMetadata;
733
+ eventName?: string;
734
+ properties?: SprigProperties;
735
+ userId?: string;
736
+ }
737
+
738
+ interface SprigAPIActions {
739
+ _previewSurvey: (surveyTemplateId: UUID) => void;
740
+ _reviewSurvey: (surveyId: number) => void;
741
+ addListener: (event: SprigEvent, listener: SprigListener) => Promise<void>;
742
+ addSurveyListener: (listener: SprigListener) => Promise<void>;
743
+ applyStyles: (styleString: string) => void;
744
+ displaySurvey: (surveyId: number) => Promise<{
745
+ success: boolean;
746
+ message?: string;
747
+ surveyState: SurveyState;
748
+ }>;
749
+ dismissActiveSurvey: (reason?: DismissReason) => void;
750
+ identifyAndSetAttributes: (payload: {
751
+ anonymousId?: string;
752
+ attributes?: SprigAttributes;
753
+ userId?: string;
754
+ }) => IdentifyResult;
755
+ identifyAndTrack: (payload: TrackPayload) => IdentifyResult;
756
+ integrateOptimizely: (strData: string) => void;
757
+ logoutUser: () => void;
758
+ mute: () => unknown;
759
+ removeAttributes: (attributes: SprigAttributes) => IdentifyResult;
760
+ previewSurvey: (surveyTemplateId: UUID) => void;
761
+ removeAllListeners: () => Promise<void>;
762
+ removeListener: (
763
+ event: SprigEvent,
764
+ listener: SprigListener
765
+ ) => Promise<void>;
766
+ removeSurveyListener: (listener: SprigListener) => Promise<void>;
767
+ reviewSurvey: (surveyId: number) => void;
768
+ setAttribute: (attribute: string, value: string | number) => IdentifyResult;
769
+ setAttributes: (attributes?: SprigAttributes) => IdentifyResult;
770
+ setPartnerAnonymousId: (
771
+ partnerAnonymousId: string
772
+ ) => Promise<{ success: boolean; message?: string }>;
773
+ setVisitorAttribute: (
774
+ attribute: string,
775
+ value: string | number
776
+ ) => IdentifyResult;
777
+ setWindowDimensions: (
778
+ width: number | string,
779
+ height: number | string
780
+ ) => void;
781
+ setEmail: (email: string) => IdentifyResult;
782
+ setUserId: (userId: string) => IdentifyResult;
783
+ setVisitorEmail: (email: string) => IdentifyResult;
784
+ setVisitorToken: () => void;
785
+ teardown: () => void;
786
+ track: (
787
+ eventName: string,
788
+ properties?: TrackPayload["properties"],
789
+ metadata?: SprigMetadata
790
+ ) => IdentifyResult;
791
+ unmute: (surveyId: number) => void;
792
+ }
793
+
794
+ type WindowSprig = Config &
795
+ SprigAPIActions & {
796
+ _API_URL: string;
797
+ _config: Config;
798
+ _gtm: unknown; // TODO: determine if boolean?
799
+ _queue: SprigQueue;
800
+ _segment: unknown; // TODO: determine if boolean?
801
+ appId: string;
802
+ container?: HTMLElement | null;
803
+ config: Config;
804
+ debugMode?: boolean;
805
+ delayingSurvey: boolean;
806
+ email?: string | null;
807
+ envId: string;
808
+ error?: Error;
809
+ frameId: string;
810
+ loaded: boolean;
811
+ locale?: string;
812
+ localStorageAvailable: boolean;
813
+ maxHeight?: number | string;
814
+ mobileHeadersJSON?: string;
815
+ nonce?: string;
816
+ partnerAnonymousId: string | null;
817
+ reportError: (name: string, err: Error) => void;
818
+ sampleRate?: unknown; // TODO: determine type
819
+ token: string | null;
820
+ UPDATES: typeof EVENTS;
821
+ viewSDKURL?: string;
822
+ windowDimensions?: {
823
+ height: number;
824
+ width: number;
825
+ };
826
+ } & ((name: "_previewSurvey", surveyTemplateId: string) => void) &
827
+ ((name: "_reviewSurvey", surveyId: number) => void) &
828
+ ((name: "addListener", event: string, listener: SprigListener) => void) &
829
+ ((name: "applyStyles", styles: string) => void) &
830
+ ((name: "dismissActiveSurvey", reason?: DismissReason) => void) &
831
+ ((name: "displaySurvey", surveyId: number) => void) &
832
+ ((
833
+ name: "identifyAndSetAttributes",
834
+ payload: {
835
+ anonymousID?: string;
836
+ attributes: SprigAttributes;
837
+ userID?: string;
838
+ }
839
+ ) => void) &
840
+ ((
841
+ name: "identifyAndTrack",
842
+ payload: {
843
+ anonymousId?: string;
844
+ eventName: string;
845
+ metadata?: SprigMetadata;
846
+ userId?: string;
847
+ }
848
+ ) => void) &
849
+ ((name: "logoutUser") => void) &
850
+ ((name: "mute") => void) &
851
+ ((name: "previewSurvey", surveyTemplateId: string) => void) &
852
+ ((name: "removeAllListeners") => void) &
853
+ ((name: "removeAttributes", attributes: SprigAttributes) => void) &
854
+ ((name: "removeListener", event: string, listener: SprigListener) => void) &
855
+ ((name: "reviewSurvey", surveyId: number) => void) &
856
+ ((name: "setAttribute", attribute: string, value: string) => void) &
857
+ ((name: "setAttributes", attributes: SprigAttributes) => void) &
858
+ ((name: "setPartnerAnonymousId", partnerAnonymousId: string) => void) &
859
+ ((name: "setUserId", userId: string) => void) &
860
+ ((
861
+ name: "setWindowDimensions",
862
+ width: number | string,
863
+ height: number | string
864
+ ) => void) &
865
+ ((name: "teardown") => void) &
866
+ ((
867
+ name: "track",
868
+ eventName: string,
869
+ properties?: SprigProperties,
870
+ metadata?: SprigMetadata
871
+ ) => void) &
872
+ ((name: "unmute") => void);
873
+ }
874
+
875
+ declare global {
876
+ interface Window {
877
+ __cfg: Config;
878
+ attachEvent?: typeof window.addEventListener;
879
+ Intercom: Intercom_.IntercomStatic & { ul_wasVisible?: boolean };
880
+ optimizely?: optimizely.Optimizely;
881
+ previewMode?: unknown;
882
+ UpChunk: upchunk.UpChunkModule;
883
+ _Sprig?: sprigConfig.WindowSprig;
884
+ Sprig: sprigConfig.WindowSprig;
885
+ UserLeap: sprigConfig.WindowSprig;
886
+ }
887
+
888
+ type WindowSprig = sprigConfig.WindowSprig;
889
+ type SprigAttributes = Record<string, boolean | number | string>;
890
+ type SprigListener = (data: unknown) => void;
891
+ type SprigMetadata = Record<string, unknown>;
892
+ type SprigProperties = Record<string, unknown>;
893
+ type SprigAPIActions = sprigConfig.SprigAPIActions;
894
+ type TrackPayload = sprigConfig.TrackPayload;
895
+
896
+ // common types
897
+ /** @example "123e4567-e89b-12d3-a456-426614174000" */
898
+ type UUID = string;
899
+ }
900
+
901
+ declare class SprigAPI {
902
+ /**
903
+ * Include external events emitted from Sprig
904
+ */
905
+ UPDATES: {
906
+ SDK_READY: SprigEvent;
907
+ SURVEY_APPEARED: SprigEvent;
908
+ SURVEY_CLOSED: SprigEvent;
909
+ SURVEY_DIMENSIONS: SprigEvent;
910
+ SURVEY_FADING_OUT: SprigEvent;
911
+ SURVEY_HEIGHT: SprigEvent;
912
+ SURVEY_PRESENTED: SprigEvent;
913
+ SURVEY_LIFE_CYCLE: SprigEvent;
914
+ SURVEY_WILL_CLOSE: SprigEvent;
915
+ SURVEY_WILL_PRESENT: SprigEvent;
916
+ CLOSE_SURVEY_ON_OVERLAY_CLICK: SprigEvent;
917
+ VISITOR_ID_UPDATED: SprigEvent;
918
+ DATA: {
919
+ DISMISS_REASONS: {
920
+ API: DismissReason;
921
+ CLOSED: DismissReason;
922
+ COMPLETE: DismissReason;
923
+ PAGE_CHANGE: DismissReason;
924
+ OVERRIDE: DismissReason;
925
+ };
926
+ SURVEY_ID: SprigEventData;
927
+ };
928
+ };
929
+ /**
930
+ * Triggers displaying specified survey. Does submit answers!
931
+ * @returns
932
+ */
933
+ displaySurvey(surveyId: number): void;
934
+ /**
935
+ * Pauses api interactions
936
+ */
937
+ mute(): void;
938
+ /**
939
+ * Restart api interactions
940
+ */
941
+ unmute(): void;
942
+ /**
943
+ * Manually dismiss an opened survey
944
+ */
945
+ dismissActiveSurvey(): void;
946
+ /**
947
+ * Set an arbitrary attribute on the visitor
948
+ */
949
+ setAttribute(attribute: string, value: string): void;
950
+ /**
951
+ * Set attributes on visitor
952
+ */
953
+ setAttributes(attributes: SprigAttributes): void;
954
+ /**
955
+ * Set identifiers and attributes on visitor
956
+ */
957
+ identifyAndSetAttributes(payload: {
958
+ anonymousID?: string;
959
+ attributes: SprigAttributes;
960
+ userID?: string;
961
+ }): void;
962
+ /**
963
+ * Remove attributes on visitor
964
+ */
965
+ removeAttributes(attributes: SprigAttributes): void;
966
+ /**
967
+ * Add a listener for an event defined in ulEvents
968
+ */
969
+ addListener(event: string, listener: SprigListener): void;
970
+ /**
971
+ * Remove a listener for an event defined in ulEvents
972
+ */
973
+ removeListener(event: string, listener: SprigListener): void;
974
+ /**
975
+ * Remove all listeners set on Sprig
976
+ */
977
+ removeAllListeners(): void;
978
+ /**
979
+ * Attach an email address to visitor
980
+ */
981
+ setEmail(email: string): void;
982
+ /**
983
+ * Attach a user id to the visitor
984
+ */
985
+ setUserId(userId: string): void;
986
+ /**
987
+ * Set a partner anonymous id for future requests.
988
+ */
989
+ setPartnerAnonymousId(partnerAnonymousId: string): void;
990
+ /**
991
+ * Track an event to show survey if eligible
992
+ * @param eventName name of event to track
993
+ */
994
+ track(eventName: string, properties?: Record<string, unknown>, metadata?: SprigMetadata): void;
995
+ /**
996
+ * Optionally set userId and/or anonymousId, track an event to show survey if eligible
997
+ */
998
+ identifyAndTrack(payload: {
999
+ anonymousId?: string;
1000
+ eventName: string;
1001
+ metadata?: SprigMetadata;
1002
+ userId?: string;
1003
+ }): void;
1004
+ /**
1005
+ * Apply a css string representing the customized styles
1006
+ */
1007
+ applyStyles(styleString: string): void;
1008
+ /**
1009
+ Set viewport dimensions, in int pixels. necessary if Sprig is installed in an iframe/component defaulting to 0 width and height.
1010
+ */
1011
+ setWindowDimensions(width: number | string, height: number | string): void;
1012
+ /**
1013
+ * Logs out current visitor and associated ids
1014
+ */
1015
+ logoutUser(): void;
1016
+ /**
1017
+ * Clears Sprig from window
1018
+ */
1019
+ teardown(): void;
1020
+ }
1021
+ declare type NpmConfig = {
1022
+ envId?: string;
1023
+ environmentId?: string;
1024
+ path?: string;
1025
+ } & Partial<WindowSprig$1>;
1026
+ declare const sprig: {
1027
+ /**
1028
+ * Sets up the sprig api and load the sprig sdk on document load
1029
+ * @param config
1030
+ * @returns an instance of the sprig api
1031
+ */
1032
+ configure: (config: NpmConfig) => sprigConfig.WindowSprig;
1033
+ };
1034
+ declare type WindowSprig$1 = typeof window.Sprig;
1035
+
1036
+ declare const _default: {
1037
+ sprig: {
1038
+ /**
1039
+ * Sets up the sprig api and load the sprig sdk on document load
1040
+ * @param config
1041
+ * @returns an instance of the sprig api
1042
+ */
1043
+ configure: (config: NpmConfig) => sprigConfig.WindowSprig;
1044
+ };
1045
+ SprigAPI: typeof SprigAPI;
1046
+ configure: (config: NpmConfig) => sprigConfig.WindowSprig;
1047
+ };
1048
+
1049
+ export { DismissReason, SprigAPI, WindowSprig$1 as WindowSprig, _default as default, sprig };