This repository has been archived by the owner on Jan 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
integrations.ts
210 lines (189 loc) · 4.84 KB
/
integrations.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import { Document, Schema } from 'mongoose';
import { FORM_LOAD_TYPES, FORM_SUCCESS_ACTIONS, KIND_CHOICES, MESSENGER_DATA_AVAILABILITY } from './constants';
import { field } from './utils';
export interface ILink {
twitter?: string;
facebook?: string;
youtube?: string;
}
export interface IMessengerOnlineHours {
day?: string;
from?: string;
to?: string;
}
export interface IMessengerOnlineHoursDocument extends IMessengerOnlineHours, Document {}
export interface IMessengerDataMessagesItem {
greetings?: { title?: string; message?: string };
away?: string;
thank?: string;
welcome?: string;
}
export interface IMessageDataMessages {
[key: string]: IMessengerDataMessagesItem;
}
export interface IMessengerData {
supporterIds?: string[];
notifyCustomer?: boolean;
availabilityMethod?: string;
isOnline?: boolean;
onlineHours?: IMessengerOnlineHours[];
timezone?: string;
messages?: IMessageDataMessages;
links?: ILink;
showChat?: boolean;
showLauncher?: boolean;
requireAuth?: boolean;
forceLogoutWhenResolve?: boolean;
}
export interface IMessengerDataDocument extends IMessengerData, Document {}
export interface IFormData {
loadType?: string;
successAction?: string;
fromEmail?: string;
userEmailTitle?: string;
userEmailContent?: string;
adminEmails?: string;
adminEmailTitle?: string;
adminEmailContent?: string;
thankContent?: string;
redirectUrl?: string;
}
export interface IFormDataDocument extends IFormData, Document {}
export interface IUiOptions {
color?: string;
wallpaper?: string;
logo?: string;
}
// subdocument schema for messenger UiOptions
export interface IUiOptionsDocument extends IUiOptions, Document {}
export interface IIntegration {
kind?: string;
name?: string;
brandId?: string;
languageCode?: string;
tagIds?: string[];
formId?: string;
formData?: IFormData;
messengerData?: IMessengerData;
uiOptions?: IUiOptions;
}
export interface IIntegrationDocument extends IIntegration, Document {
_id: string;
formData?: IFormDataDocument;
messengerData?: IMessengerDataDocument;
uiOptions?: IUiOptionsDocument;
}
// subdocument schema for MessengerOnlineHours
const messengerOnlineHoursSchema = new Schema(
{
day: field({ type: String }),
from: field({ type: String }),
to: field({ type: String }),
},
{ _id: false },
);
// subdocument schema for MessengerData
const messengerDataSchema = new Schema(
{
supporterIds: field({ type: [String] }),
notifyCustomer: field({ type: Boolean }),
availabilityMethod: field({
type: String,
enum: MESSENGER_DATA_AVAILABILITY.ALL,
}),
isOnline: field({
type: Boolean,
}),
onlineHours: field({ type: [messengerOnlineHoursSchema] }),
timezone: field({
type: String,
optional: true,
}),
messages: field({ type: Object, optional: true }),
links: {
facebook: String,
twitter: String,
youtube: String,
},
requireAuth: field({ type: Boolean, default: true }),
showChat: field({ type: Boolean, default: true }),
showLauncher: field({ type: Boolean, default: true }),
forceLogoutWhenResolve: field({ type: Boolean, default: false }),
},
{ _id: false },
);
// subdocument schema for FormData
const formDataSchema = new Schema(
{
loadType: field({
type: String,
enum: FORM_LOAD_TYPES.ALL,
}),
successAction: field({
type: String,
enum: FORM_SUCCESS_ACTIONS.ALL,
optional: true,
}),
fromEmail: field({
type: String,
optional: true,
}),
userEmailTitle: field({
type: String,
optional: true,
}),
userEmailContent: field({
type: String,
optional: true,
}),
adminEmails: field({
type: [String],
optional: true,
}),
adminEmailTitle: field({
type: String,
optional: true,
}),
adminEmailContent: field({
type: String,
optional: true,
}),
thankContent: field({
type: String,
optional: true,
}),
redirectUrl: field({
type: String,
optional: true,
}),
},
{ _id: false },
);
// subdocument schema for messenger UiOptions
const uiOptionsSchema = new Schema(
{
color: field({ type: String }),
wallpaper: field({ type: String }),
logo: field({ type: String }),
},
{ _id: false },
);
// schema for integration document
export const integrationSchema = new Schema({
_id: field({ pkey: true }),
kind: field({
type: String,
enum: KIND_CHOICES.ALL,
}),
name: field({ type: String }),
brandId: field({ type: String }),
languageCode: field({
type: String,
optional: true,
}),
tagIds: field({ type: [String], optional: true }),
formId: field({ type: String }),
formData: field({ type: formDataSchema }),
messengerData: field({ type: messengerDataSchema }),
uiOptions: field({ type: uiOptionsSchema }),
});