-
Notifications
You must be signed in to change notification settings - Fork 1
/
types.ts
123 lines (108 loc) 路 3.15 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import Widget from "./widgets/Widget";
export type WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] };
/**
* When you load Squatch.js you need to provide these configuration options.
*
* @param tenantAlias The Tenant that you're using.
* @param domain The domain for API. Defaults to `https://app.referralsaasquatch.com`
* @param debug Enables debug logging. Defaults to `false`.
*/
export interface ConfigOptions {
tenantAlias: string;
domain?: string;
npmCdn?: string;
debug?: boolean;
}
export type DeclarativeConfigOptions = Omit<ConfigOptions, "tenantAlias">;
/**
* Config options for loading a widget
*
* @param user The user details
* @param widgetType The content of the widget.
* @param engagementMedium How to display the widget.
* @param container Element to load the widget into.
* @param trigger Trigger element's selector for opening the popup widget
* @param jwt the JSON Web Token (JWT) that is used
*/
export interface WidgetConfig {
user?: User;
widgetType?: WidgetType;
engagementMedium?: EngagementMedium;
container?: HTMLElement | string;
trigger?: string;
jwt?: JWT;
locale?: string;
displayOnLoad?: boolean;
}
/**
* @param user The user details
* @param widgetType The content of the widget.
* @param engagementMedium How to display the widget.
* @param jwt the JSON Web Token (JWT) that is used
*/
export interface CookieWidgetConfig {
user?: CookieUser;
widgetType?: WidgetType;
engagementMedium?: EngagementMedium;
jwt?: JWT;
}
/**
* When a widget is loaded using {@link Widgets} you'll get both the `user` data and the `widget` object back.
*
* @param widget The widget that was created.
* @param user The user that's in the widget.
*
*/
export interface WidgetResult {
widget: Widget;
user: User;
}
export type User = {
id: string;
accountId: string;
[key: string]: any;
};
export type CookieUser = {
[key: string]: any;
};
/**
* EngagementMedium is an enum for the content of the widgets.
*
* @example `widgetType: "POPUP"`
*/
export type EngagementMedium =
/** Displays the widget as a modal popup. Creates a {@link PopupWidget} */
| "POPUP"
/** Displays the widget embedded in the page. Create an {@link EmbedWidget} */
| "EMBED";
export type UpsertWidgetContext = {
type: "upsert";
user?: User | null;
engagementMedium?: EngagementMedium;
container?: HTMLElement | string;
trigger?: string;
};
export type BaseWidgetContext = {
type: "cookie" | "error" | "passwordless";
engagementMedium?: EngagementMedium;
container?: HTMLElement | string;
trigger?: string;
displayOnLoad?: boolean;
};
export type WidgetContext = UpsertWidgetContext | BaseWidgetContext;
export type WidgetContextType = "upsert" | "cookie" | "error" | "passwordless";
/**
* WidgetType is an enum for types of ways a Widget can be displayed.
*/
export type WidgetType =
/** Widget content that lets people make referrals */
| "REFERRER_WIDGET"
/** Widget content that shows that someone has been referred */
| "CONVERSION_WIDGET"
| string;
export type ShareMedium = string;
export type JWT = string;
export type ReferralCookie = {
codes: string[];
encodedCookie: string;
};