@23blocks/block-crm 1.0.3 → 1.0.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.
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +897 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/lib/block-crm.d.ts +2 -0
- package/dist/src/lib/block-crm.d.ts.map +1 -0
- package/dist/src/lib/crm.block.d.ts +17 -0
- package/dist/src/lib/crm.block.d.ts.map +1 -0
- package/dist/src/lib/mappers/account.mapper.d.ts +5 -0
- package/dist/src/lib/mappers/account.mapper.d.ts.map +1 -0
- package/dist/src/lib/mappers/contact.mapper.d.ts +5 -0
- package/dist/src/lib/mappers/contact.mapper.d.ts.map +1 -0
- package/dist/{lib/mappers/index.js → src/lib/mappers/index.d.ts} +1 -2
- package/dist/src/lib/mappers/index.d.ts.map +1 -0
- package/dist/src/lib/mappers/lead.mapper.d.ts +4 -0
- package/dist/src/lib/mappers/lead.mapper.d.ts.map +1 -0
- package/dist/src/lib/mappers/meeting.mapper.d.ts +4 -0
- package/dist/src/lib/mappers/meeting.mapper.d.ts.map +1 -0
- package/dist/src/lib/mappers/opportunity.mapper.d.ts +4 -0
- package/dist/src/lib/mappers/opportunity.mapper.d.ts.map +1 -0
- package/dist/src/lib/mappers/quote.mapper.d.ts +4 -0
- package/dist/src/lib/mappers/quote.mapper.d.ts.map +1 -0
- package/dist/src/lib/mappers/utils.d.ts +29 -0
- package/dist/src/lib/mappers/utils.d.ts.map +1 -0
- package/dist/src/lib/services/accounts.service.d.ts +16 -0
- package/dist/src/lib/services/accounts.service.d.ts.map +1 -0
- package/dist/src/lib/services/contacts.service.d.ts +16 -0
- package/dist/src/lib/services/contacts.service.d.ts.map +1 -0
- package/dist/{lib/services/index.js → src/lib/services/index.d.ts} +1 -2
- package/dist/src/lib/services/index.d.ts.map +1 -0
- package/dist/src/lib/services/leads.service.d.ts +16 -0
- package/dist/src/lib/services/leads.service.d.ts.map +1 -0
- package/dist/src/lib/services/meetings.service.d.ts +16 -0
- package/dist/src/lib/services/meetings.service.d.ts.map +1 -0
- package/dist/src/lib/services/opportunities.service.d.ts +16 -0
- package/dist/src/lib/services/opportunities.service.d.ts.map +1 -0
- package/dist/src/lib/services/quotes.service.d.ts +16 -0
- package/dist/src/lib/services/quotes.service.d.ts.map +1 -0
- package/dist/src/lib/types/account.d.ts +56 -0
- package/dist/src/lib/types/account.d.ts.map +1 -0
- package/dist/src/lib/types/contact.d.ts +73 -0
- package/dist/src/lib/types/contact.d.ts.map +1 -0
- package/dist/{lib/types/index.js → src/lib/types/index.d.ts} +1 -2
- package/dist/src/lib/types/index.d.ts.map +1 -0
- package/dist/src/lib/types/lead.d.ts +71 -0
- package/dist/src/lib/types/lead.d.ts.map +1 -0
- package/dist/src/lib/types/meeting.d.ts +73 -0
- package/dist/src/lib/types/meeting.d.ts.map +1 -0
- package/dist/src/lib/types/opportunity.d.ts +66 -0
- package/dist/src/lib/types/opportunity.d.ts.map +1 -0
- package/dist/src/lib/types/quote.d.ts +66 -0
- package/dist/src/lib/types/quote.d.ts.map +1 -0
- package/package.json +10 -8
- package/dist/index.js +0 -7
- package/dist/index.js.map +0 -1
- package/dist/lib/block-crm.js +0 -5
- package/dist/lib/block-crm.js.map +0 -1
- package/dist/lib/crm.block.js +0 -28
- package/dist/lib/crm.block.js.map +0 -1
- package/dist/lib/mappers/account.mapper.js +0 -44
- package/dist/lib/mappers/account.mapper.js.map +0 -1
- package/dist/lib/mappers/contact.mapper.js +0 -54
- package/dist/lib/mappers/contact.mapper.js.map +0 -1
- package/dist/lib/mappers/index.js.map +0 -1
- package/dist/lib/mappers/lead.mapper.js +0 -31
- package/dist/lib/mappers/lead.mapper.js.map +0 -1
- package/dist/lib/mappers/meeting.mapper.js +0 -34
- package/dist/lib/mappers/meeting.mapper.js.map +0 -1
- package/dist/lib/mappers/opportunity.mapper.js +0 -30
- package/dist/lib/mappers/opportunity.mapper.js.map +0 -1
- package/dist/lib/mappers/quote.mapper.js +0 -30
- package/dist/lib/mappers/quote.mapper.js.map +0 -1
- package/dist/lib/mappers/utils.js +0 -75
- package/dist/lib/mappers/utils.js.map +0 -1
- package/dist/lib/services/accounts.service.js +0 -88
- package/dist/lib/services/accounts.service.js.map +0 -1
- package/dist/lib/services/contacts.service.js +0 -95
- package/dist/lib/services/contacts.service.js.map +0 -1
- package/dist/lib/services/index.js.map +0 -1
- package/dist/lib/services/leads.service.js +0 -109
- package/dist/lib/services/leads.service.js.map +0 -1
- package/dist/lib/services/meetings.service.js +0 -108
- package/dist/lib/services/meetings.service.js.map +0 -1
- package/dist/lib/services/opportunities.service.js +0 -105
- package/dist/lib/services/opportunities.service.js.map +0 -1
- package/dist/lib/services/quotes.service.js +0 -105
- package/dist/lib/services/quotes.service.js.map +0 -1
- package/dist/lib/types/account.js +0 -3
- package/dist/lib/types/account.js.map +0 -1
- package/dist/lib/types/contact.js +0 -3
- package/dist/lib/types/contact.js.map +0 -1
- package/dist/lib/types/index.js.map +0 -1
- package/dist/lib/types/lead.js +0 -3
- package/dist/lib/types/lead.js.map +0 -1
- package/dist/lib/types/meeting.js +0 -3
- package/dist/lib/types/meeting.js.map +0 -1
- package/dist/lib/types/opportunity.js +0 -3
- package/dist/lib/types/opportunity.js.map +0 -1
- package/dist/lib/types/quote.js +0 -3
- package/dist/lib/types/quote.js.map +0 -1
|
@@ -0,0 +1,897 @@
|
|
|
1
|
+
import { decodePageResult, decodeOne } from '@23blocks/jsonapi-codec';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Parse a string value, returning undefined for empty/undefined
|
|
5
|
+
*/ function parseString(value) {
|
|
6
|
+
if (value === null || value === undefined) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
const str = String(value);
|
|
10
|
+
return str.length > 0 ? str : undefined;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Parse a date value
|
|
14
|
+
*/ function parseDate(value) {
|
|
15
|
+
if (value === null || value === undefined) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
if (value instanceof Date) {
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
22
|
+
const date = new Date(value);
|
|
23
|
+
return isNaN(date.getTime()) ? undefined : date;
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Parse a boolean value
|
|
29
|
+
*/ function parseBoolean(value) {
|
|
30
|
+
if (typeof value === 'boolean') {
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
if (value === 'true' || value === '1' || value === 1) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Parse an array of strings
|
|
40
|
+
*/ function parseStringArray(value) {
|
|
41
|
+
if (value === null || value === undefined) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
if (Array.isArray(value)) {
|
|
45
|
+
return value.map(String);
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Parse an optional number value
|
|
51
|
+
*/ function parseOptionalNumber(value) {
|
|
52
|
+
if (value === null || value === undefined) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
const num = Number(value);
|
|
56
|
+
return isNaN(num) ? undefined : num;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Parse entity status
|
|
60
|
+
*/ function parseStatus(value) {
|
|
61
|
+
const status = parseString(value);
|
|
62
|
+
if (status === 'active' || status === 'inactive' || status === 'pending' || status === 'archived' || status === 'deleted') {
|
|
63
|
+
return status;
|
|
64
|
+
}
|
|
65
|
+
return 'active';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const accountMapper = {
|
|
69
|
+
type: 'Account',
|
|
70
|
+
map: (resource)=>({
|
|
71
|
+
id: resource.id,
|
|
72
|
+
uniqueId: parseString(resource.attributes['unique_id']) || resource.id,
|
|
73
|
+
createdAt: parseDate(resource.attributes['created_at']) || new Date(),
|
|
74
|
+
updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
|
|
75
|
+
code: parseString(resource.attributes['code']) || '',
|
|
76
|
+
name: parseString(resource.attributes['name']) || '',
|
|
77
|
+
label: parseString(resource.attributes['label']),
|
|
78
|
+
status: parseStatus(resource.attributes['status']),
|
|
79
|
+
enabled: parseBoolean(resource.attributes['enabled']),
|
|
80
|
+
preferredDomain: parseString(resource.attributes['preferred_domain']),
|
|
81
|
+
preferredLanguage: parseString(resource.attributes['preferred_language']),
|
|
82
|
+
payload: resource.attributes['payload'],
|
|
83
|
+
tags: parseStringArray(resource.attributes['tags']),
|
|
84
|
+
createdBy: parseString(resource.attributes['created_by']),
|
|
85
|
+
updatedBy: parseString(resource.attributes['updated_by'])
|
|
86
|
+
})
|
|
87
|
+
};
|
|
88
|
+
const accountDetailMapper = {
|
|
89
|
+
type: 'AccountDetail',
|
|
90
|
+
map: (resource)=>({
|
|
91
|
+
id: resource.id,
|
|
92
|
+
uniqueId: parseString(resource.attributes['unique_id']) || resource.id,
|
|
93
|
+
createdAt: parseDate(resource.attributes['created_at']) || new Date(),
|
|
94
|
+
updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
|
|
95
|
+
accountUniqueId: parseString(resource.attributes['account_unique_id']) || '',
|
|
96
|
+
code: parseString(resource.attributes['code']) || '',
|
|
97
|
+
name: parseString(resource.attributes['name']) || '',
|
|
98
|
+
label: parseString(resource.attributes['label']),
|
|
99
|
+
status: parseStatus(resource.attributes['status']),
|
|
100
|
+
enabled: parseBoolean(resource.attributes['enabled']),
|
|
101
|
+
preferredDomain: parseString(resource.attributes['preferred_domain']),
|
|
102
|
+
preferredLanguage: parseString(resource.attributes['preferred_language']),
|
|
103
|
+
payload: resource.attributes['payload'],
|
|
104
|
+
tags: parseStringArray(resource.attributes['tags']),
|
|
105
|
+
createdBy: parseString(resource.attributes['created_by']),
|
|
106
|
+
updatedBy: parseString(resource.attributes['updated_by'])
|
|
107
|
+
})
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
function createAccountsService(transport, _config) {
|
|
111
|
+
return {
|
|
112
|
+
async list (params) {
|
|
113
|
+
const queryParams = {};
|
|
114
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
115
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
116
|
+
if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
|
|
117
|
+
if (params == null ? void 0 : params.search) queryParams['search'] = params.search;
|
|
118
|
+
if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
|
|
119
|
+
const response = await transport.get('/accounts', {
|
|
120
|
+
params: queryParams
|
|
121
|
+
});
|
|
122
|
+
return decodePageResult(response, accountMapper);
|
|
123
|
+
},
|
|
124
|
+
async get (uniqueId) {
|
|
125
|
+
const response = await transport.get(`/accounts/${uniqueId}`);
|
|
126
|
+
return decodeOne(response, accountMapper);
|
|
127
|
+
},
|
|
128
|
+
async create (data) {
|
|
129
|
+
const response = await transport.post('/accounts', {
|
|
130
|
+
data: {
|
|
131
|
+
type: 'Account',
|
|
132
|
+
attributes: {
|
|
133
|
+
code: data.code,
|
|
134
|
+
name: data.name,
|
|
135
|
+
label: data.label,
|
|
136
|
+
preferred_domain: data.preferredDomain,
|
|
137
|
+
preferred_language: data.preferredLanguage,
|
|
138
|
+
payload: data.payload,
|
|
139
|
+
tags: data.tags
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
return decodeOne(response, accountMapper);
|
|
144
|
+
},
|
|
145
|
+
async update (uniqueId, data) {
|
|
146
|
+
const response = await transport.put(`/accounts/${uniqueId}`, {
|
|
147
|
+
data: {
|
|
148
|
+
type: 'Account',
|
|
149
|
+
attributes: {
|
|
150
|
+
name: data.name,
|
|
151
|
+
label: data.label,
|
|
152
|
+
preferred_domain: data.preferredDomain,
|
|
153
|
+
preferred_language: data.preferredLanguage,
|
|
154
|
+
enabled: data.enabled,
|
|
155
|
+
status: data.status,
|
|
156
|
+
payload: data.payload,
|
|
157
|
+
tags: data.tags
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
return decodeOne(response, accountMapper);
|
|
162
|
+
},
|
|
163
|
+
async delete (uniqueId) {
|
|
164
|
+
await transport.delete(`/accounts/${uniqueId}`);
|
|
165
|
+
},
|
|
166
|
+
async recover (uniqueId) {
|
|
167
|
+
const response = await transport.put(`/accounts/${uniqueId}/recover`, {});
|
|
168
|
+
return decodeOne(response, accountMapper);
|
|
169
|
+
},
|
|
170
|
+
async search (query, params) {
|
|
171
|
+
const queryParams = {
|
|
172
|
+
search: query
|
|
173
|
+
};
|
|
174
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
175
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
176
|
+
const response = await transport.post('/accounts/search', {
|
|
177
|
+
search: query
|
|
178
|
+
}, {
|
|
179
|
+
params: queryParams
|
|
180
|
+
});
|
|
181
|
+
return decodePageResult(response, accountMapper);
|
|
182
|
+
},
|
|
183
|
+
async listDeleted (params) {
|
|
184
|
+
const queryParams = {};
|
|
185
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
186
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
187
|
+
const response = await transport.get('/accounts/trash/show', {
|
|
188
|
+
params: queryParams
|
|
189
|
+
});
|
|
190
|
+
return decodePageResult(response, accountMapper);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const contactMapper = {
|
|
196
|
+
type: 'Contact',
|
|
197
|
+
map: (resource)=>({
|
|
198
|
+
id: resource.id,
|
|
199
|
+
uniqueId: parseString(resource.attributes['unique_id']) || resource.id,
|
|
200
|
+
createdAt: parseDate(resource.attributes['created_at']) || new Date(),
|
|
201
|
+
updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
|
|
202
|
+
firstName: parseString(resource.attributes['first_name']) || '',
|
|
203
|
+
lastName: parseString(resource.attributes['last_name']) || '',
|
|
204
|
+
middleName: parseString(resource.attributes['middle_name']),
|
|
205
|
+
primaryEmail: parseString(resource.attributes['primary_email']),
|
|
206
|
+
primaryPhone: parseString(resource.attributes['primary_phone']),
|
|
207
|
+
position: parseString(resource.attributes['position']),
|
|
208
|
+
notes: parseString(resource.attributes['notes']),
|
|
209
|
+
source: parseString(resource.attributes['source']),
|
|
210
|
+
sourceId: parseString(resource.attributes['source_id']),
|
|
211
|
+
sourceAlias: parseString(resource.attributes['source_alias']),
|
|
212
|
+
sourceType: parseString(resource.attributes['source_type']),
|
|
213
|
+
status: parseStatus(resource.attributes['status']),
|
|
214
|
+
contactStatus: parseString(resource.attributes['contact_status']),
|
|
215
|
+
userUniqueId: parseString(resource.attributes['user_unique_id']),
|
|
216
|
+
enabled: parseBoolean(resource.attributes['enabled']),
|
|
217
|
+
tags: parseStringArray(resource.attributes['tags'])
|
|
218
|
+
})
|
|
219
|
+
};
|
|
220
|
+
const contactProfileMapper = {
|
|
221
|
+
type: 'ContactProfile',
|
|
222
|
+
map: (resource)=>({
|
|
223
|
+
id: resource.id,
|
|
224
|
+
uniqueId: parseString(resource.attributes['unique_id']) || resource.id,
|
|
225
|
+
createdAt: parseDate(resource.attributes['created_at']) || new Date(),
|
|
226
|
+
updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
|
|
227
|
+
contactUniqueId: parseString(resource.attributes['contact_unique_id']) || '',
|
|
228
|
+
firstName: parseString(resource.attributes['first_name']) || '',
|
|
229
|
+
lastName: parseString(resource.attributes['last_name']) || '',
|
|
230
|
+
middleName: parseString(resource.attributes['middle_name']),
|
|
231
|
+
primaryEmail: parseString(resource.attributes['primary_email']),
|
|
232
|
+
primaryPhone: parseString(resource.attributes['primary_phone']),
|
|
233
|
+
position: parseString(resource.attributes['position']),
|
|
234
|
+
notes: parseString(resource.attributes['notes']),
|
|
235
|
+
source: parseString(resource.attributes['source']),
|
|
236
|
+
sourceId: parseString(resource.attributes['source_id']),
|
|
237
|
+
sourceAlias: parseString(resource.attributes['source_alias']),
|
|
238
|
+
sourceType: parseString(resource.attributes['source_type']),
|
|
239
|
+
status: parseStatus(resource.attributes['status']),
|
|
240
|
+
contactStatus: parseString(resource.attributes['contact_status']),
|
|
241
|
+
userUniqueId: parseString(resource.attributes['user_unique_id']),
|
|
242
|
+
enabled: parseBoolean(resource.attributes['enabled']),
|
|
243
|
+
tags: parseStringArray(resource.attributes['tags'])
|
|
244
|
+
})
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
function createContactsService(transport, _config) {
|
|
248
|
+
return {
|
|
249
|
+
async list (params) {
|
|
250
|
+
const queryParams = {};
|
|
251
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
252
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
253
|
+
if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
|
|
254
|
+
if (params == null ? void 0 : params.contactStatus) queryParams['contact_status'] = params.contactStatus;
|
|
255
|
+
if (params == null ? void 0 : params.search) queryParams['search'] = params.search;
|
|
256
|
+
if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
|
|
257
|
+
const response = await transport.get('/contacts', {
|
|
258
|
+
params: queryParams
|
|
259
|
+
});
|
|
260
|
+
return decodePageResult(response, contactMapper);
|
|
261
|
+
},
|
|
262
|
+
async get (uniqueId) {
|
|
263
|
+
const response = await transport.get(`/contacts/${uniqueId}`);
|
|
264
|
+
return decodeOne(response, contactMapper);
|
|
265
|
+
},
|
|
266
|
+
async create (data) {
|
|
267
|
+
const response = await transport.post('/contacts', {
|
|
268
|
+
data: {
|
|
269
|
+
type: 'Contact',
|
|
270
|
+
attributes: {
|
|
271
|
+
first_name: data.firstName,
|
|
272
|
+
last_name: data.lastName,
|
|
273
|
+
middle_name: data.middleName,
|
|
274
|
+
primary_email: data.primaryEmail,
|
|
275
|
+
primary_phone: data.primaryPhone,
|
|
276
|
+
position: data.position,
|
|
277
|
+
notes: data.notes,
|
|
278
|
+
source: data.source,
|
|
279
|
+
user_unique_id: data.userUniqueId,
|
|
280
|
+
tags: data.tags
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
return decodeOne(response, contactMapper);
|
|
285
|
+
},
|
|
286
|
+
async update (uniqueId, data) {
|
|
287
|
+
const response = await transport.put(`/contacts/${uniqueId}`, {
|
|
288
|
+
data: {
|
|
289
|
+
type: 'Contact',
|
|
290
|
+
attributes: {
|
|
291
|
+
first_name: data.firstName,
|
|
292
|
+
last_name: data.lastName,
|
|
293
|
+
middle_name: data.middleName,
|
|
294
|
+
primary_email: data.primaryEmail,
|
|
295
|
+
primary_phone: data.primaryPhone,
|
|
296
|
+
position: data.position,
|
|
297
|
+
notes: data.notes,
|
|
298
|
+
contact_status: data.contactStatus,
|
|
299
|
+
enabled: data.enabled,
|
|
300
|
+
status: data.status,
|
|
301
|
+
tags: data.tags
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
return decodeOne(response, contactMapper);
|
|
306
|
+
},
|
|
307
|
+
async delete (uniqueId) {
|
|
308
|
+
await transport.delete(`/contacts/${uniqueId}`);
|
|
309
|
+
},
|
|
310
|
+
async recover (uniqueId) {
|
|
311
|
+
const response = await transport.put(`/contacts/${uniqueId}/recover`, {});
|
|
312
|
+
return decodeOne(response, contactMapper);
|
|
313
|
+
},
|
|
314
|
+
async search (query, params) {
|
|
315
|
+
const queryParams = {
|
|
316
|
+
search: query
|
|
317
|
+
};
|
|
318
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
319
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
320
|
+
const response = await transport.post('/contacts/search', {
|
|
321
|
+
search: query
|
|
322
|
+
}, {
|
|
323
|
+
params: queryParams
|
|
324
|
+
});
|
|
325
|
+
return decodePageResult(response, contactMapper);
|
|
326
|
+
},
|
|
327
|
+
async listDeleted (params) {
|
|
328
|
+
const queryParams = {};
|
|
329
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
330
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
331
|
+
const response = await transport.get('/contacts/trash/show', {
|
|
332
|
+
params: queryParams
|
|
333
|
+
});
|
|
334
|
+
return decodePageResult(response, contactMapper);
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const leadMapper = {
|
|
340
|
+
type: 'Lead',
|
|
341
|
+
map: (resource)=>({
|
|
342
|
+
id: resource.id,
|
|
343
|
+
uniqueId: parseString(resource.attributes['unique_id']) || resource.id,
|
|
344
|
+
createdAt: parseDate(resource.attributes['created_at']) || new Date(),
|
|
345
|
+
updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
|
|
346
|
+
firstName: parseString(resource.attributes['first_name']) || '',
|
|
347
|
+
lastName: parseString(resource.attributes['last_name']) || '',
|
|
348
|
+
middleName: parseString(resource.attributes['middle_name']),
|
|
349
|
+
leadEmail: parseString(resource.attributes['lead_email']),
|
|
350
|
+
phoneNumber: parseString(resource.attributes['phone_number']),
|
|
351
|
+
webSite: parseString(resource.attributes['web_site']),
|
|
352
|
+
twitter: parseString(resource.attributes['twitter']),
|
|
353
|
+
fb: parseString(resource.attributes['fb']),
|
|
354
|
+
instagram: parseString(resource.attributes['instagram']),
|
|
355
|
+
linkedin: parseString(resource.attributes['linkedin']),
|
|
356
|
+
youtube: parseString(resource.attributes['youtube']),
|
|
357
|
+
blog: parseString(resource.attributes['blog']),
|
|
358
|
+
notes: parseString(resource.attributes['notes']),
|
|
359
|
+
source: parseString(resource.attributes['source']),
|
|
360
|
+
status: parseStatus(resource.attributes['status']),
|
|
361
|
+
contactStatus: parseString(resource.attributes['contact_status']),
|
|
362
|
+
enabled: parseBoolean(resource.attributes['enabled']),
|
|
363
|
+
payload: resource.attributes['payload'],
|
|
364
|
+
tags: parseStringArray(resource.attributes['tags'])
|
|
365
|
+
})
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
function createLeadsService(transport, _config) {
|
|
369
|
+
return {
|
|
370
|
+
async list (params) {
|
|
371
|
+
const queryParams = {};
|
|
372
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
373
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
374
|
+
if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
|
|
375
|
+
if (params == null ? void 0 : params.contactStatus) queryParams['contact_status'] = params.contactStatus;
|
|
376
|
+
if (params == null ? void 0 : params.source) queryParams['source'] = params.source;
|
|
377
|
+
if (params == null ? void 0 : params.search) queryParams['search'] = params.search;
|
|
378
|
+
if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
|
|
379
|
+
const response = await transport.get('/leads', {
|
|
380
|
+
params: queryParams
|
|
381
|
+
});
|
|
382
|
+
return decodePageResult(response, leadMapper);
|
|
383
|
+
},
|
|
384
|
+
async get (uniqueId) {
|
|
385
|
+
const response = await transport.get(`/leads/${uniqueId}`);
|
|
386
|
+
return decodeOne(response, leadMapper);
|
|
387
|
+
},
|
|
388
|
+
async create (data) {
|
|
389
|
+
const response = await transport.post('/leads', {
|
|
390
|
+
data: {
|
|
391
|
+
type: 'Lead',
|
|
392
|
+
attributes: {
|
|
393
|
+
first_name: data.firstName,
|
|
394
|
+
last_name: data.lastName,
|
|
395
|
+
middle_name: data.middleName,
|
|
396
|
+
lead_email: data.leadEmail,
|
|
397
|
+
phone_number: data.phoneNumber,
|
|
398
|
+
web_site: data.webSite,
|
|
399
|
+
twitter: data.twitter,
|
|
400
|
+
fb: data.fb,
|
|
401
|
+
instagram: data.instagram,
|
|
402
|
+
linkedin: data.linkedin,
|
|
403
|
+
youtube: data.youtube,
|
|
404
|
+
blog: data.blog,
|
|
405
|
+
notes: data.notes,
|
|
406
|
+
source: data.source,
|
|
407
|
+
payload: data.payload,
|
|
408
|
+
tags: data.tags
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
return decodeOne(response, leadMapper);
|
|
413
|
+
},
|
|
414
|
+
async update (uniqueId, data) {
|
|
415
|
+
const response = await transport.put(`/leads/${uniqueId}`, {
|
|
416
|
+
data: {
|
|
417
|
+
type: 'Lead',
|
|
418
|
+
attributes: {
|
|
419
|
+
first_name: data.firstName,
|
|
420
|
+
last_name: data.lastName,
|
|
421
|
+
middle_name: data.middleName,
|
|
422
|
+
lead_email: data.leadEmail,
|
|
423
|
+
phone_number: data.phoneNumber,
|
|
424
|
+
web_site: data.webSite,
|
|
425
|
+
twitter: data.twitter,
|
|
426
|
+
fb: data.fb,
|
|
427
|
+
instagram: data.instagram,
|
|
428
|
+
linkedin: data.linkedin,
|
|
429
|
+
youtube: data.youtube,
|
|
430
|
+
blog: data.blog,
|
|
431
|
+
notes: data.notes,
|
|
432
|
+
contact_status: data.contactStatus,
|
|
433
|
+
enabled: data.enabled,
|
|
434
|
+
status: data.status,
|
|
435
|
+
payload: data.payload,
|
|
436
|
+
tags: data.tags
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
return decodeOne(response, leadMapper);
|
|
441
|
+
},
|
|
442
|
+
async delete (uniqueId) {
|
|
443
|
+
await transport.delete(`/leads/${uniqueId}`);
|
|
444
|
+
},
|
|
445
|
+
async recover (uniqueId) {
|
|
446
|
+
const response = await transport.put(`/leads/${uniqueId}/recover`, {});
|
|
447
|
+
return decodeOne(response, leadMapper);
|
|
448
|
+
},
|
|
449
|
+
async search (query, params) {
|
|
450
|
+
const queryParams = {
|
|
451
|
+
search: query
|
|
452
|
+
};
|
|
453
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
454
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
455
|
+
const response = await transport.post('/leads/search', {
|
|
456
|
+
search: query
|
|
457
|
+
}, {
|
|
458
|
+
params: queryParams
|
|
459
|
+
});
|
|
460
|
+
return decodePageResult(response, leadMapper);
|
|
461
|
+
},
|
|
462
|
+
async listDeleted (params) {
|
|
463
|
+
const queryParams = {};
|
|
464
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
465
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
466
|
+
const response = await transport.get('/leads/trash/show', {
|
|
467
|
+
params: queryParams
|
|
468
|
+
});
|
|
469
|
+
return decodePageResult(response, leadMapper);
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
const opportunityMapper = {
|
|
475
|
+
type: 'Opportunity',
|
|
476
|
+
map: (resource)=>({
|
|
477
|
+
id: resource.id,
|
|
478
|
+
uniqueId: parseString(resource.attributes['unique_id']) || resource.id,
|
|
479
|
+
createdAt: parseDate(resource.attributes['created_at']) || new Date(),
|
|
480
|
+
updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
|
|
481
|
+
accountUniqueId: parseString(resource.attributes['account_unique_id']),
|
|
482
|
+
contactUniqueId: parseString(resource.attributes['contact_unique_id']),
|
|
483
|
+
code: parseString(resource.attributes['code']) || '',
|
|
484
|
+
name: parseString(resource.attributes['name']) || '',
|
|
485
|
+
notes: parseString(resource.attributes['notes']),
|
|
486
|
+
budget: parseOptionalNumber(resource.attributes['budget']),
|
|
487
|
+
total: parseOptionalNumber(resource.attributes['total']),
|
|
488
|
+
duration: parseOptionalNumber(resource.attributes['duration']),
|
|
489
|
+
durationUnit: parseString(resource.attributes['duration_unit']),
|
|
490
|
+
durationDescription: parseString(resource.attributes['duration_description']),
|
|
491
|
+
payload: resource.attributes['payload'],
|
|
492
|
+
nextActionAt: parseDate(resource.attributes['next_action_at']),
|
|
493
|
+
ownerUniqueId: parseString(resource.attributes['owner_unique_id']),
|
|
494
|
+
ownerName: parseString(resource.attributes['owner_name']),
|
|
495
|
+
ownerEmail: parseString(resource.attributes['owner_email']),
|
|
496
|
+
status: parseStatus(resource.attributes['status']),
|
|
497
|
+
enabled: parseBoolean(resource.attributes['enabled']),
|
|
498
|
+
tags: parseStringArray(resource.attributes['tags'])
|
|
499
|
+
})
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
function createOpportunitiesService(transport, _config) {
|
|
503
|
+
return {
|
|
504
|
+
async list (params) {
|
|
505
|
+
const queryParams = {};
|
|
506
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
507
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
508
|
+
if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
|
|
509
|
+
if (params == null ? void 0 : params.accountUniqueId) queryParams['account_unique_id'] = params.accountUniqueId;
|
|
510
|
+
if (params == null ? void 0 : params.contactUniqueId) queryParams['contact_unique_id'] = params.contactUniqueId;
|
|
511
|
+
if (params == null ? void 0 : params.ownerUniqueId) queryParams['owner_unique_id'] = params.ownerUniqueId;
|
|
512
|
+
if (params == null ? void 0 : params.search) queryParams['search'] = params.search;
|
|
513
|
+
if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
|
|
514
|
+
const response = await transport.get('/opportunities', {
|
|
515
|
+
params: queryParams
|
|
516
|
+
});
|
|
517
|
+
return decodePageResult(response, opportunityMapper);
|
|
518
|
+
},
|
|
519
|
+
async get (uniqueId) {
|
|
520
|
+
const response = await transport.get(`/opportunities/${uniqueId}`);
|
|
521
|
+
return decodeOne(response, opportunityMapper);
|
|
522
|
+
},
|
|
523
|
+
async create (data) {
|
|
524
|
+
const response = await transport.post('/opportunities', {
|
|
525
|
+
data: {
|
|
526
|
+
type: 'Opportunity',
|
|
527
|
+
attributes: {
|
|
528
|
+
account_unique_id: data.accountUniqueId,
|
|
529
|
+
contact_unique_id: data.contactUniqueId,
|
|
530
|
+
code: data.code,
|
|
531
|
+
name: data.name,
|
|
532
|
+
notes: data.notes,
|
|
533
|
+
budget: data.budget,
|
|
534
|
+
total: data.total,
|
|
535
|
+
duration: data.duration,
|
|
536
|
+
duration_unit: data.durationUnit,
|
|
537
|
+
duration_description: data.durationDescription,
|
|
538
|
+
payload: data.payload,
|
|
539
|
+
next_action_at: data.nextActionAt,
|
|
540
|
+
owner_unique_id: data.ownerUniqueId,
|
|
541
|
+
tags: data.tags
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
});
|
|
545
|
+
return decodeOne(response, opportunityMapper);
|
|
546
|
+
},
|
|
547
|
+
async update (uniqueId, data) {
|
|
548
|
+
const response = await transport.put(`/opportunities/${uniqueId}`, {
|
|
549
|
+
data: {
|
|
550
|
+
type: 'Opportunity',
|
|
551
|
+
attributes: {
|
|
552
|
+
name: data.name,
|
|
553
|
+
notes: data.notes,
|
|
554
|
+
budget: data.budget,
|
|
555
|
+
total: data.total,
|
|
556
|
+
duration: data.duration,
|
|
557
|
+
duration_unit: data.durationUnit,
|
|
558
|
+
duration_description: data.durationDescription,
|
|
559
|
+
payload: data.payload,
|
|
560
|
+
next_action_at: data.nextActionAt,
|
|
561
|
+
owner_unique_id: data.ownerUniqueId,
|
|
562
|
+
owner_name: data.ownerName,
|
|
563
|
+
owner_email: data.ownerEmail,
|
|
564
|
+
enabled: data.enabled,
|
|
565
|
+
status: data.status,
|
|
566
|
+
tags: data.tags
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
return decodeOne(response, opportunityMapper);
|
|
571
|
+
},
|
|
572
|
+
async delete (uniqueId) {
|
|
573
|
+
await transport.delete(`/opportunities/${uniqueId}`);
|
|
574
|
+
},
|
|
575
|
+
async recover (uniqueId) {
|
|
576
|
+
const response = await transport.put(`/opportunities/${uniqueId}/recover`, {});
|
|
577
|
+
return decodeOne(response, opportunityMapper);
|
|
578
|
+
},
|
|
579
|
+
async search (query, params) {
|
|
580
|
+
const queryParams = {
|
|
581
|
+
search: query
|
|
582
|
+
};
|
|
583
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
584
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
585
|
+
const response = await transport.post('/opportunities/search', {
|
|
586
|
+
search: query
|
|
587
|
+
}, {
|
|
588
|
+
params: queryParams
|
|
589
|
+
});
|
|
590
|
+
return decodePageResult(response, opportunityMapper);
|
|
591
|
+
},
|
|
592
|
+
async listDeleted (params) {
|
|
593
|
+
const queryParams = {};
|
|
594
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
595
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
596
|
+
const response = await transport.get('/opportunities/trash/show', {
|
|
597
|
+
params: queryParams
|
|
598
|
+
});
|
|
599
|
+
return decodePageResult(response, opportunityMapper);
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
const meetingMapper = {
|
|
605
|
+
type: 'Meeting',
|
|
606
|
+
map: (resource)=>({
|
|
607
|
+
id: resource.id,
|
|
608
|
+
uniqueId: parseString(resource.attributes['unique_id']) || resource.id,
|
|
609
|
+
createdAt: parseDate(resource.attributes['created_at']) || new Date(),
|
|
610
|
+
updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
|
|
611
|
+
code: parseString(resource.attributes['code']) || '',
|
|
612
|
+
title: parseString(resource.attributes['title']) || '',
|
|
613
|
+
meetingType: parseString(resource.attributes['meeting_type']),
|
|
614
|
+
token: parseString(resource.attributes['token']),
|
|
615
|
+
description: parseString(resource.attributes['description']),
|
|
616
|
+
scheduledAt: parseDate(resource.attributes['scheduled_at']),
|
|
617
|
+
startTime: parseDate(resource.attributes['start_time']),
|
|
618
|
+
endTime: parseDate(resource.attributes['end_time']),
|
|
619
|
+
timeUnit: parseString(resource.attributes['time_unit']),
|
|
620
|
+
timeQuantity: parseOptionalNumber(resource.attributes['time_quantity']),
|
|
621
|
+
allDay: parseBoolean(resource.attributes['all_day']),
|
|
622
|
+
timezone: parseString(resource.attributes['timezone']),
|
|
623
|
+
userUniqueId: parseString(resource.attributes['user_unique_id']),
|
|
624
|
+
userName: parseString(resource.attributes['user_name']),
|
|
625
|
+
userEmail: parseString(resource.attributes['user_email']),
|
|
626
|
+
accountUniqueId: parseString(resource.attributes['account_unique_id']),
|
|
627
|
+
meetingLocation: parseString(resource.attributes['meeting_location']),
|
|
628
|
+
meetingUrl: parseString(resource.attributes['meeting_url']),
|
|
629
|
+
meetingScore: parseOptionalNumber(resource.attributes['meeting_score']),
|
|
630
|
+
payload: resource.attributes['payload'],
|
|
631
|
+
status: parseStatus(resource.attributes['status']),
|
|
632
|
+
enabled: parseBoolean(resource.attributes['enabled'])
|
|
633
|
+
})
|
|
634
|
+
};
|
|
635
|
+
|
|
636
|
+
function createMeetingsService(transport, _config) {
|
|
637
|
+
return {
|
|
638
|
+
async list (params) {
|
|
639
|
+
const queryParams = {};
|
|
640
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
641
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
642
|
+
if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
|
|
643
|
+
if (params == null ? void 0 : params.userUniqueId) queryParams['user_unique_id'] = params.userUniqueId;
|
|
644
|
+
if (params == null ? void 0 : params.accountUniqueId) queryParams['account_unique_id'] = params.accountUniqueId;
|
|
645
|
+
if (params == null ? void 0 : params.meetingType) queryParams['meeting_type'] = params.meetingType;
|
|
646
|
+
if (params == null ? void 0 : params.search) queryParams['search'] = params.search;
|
|
647
|
+
if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
|
|
648
|
+
const response = await transport.get('/meetings', {
|
|
649
|
+
params: queryParams
|
|
650
|
+
});
|
|
651
|
+
return decodePageResult(response, meetingMapper);
|
|
652
|
+
},
|
|
653
|
+
async get (uniqueId) {
|
|
654
|
+
const response = await transport.get(`/meetings/${uniqueId}`);
|
|
655
|
+
return decodeOne(response, meetingMapper);
|
|
656
|
+
},
|
|
657
|
+
async create (data) {
|
|
658
|
+
const response = await transport.post('/meetings', {
|
|
659
|
+
data: {
|
|
660
|
+
type: 'Meeting',
|
|
661
|
+
attributes: {
|
|
662
|
+
code: data.code,
|
|
663
|
+
title: data.title,
|
|
664
|
+
meeting_type: data.meetingType,
|
|
665
|
+
description: data.description,
|
|
666
|
+
scheduled_at: data.scheduledAt,
|
|
667
|
+
start_time: data.startTime,
|
|
668
|
+
end_time: data.endTime,
|
|
669
|
+
time_unit: data.timeUnit,
|
|
670
|
+
time_quantity: data.timeQuantity,
|
|
671
|
+
all_day: data.allDay,
|
|
672
|
+
timezone: data.timezone,
|
|
673
|
+
user_unique_id: data.userUniqueId,
|
|
674
|
+
account_unique_id: data.accountUniqueId,
|
|
675
|
+
meeting_location: data.meetingLocation,
|
|
676
|
+
meeting_url: data.meetingUrl,
|
|
677
|
+
payload: data.payload
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
});
|
|
681
|
+
return decodeOne(response, meetingMapper);
|
|
682
|
+
},
|
|
683
|
+
async update (uniqueId, data) {
|
|
684
|
+
const response = await transport.put(`/meetings/${uniqueId}`, {
|
|
685
|
+
data: {
|
|
686
|
+
type: 'Meeting',
|
|
687
|
+
attributes: {
|
|
688
|
+
title: data.title,
|
|
689
|
+
meeting_type: data.meetingType,
|
|
690
|
+
description: data.description,
|
|
691
|
+
scheduled_at: data.scheduledAt,
|
|
692
|
+
start_time: data.startTime,
|
|
693
|
+
end_time: data.endTime,
|
|
694
|
+
time_unit: data.timeUnit,
|
|
695
|
+
time_quantity: data.timeQuantity,
|
|
696
|
+
all_day: data.allDay,
|
|
697
|
+
timezone: data.timezone,
|
|
698
|
+
meeting_location: data.meetingLocation,
|
|
699
|
+
meeting_url: data.meetingUrl,
|
|
700
|
+
meeting_score: data.meetingScore,
|
|
701
|
+
enabled: data.enabled,
|
|
702
|
+
status: data.status,
|
|
703
|
+
payload: data.payload
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
});
|
|
707
|
+
return decodeOne(response, meetingMapper);
|
|
708
|
+
},
|
|
709
|
+
async delete (uniqueId) {
|
|
710
|
+
await transport.delete(`/meetings/${uniqueId}`);
|
|
711
|
+
},
|
|
712
|
+
async recover (uniqueId) {
|
|
713
|
+
const response = await transport.put(`/meetings/${uniqueId}/recover`, {});
|
|
714
|
+
return decodeOne(response, meetingMapper);
|
|
715
|
+
},
|
|
716
|
+
async search (query, params) {
|
|
717
|
+
const queryParams = {
|
|
718
|
+
search: query
|
|
719
|
+
};
|
|
720
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
721
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
722
|
+
const response = await transport.post('/meetings/search', {
|
|
723
|
+
search: query
|
|
724
|
+
}, {
|
|
725
|
+
params: queryParams
|
|
726
|
+
});
|
|
727
|
+
return decodePageResult(response, meetingMapper);
|
|
728
|
+
},
|
|
729
|
+
async listDeleted (params) {
|
|
730
|
+
const queryParams = {};
|
|
731
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
732
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
733
|
+
const response = await transport.get('/meetings/trash/show', {
|
|
734
|
+
params: queryParams
|
|
735
|
+
});
|
|
736
|
+
return decodePageResult(response, meetingMapper);
|
|
737
|
+
}
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
const quoteMapper = {
|
|
742
|
+
type: 'Quote',
|
|
743
|
+
map: (resource)=>({
|
|
744
|
+
id: resource.id,
|
|
745
|
+
uniqueId: parseString(resource.attributes['unique_id']) || resource.id,
|
|
746
|
+
createdAt: parseDate(resource.attributes['created_at']) || new Date(),
|
|
747
|
+
updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
|
|
748
|
+
accountUniqueId: parseString(resource.attributes['account_unique_id']),
|
|
749
|
+
contactUniqueId: parseString(resource.attributes['contact_unique_id']),
|
|
750
|
+
code: parseString(resource.attributes['code']) || '',
|
|
751
|
+
name: parseString(resource.attributes['name']) || '',
|
|
752
|
+
notes: parseString(resource.attributes['notes']),
|
|
753
|
+
budget: parseOptionalNumber(resource.attributes['budget']),
|
|
754
|
+
total: parseOptionalNumber(resource.attributes['total']),
|
|
755
|
+
duration: parseOptionalNumber(resource.attributes['duration']),
|
|
756
|
+
durationUnit: parseString(resource.attributes['duration_unit']),
|
|
757
|
+
durationDescription: parseString(resource.attributes['duration_description']),
|
|
758
|
+
payload: resource.attributes['payload'],
|
|
759
|
+
nextActionAt: parseDate(resource.attributes['next_action_at']),
|
|
760
|
+
ownerUniqueId: parseString(resource.attributes['owner_unique_id']),
|
|
761
|
+
ownerName: parseString(resource.attributes['owner_name']),
|
|
762
|
+
ownerEmail: parseString(resource.attributes['owner_email']),
|
|
763
|
+
status: parseStatus(resource.attributes['status']),
|
|
764
|
+
enabled: parseBoolean(resource.attributes['enabled']),
|
|
765
|
+
tags: parseStringArray(resource.attributes['tags'])
|
|
766
|
+
})
|
|
767
|
+
};
|
|
768
|
+
|
|
769
|
+
function createQuotesService(transport, _config) {
|
|
770
|
+
return {
|
|
771
|
+
async list (params) {
|
|
772
|
+
const queryParams = {};
|
|
773
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
774
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
775
|
+
if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
|
|
776
|
+
if (params == null ? void 0 : params.accountUniqueId) queryParams['account_unique_id'] = params.accountUniqueId;
|
|
777
|
+
if (params == null ? void 0 : params.contactUniqueId) queryParams['contact_unique_id'] = params.contactUniqueId;
|
|
778
|
+
if (params == null ? void 0 : params.ownerUniqueId) queryParams['owner_unique_id'] = params.ownerUniqueId;
|
|
779
|
+
if (params == null ? void 0 : params.search) queryParams['search'] = params.search;
|
|
780
|
+
if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
|
|
781
|
+
const response = await transport.get('/quotes', {
|
|
782
|
+
params: queryParams
|
|
783
|
+
});
|
|
784
|
+
return decodePageResult(response, quoteMapper);
|
|
785
|
+
},
|
|
786
|
+
async get (uniqueId) {
|
|
787
|
+
const response = await transport.get(`/quotes/${uniqueId}`);
|
|
788
|
+
return decodeOne(response, quoteMapper);
|
|
789
|
+
},
|
|
790
|
+
async create (data) {
|
|
791
|
+
const response = await transport.post('/quotes', {
|
|
792
|
+
data: {
|
|
793
|
+
type: 'Quote',
|
|
794
|
+
attributes: {
|
|
795
|
+
account_unique_id: data.accountUniqueId,
|
|
796
|
+
contact_unique_id: data.contactUniqueId,
|
|
797
|
+
code: data.code,
|
|
798
|
+
name: data.name,
|
|
799
|
+
notes: data.notes,
|
|
800
|
+
budget: data.budget,
|
|
801
|
+
total: data.total,
|
|
802
|
+
duration: data.duration,
|
|
803
|
+
duration_unit: data.durationUnit,
|
|
804
|
+
duration_description: data.durationDescription,
|
|
805
|
+
payload: data.payload,
|
|
806
|
+
next_action_at: data.nextActionAt,
|
|
807
|
+
owner_unique_id: data.ownerUniqueId,
|
|
808
|
+
tags: data.tags
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
});
|
|
812
|
+
return decodeOne(response, quoteMapper);
|
|
813
|
+
},
|
|
814
|
+
async update (uniqueId, data) {
|
|
815
|
+
const response = await transport.put(`/quotes/${uniqueId}`, {
|
|
816
|
+
data: {
|
|
817
|
+
type: 'Quote',
|
|
818
|
+
attributes: {
|
|
819
|
+
name: data.name,
|
|
820
|
+
notes: data.notes,
|
|
821
|
+
budget: data.budget,
|
|
822
|
+
total: data.total,
|
|
823
|
+
duration: data.duration,
|
|
824
|
+
duration_unit: data.durationUnit,
|
|
825
|
+
duration_description: data.durationDescription,
|
|
826
|
+
payload: data.payload,
|
|
827
|
+
next_action_at: data.nextActionAt,
|
|
828
|
+
owner_unique_id: data.ownerUniqueId,
|
|
829
|
+
owner_name: data.ownerName,
|
|
830
|
+
owner_email: data.ownerEmail,
|
|
831
|
+
enabled: data.enabled,
|
|
832
|
+
status: data.status,
|
|
833
|
+
tags: data.tags
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
});
|
|
837
|
+
return decodeOne(response, quoteMapper);
|
|
838
|
+
},
|
|
839
|
+
async delete (uniqueId) {
|
|
840
|
+
await transport.delete(`/quotes/${uniqueId}`);
|
|
841
|
+
},
|
|
842
|
+
async recover (uniqueId) {
|
|
843
|
+
const response = await transport.put(`/quotes/${uniqueId}/recover`, {});
|
|
844
|
+
return decodeOne(response, quoteMapper);
|
|
845
|
+
},
|
|
846
|
+
async search (query, params) {
|
|
847
|
+
const queryParams = {
|
|
848
|
+
search: query
|
|
849
|
+
};
|
|
850
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
851
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
852
|
+
const response = await transport.post('/quotes/search', {
|
|
853
|
+
search: query
|
|
854
|
+
}, {
|
|
855
|
+
params: queryParams
|
|
856
|
+
});
|
|
857
|
+
return decodePageResult(response, quoteMapper);
|
|
858
|
+
},
|
|
859
|
+
async listDeleted (params) {
|
|
860
|
+
const queryParams = {};
|
|
861
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
862
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
863
|
+
const response = await transport.get('/quotes/trash/show', {
|
|
864
|
+
params: queryParams
|
|
865
|
+
});
|
|
866
|
+
return decodePageResult(response, quoteMapper);
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
function createCrmBlock(transport, config) {
|
|
872
|
+
return {
|
|
873
|
+
accounts: createAccountsService(transport),
|
|
874
|
+
contacts: createContactsService(transport),
|
|
875
|
+
leads: createLeadsService(transport),
|
|
876
|
+
opportunities: createOpportunitiesService(transport),
|
|
877
|
+
meetings: createMeetingsService(transport),
|
|
878
|
+
quotes: createQuotesService(transport)
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
const crmBlockMetadata = {
|
|
882
|
+
name: 'crm',
|
|
883
|
+
version: '0.1.0',
|
|
884
|
+
description: 'CRM block for managing accounts, contacts, leads, opportunities, meetings, and quotes',
|
|
885
|
+
resourceTypes: [
|
|
886
|
+
'Account',
|
|
887
|
+
'AccountDetail',
|
|
888
|
+
'Contact',
|
|
889
|
+
'ContactProfile',
|
|
890
|
+
'Lead',
|
|
891
|
+
'Opportunity',
|
|
892
|
+
'Meeting',
|
|
893
|
+
'Quote'
|
|
894
|
+
]
|
|
895
|
+
};
|
|
896
|
+
|
|
897
|
+
export { accountDetailMapper, accountMapper, contactMapper, contactProfileMapper, createAccountsService, createContactsService, createCrmBlock, createLeadsService, createMeetingsService, createOpportunitiesService, createQuotesService, crmBlockMetadata, leadMapper, meetingMapper, opportunityMapper, quoteMapper };
|