@23blocks/block-conversations 1.0.3 → 2.0.0
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 +668 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/lib/conversations.block.d.ts +16 -0
- package/dist/src/lib/conversations.block.d.ts.map +1 -0
- package/dist/src/lib/mappers/draft-message.mapper.d.ts +4 -0
- package/dist/src/lib/mappers/draft-message.mapper.d.ts.map +1 -0
- package/dist/src/lib/mappers/group.mapper.d.ts +4 -0
- package/dist/src/lib/mappers/group.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/message.mapper.d.ts +4 -0
- package/dist/src/lib/mappers/message.mapper.d.ts.map +1 -0
- package/dist/src/lib/mappers/notification.mapper.d.ts +4 -0
- package/dist/src/lib/mappers/notification.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/conversations.service.d.ts +11 -0
- package/dist/src/lib/services/conversations.service.d.ts.map +1 -0
- package/dist/src/lib/services/draft-messages.service.d.ts +15 -0
- package/dist/src/lib/services/draft-messages.service.d.ts.map +1 -0
- package/dist/src/lib/services/groups.service.d.ts +18 -0
- package/dist/src/lib/services/groups.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/messages.service.d.ts +17 -0
- package/dist/src/lib/services/messages.service.d.ts.map +1 -0
- package/dist/src/lib/services/notifications.service.d.ts +17 -0
- package/dist/src/lib/services/notifications.service.d.ts.map +1 -0
- package/dist/src/lib/types/conversation.d.ts +29 -0
- package/dist/src/lib/types/conversation.d.ts.map +1 -0
- package/dist/src/lib/types/draft-message.d.ts +77 -0
- package/dist/src/lib/types/draft-message.d.ts.map +1 -0
- package/dist/src/lib/types/group.d.ts +50 -0
- package/dist/src/lib/types/group.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/message.d.ts +81 -0
- package/dist/src/lib/types/message.d.ts.map +1 -0
- package/dist/src/lib/types/notification.d.ts +56 -0
- package/dist/src/lib/types/notification.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/conversations.block.js +0 -24
- package/dist/lib/conversations.block.js.map +0 -1
- package/dist/lib/mappers/draft-message.mapper.js +0 -50
- package/dist/lib/mappers/draft-message.mapper.js.map +0 -1
- package/dist/lib/mappers/group.mapper.js +0 -29
- package/dist/lib/mappers/group.mapper.js.map +0 -1
- package/dist/lib/mappers/index.js.map +0 -1
- package/dist/lib/mappers/message.mapper.js +0 -53
- package/dist/lib/mappers/message.mapper.js.map +0 -1
- package/dist/lib/mappers/notification.mapper.js +0 -39
- package/dist/lib/mappers/notification.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/conversations.service.js +0 -38
- package/dist/lib/services/conversations.service.js.map +0 -1
- package/dist/lib/services/draft-messages.service.js +0 -94
- package/dist/lib/services/draft-messages.service.js.map +0 -1
- package/dist/lib/services/groups.service.js +0 -109
- package/dist/lib/services/groups.service.js.map +0 -1
- package/dist/lib/services/index.js.map +0 -1
- package/dist/lib/services/messages.service.js +0 -116
- package/dist/lib/services/messages.service.js.map +0 -1
- package/dist/lib/services/notifications.service.js +0 -100
- package/dist/lib/services/notifications.service.js.map +0 -1
- package/dist/lib/types/conversation.js +0 -4
- package/dist/lib/types/conversation.js.map +0 -1
- package/dist/lib/types/draft-message.js +0 -3
- package/dist/lib/types/draft-message.js.map +0 -1
- package/dist/lib/types/group.js +0 -3
- package/dist/lib/types/group.js.map +0 -1
- package/dist/lib/types/index.js.map +0 -1
- package/dist/lib/types/message.js +0 -3
- package/dist/lib/types/message.js.map +0 -1
- package/dist/lib/types/notification.js +0 -3
- package/dist/lib/types/notification.js.map +0 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|
|
@@ -0,0 +1,668 @@
|
|
|
1
|
+
import { decodePageResult, decodeOne, decodeMany } 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 messageMapper = {
|
|
69
|
+
type: 'Message',
|
|
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
|
+
contextId: parseString(resource.attributes['context_id']),
|
|
76
|
+
parentId: parseString(resource.attributes['parent_id']),
|
|
77
|
+
content: parseString(resource.attributes['content']) || '',
|
|
78
|
+
// Source (sender)
|
|
79
|
+
source: parseString(resource.attributes['source']),
|
|
80
|
+
sourceId: parseString(resource.attributes['source_id']),
|
|
81
|
+
sourceAlias: parseString(resource.attributes['source_alias']),
|
|
82
|
+
sourceEmail: parseString(resource.attributes['source_email']),
|
|
83
|
+
sourcePhone: parseString(resource.attributes['source_phone']),
|
|
84
|
+
sourceType: parseString(resource.attributes['source_type']),
|
|
85
|
+
// Target (recipient)
|
|
86
|
+
target: parseString(resource.attributes['target']),
|
|
87
|
+
targetId: parseString(resource.attributes['target_id']),
|
|
88
|
+
targetAlias: parseString(resource.attributes['target_alias']),
|
|
89
|
+
targetEmail: parseString(resource.attributes['target_email']),
|
|
90
|
+
targetPhone: parseString(resource.attributes['target_phone']),
|
|
91
|
+
targetType: parseString(resource.attributes['target_type']),
|
|
92
|
+
targetDeviceId: parseString(resource.attributes['target_device_id']),
|
|
93
|
+
// Value and data source
|
|
94
|
+
value: parseOptionalNumber(resource.attributes['value']),
|
|
95
|
+
dataSource: parseString(resource.attributes['data_source']),
|
|
96
|
+
dataSourceId: parseString(resource.attributes['data_source_id']),
|
|
97
|
+
dataSourceType: parseString(resource.attributes['data_source_type']),
|
|
98
|
+
dataSourceAlias: parseString(resource.attributes['data_source_alias']),
|
|
99
|
+
// Status
|
|
100
|
+
status: parseStatus(resource.attributes['status']),
|
|
101
|
+
enabled: parseBoolean(resource.attributes['enabled']),
|
|
102
|
+
// Extra data
|
|
103
|
+
payload: resource.attributes['payload'],
|
|
104
|
+
// Notification
|
|
105
|
+
notificationContent: parseString(resource.attributes['notification_content']),
|
|
106
|
+
notificationUrl: parseString(resource.attributes['notification_url']),
|
|
107
|
+
// Expiration
|
|
108
|
+
expiresAt: parseDate(resource.attributes['expires_at']),
|
|
109
|
+
// RAG sources
|
|
110
|
+
ragSources: parseStringArray(resource.attributes['rag_sources']),
|
|
111
|
+
// Idempotency
|
|
112
|
+
idempotencyKey: parseString(resource.attributes['idempotency_key']),
|
|
113
|
+
// Tracking
|
|
114
|
+
createdBy: parseString(resource.attributes['created_by']),
|
|
115
|
+
updatedBy: parseString(resource.attributes['updated_by'])
|
|
116
|
+
})
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
function createMessagesService(transport, _config) {
|
|
120
|
+
return {
|
|
121
|
+
async list (params) {
|
|
122
|
+
const queryParams = {};
|
|
123
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
124
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
125
|
+
if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
|
|
126
|
+
if (params == null ? void 0 : params.contextId) queryParams['context_id'] = params.contextId;
|
|
127
|
+
if (params == null ? void 0 : params.parentId) queryParams['parent_id'] = params.parentId;
|
|
128
|
+
if (params == null ? void 0 : params.sourceId) queryParams['source_id'] = params.sourceId;
|
|
129
|
+
if (params == null ? void 0 : params.targetId) queryParams['target_id'] = params.targetId;
|
|
130
|
+
if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
|
|
131
|
+
const response = await transport.get('/messages', {
|
|
132
|
+
params: queryParams
|
|
133
|
+
});
|
|
134
|
+
return decodePageResult(response, messageMapper);
|
|
135
|
+
},
|
|
136
|
+
async get (uniqueId) {
|
|
137
|
+
const response = await transport.get(`/messages/${uniqueId}`);
|
|
138
|
+
return decodeOne(response, messageMapper);
|
|
139
|
+
},
|
|
140
|
+
async create (data) {
|
|
141
|
+
const response = await transport.post('/messages', {
|
|
142
|
+
message: {
|
|
143
|
+
context_id: data.contextId,
|
|
144
|
+
parent_id: data.parentId,
|
|
145
|
+
content: data.content,
|
|
146
|
+
source: data.source,
|
|
147
|
+
source_id: data.sourceId,
|
|
148
|
+
source_alias: data.sourceAlias,
|
|
149
|
+
source_email: data.sourceEmail,
|
|
150
|
+
source_phone: data.sourcePhone,
|
|
151
|
+
source_type: data.sourceType,
|
|
152
|
+
target: data.target,
|
|
153
|
+
target_id: data.targetId,
|
|
154
|
+
target_alias: data.targetAlias,
|
|
155
|
+
target_email: data.targetEmail,
|
|
156
|
+
target_phone: data.targetPhone,
|
|
157
|
+
target_type: data.targetType,
|
|
158
|
+
target_device_id: data.targetDeviceId,
|
|
159
|
+
value: data.value,
|
|
160
|
+
data_source: data.dataSource,
|
|
161
|
+
data_source_id: data.dataSourceId,
|
|
162
|
+
data_source_type: data.dataSourceType,
|
|
163
|
+
data_source_alias: data.dataSourceAlias,
|
|
164
|
+
notification_content: data.notificationContent,
|
|
165
|
+
notification_url: data.notificationUrl,
|
|
166
|
+
expires_at: data.expiresAt,
|
|
167
|
+
rag_sources: data.ragSources,
|
|
168
|
+
idempotency_key: data.idempotencyKey,
|
|
169
|
+
payload: data.payload
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
return decodeOne(response, messageMapper);
|
|
173
|
+
},
|
|
174
|
+
async update (uniqueId, data) {
|
|
175
|
+
const response = await transport.put(`/messages/${uniqueId}`, {
|
|
176
|
+
message: {
|
|
177
|
+
content: data.content,
|
|
178
|
+
status: data.status,
|
|
179
|
+
enabled: data.enabled,
|
|
180
|
+
payload: data.payload
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
return decodeOne(response, messageMapper);
|
|
184
|
+
},
|
|
185
|
+
async delete (uniqueId) {
|
|
186
|
+
await transport.delete(`/messages/${uniqueId}`);
|
|
187
|
+
},
|
|
188
|
+
async recover (uniqueId) {
|
|
189
|
+
const response = await transport.put(`/messages/${uniqueId}/recover`, {});
|
|
190
|
+
return decodeOne(response, messageMapper);
|
|
191
|
+
},
|
|
192
|
+
async listByContext (contextId, params) {
|
|
193
|
+
const queryParams = {};
|
|
194
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
195
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
196
|
+
if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
|
|
197
|
+
if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
|
|
198
|
+
const response = await transport.get(`/messages/context/${contextId}`, {
|
|
199
|
+
params: queryParams
|
|
200
|
+
});
|
|
201
|
+
return decodePageResult(response, messageMapper);
|
|
202
|
+
},
|
|
203
|
+
async listByParent (parentId, params) {
|
|
204
|
+
const queryParams = {};
|
|
205
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
206
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
207
|
+
if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
|
|
208
|
+
if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
|
|
209
|
+
const response = await transport.get(`/messages/parent/${parentId}`, {
|
|
210
|
+
params: queryParams
|
|
211
|
+
});
|
|
212
|
+
return decodePageResult(response, messageMapper);
|
|
213
|
+
},
|
|
214
|
+
async listDeleted (params) {
|
|
215
|
+
const queryParams = {};
|
|
216
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
217
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
218
|
+
const response = await transport.get('/messages/trash/show', {
|
|
219
|
+
params: queryParams
|
|
220
|
+
});
|
|
221
|
+
return decodePageResult(response, messageMapper);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const draftMessageMapper = {
|
|
227
|
+
type: 'DraftMessage',
|
|
228
|
+
map: (resource)=>({
|
|
229
|
+
id: resource.id,
|
|
230
|
+
uniqueId: parseString(resource.attributes['unique_id']) || resource.id,
|
|
231
|
+
createdAt: parseDate(resource.attributes['created_at']) || new Date(),
|
|
232
|
+
updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
|
|
233
|
+
contextId: parseString(resource.attributes['context_id']),
|
|
234
|
+
parentId: parseString(resource.attributes['parent_id']),
|
|
235
|
+
content: parseString(resource.attributes['content']) || '',
|
|
236
|
+
// Source (sender)
|
|
237
|
+
source: parseString(resource.attributes['source']),
|
|
238
|
+
sourceId: parseString(resource.attributes['source_id']),
|
|
239
|
+
sourceAlias: parseString(resource.attributes['source_alias']),
|
|
240
|
+
sourceEmail: parseString(resource.attributes['source_email']),
|
|
241
|
+
sourcePhone: parseString(resource.attributes['source_phone']),
|
|
242
|
+
sourceType: parseString(resource.attributes['source_type']),
|
|
243
|
+
// Target (recipient)
|
|
244
|
+
target: parseString(resource.attributes['target']),
|
|
245
|
+
targetId: parseString(resource.attributes['target_id']),
|
|
246
|
+
targetAlias: parseString(resource.attributes['target_alias']),
|
|
247
|
+
targetEmail: parseString(resource.attributes['target_email']),
|
|
248
|
+
targetPhone: parseString(resource.attributes['target_phone']),
|
|
249
|
+
targetType: parseString(resource.attributes['target_type']),
|
|
250
|
+
targetDeviceId: parseString(resource.attributes['target_device_id']),
|
|
251
|
+
// Value and data source
|
|
252
|
+
value: parseOptionalNumber(resource.attributes['value']),
|
|
253
|
+
dataSource: parseString(resource.attributes['data_source']),
|
|
254
|
+
dataSourceId: parseString(resource.attributes['data_source_id']),
|
|
255
|
+
dataSourceType: parseString(resource.attributes['data_source_type']),
|
|
256
|
+
dataSourceAlias: parseString(resource.attributes['data_source_alias']),
|
|
257
|
+
// Status
|
|
258
|
+
status: parseStatus(resource.attributes['status']),
|
|
259
|
+
enabled: parseBoolean(resource.attributes['enabled']),
|
|
260
|
+
// Extra data
|
|
261
|
+
payload: resource.attributes['payload'],
|
|
262
|
+
// Notification
|
|
263
|
+
notificationContent: parseString(resource.attributes['notification_content']),
|
|
264
|
+
notificationUrl: parseString(resource.attributes['notification_url']),
|
|
265
|
+
// Expiration
|
|
266
|
+
expiresAt: parseDate(resource.attributes['expires_at']),
|
|
267
|
+
// RAG sources
|
|
268
|
+
ragSources: parseStringArray(resource.attributes['rag_sources']),
|
|
269
|
+
// Idempotency
|
|
270
|
+
idempotencyKey: parseString(resource.attributes['idempotency_key'])
|
|
271
|
+
})
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
function createDraftMessagesService(transport, _config) {
|
|
275
|
+
return {
|
|
276
|
+
async list (params) {
|
|
277
|
+
const queryParams = {};
|
|
278
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
279
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
280
|
+
if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
|
|
281
|
+
if (params == null ? void 0 : params.contextId) queryParams['context_id'] = params.contextId;
|
|
282
|
+
if (params == null ? void 0 : params.sourceId) queryParams['source_id'] = params.sourceId;
|
|
283
|
+
if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
|
|
284
|
+
const response = await transport.get('/draft_messages', {
|
|
285
|
+
params: queryParams
|
|
286
|
+
});
|
|
287
|
+
return decodePageResult(response, draftMessageMapper);
|
|
288
|
+
},
|
|
289
|
+
async get (uniqueId) {
|
|
290
|
+
const response = await transport.get(`/draft_messages/${uniqueId}`);
|
|
291
|
+
return decodeOne(response, draftMessageMapper);
|
|
292
|
+
},
|
|
293
|
+
async create (data) {
|
|
294
|
+
const response = await transport.post('/draft_messages', {
|
|
295
|
+
draft_message: {
|
|
296
|
+
context_id: data.contextId,
|
|
297
|
+
parent_id: data.parentId,
|
|
298
|
+
content: data.content,
|
|
299
|
+
source: data.source,
|
|
300
|
+
source_id: data.sourceId,
|
|
301
|
+
source_alias: data.sourceAlias,
|
|
302
|
+
source_email: data.sourceEmail,
|
|
303
|
+
source_phone: data.sourcePhone,
|
|
304
|
+
source_type: data.sourceType,
|
|
305
|
+
target: data.target,
|
|
306
|
+
target_id: data.targetId,
|
|
307
|
+
target_alias: data.targetAlias,
|
|
308
|
+
target_email: data.targetEmail,
|
|
309
|
+
target_phone: data.targetPhone,
|
|
310
|
+
target_type: data.targetType,
|
|
311
|
+
target_device_id: data.targetDeviceId,
|
|
312
|
+
value: data.value,
|
|
313
|
+
data_source: data.dataSource,
|
|
314
|
+
data_source_id: data.dataSourceId,
|
|
315
|
+
data_source_type: data.dataSourceType,
|
|
316
|
+
data_source_alias: data.dataSourceAlias,
|
|
317
|
+
notification_content: data.notificationContent,
|
|
318
|
+
notification_url: data.notificationUrl,
|
|
319
|
+
expires_at: data.expiresAt,
|
|
320
|
+
rag_sources: data.ragSources,
|
|
321
|
+
idempotency_key: data.idempotencyKey,
|
|
322
|
+
payload: data.payload
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
return decodeOne(response, draftMessageMapper);
|
|
326
|
+
},
|
|
327
|
+
async update (uniqueId, data) {
|
|
328
|
+
const response = await transport.put(`/draft_messages/${uniqueId}`, {
|
|
329
|
+
draft_message: {
|
|
330
|
+
content: data.content,
|
|
331
|
+
status: data.status,
|
|
332
|
+
enabled: data.enabled,
|
|
333
|
+
payload: data.payload
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
return decodeOne(response, draftMessageMapper);
|
|
337
|
+
},
|
|
338
|
+
async delete (uniqueId) {
|
|
339
|
+
await transport.delete(`/draft_messages/${uniqueId}`);
|
|
340
|
+
},
|
|
341
|
+
async listByContext (contextId, params) {
|
|
342
|
+
const queryParams = {};
|
|
343
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
344
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
345
|
+
if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
|
|
346
|
+
if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
|
|
347
|
+
const response = await transport.get(`/draft_messages/context/${contextId}`, {
|
|
348
|
+
params: queryParams
|
|
349
|
+
});
|
|
350
|
+
return decodePageResult(response, draftMessageMapper);
|
|
351
|
+
},
|
|
352
|
+
async publish (uniqueId) {
|
|
353
|
+
const response = await transport.put(`/draft_messages/${uniqueId}/publish`, {});
|
|
354
|
+
return decodeOne(response, draftMessageMapper);
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const groupMapper = {
|
|
360
|
+
type: 'Group',
|
|
361
|
+
map: (resource)=>({
|
|
362
|
+
id: resource.id,
|
|
363
|
+
uniqueId: parseString(resource.attributes['unique_id']) || resource.id,
|
|
364
|
+
createdAt: parseDate(resource.attributes['created_at']) || new Date(),
|
|
365
|
+
updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
|
|
366
|
+
name: parseString(resource.attributes['name']) || '',
|
|
367
|
+
code: parseString(resource.attributes['code']),
|
|
368
|
+
uniqueCode: parseString(resource.attributes['unique_code']),
|
|
369
|
+
qcode: parseString(resource.attributes['qcode']),
|
|
370
|
+
groupType: parseString(resource.attributes['group_type']),
|
|
371
|
+
// Members
|
|
372
|
+
members: parseStringArray(resource.attributes['members']),
|
|
373
|
+
// Status
|
|
374
|
+
status: parseStatus(resource.attributes['status']),
|
|
375
|
+
enabled: parseBoolean(resource.attributes['enabled']),
|
|
376
|
+
// Source
|
|
377
|
+
source: parseString(resource.attributes['source']),
|
|
378
|
+
sourceAlias: parseString(resource.attributes['source_alias']),
|
|
379
|
+
sourceId: parseString(resource.attributes['source_id']),
|
|
380
|
+
sourceType: parseString(resource.attributes['source_type']),
|
|
381
|
+
// Extra data
|
|
382
|
+
payload: resource.attributes['payload']
|
|
383
|
+
})
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
function createGroupsService(transport, _config) {
|
|
387
|
+
return {
|
|
388
|
+
async list (params) {
|
|
389
|
+
const queryParams = {};
|
|
390
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
391
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
392
|
+
if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
|
|
393
|
+
if (params == null ? void 0 : params.groupType) queryParams['group_type'] = params.groupType;
|
|
394
|
+
if (params == null ? void 0 : params.search) queryParams['search'] = params.search;
|
|
395
|
+
if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
|
|
396
|
+
const response = await transport.get('/groups', {
|
|
397
|
+
params: queryParams
|
|
398
|
+
});
|
|
399
|
+
return decodePageResult(response, groupMapper);
|
|
400
|
+
},
|
|
401
|
+
async get (uniqueId) {
|
|
402
|
+
const response = await transport.get(`/groups/${uniqueId}`);
|
|
403
|
+
return decodeOne(response, groupMapper);
|
|
404
|
+
},
|
|
405
|
+
async create (data) {
|
|
406
|
+
const response = await transport.post('/groups', {
|
|
407
|
+
group: {
|
|
408
|
+
name: data.name,
|
|
409
|
+
code: data.code,
|
|
410
|
+
unique_code: data.uniqueCode,
|
|
411
|
+
qcode: data.qcode,
|
|
412
|
+
group_type: data.groupType,
|
|
413
|
+
members: data.members,
|
|
414
|
+
source: data.source,
|
|
415
|
+
source_alias: data.sourceAlias,
|
|
416
|
+
source_id: data.sourceId,
|
|
417
|
+
source_type: data.sourceType,
|
|
418
|
+
payload: data.payload
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
return decodeOne(response, groupMapper);
|
|
422
|
+
},
|
|
423
|
+
async update (uniqueId, data) {
|
|
424
|
+
const response = await transport.put(`/groups/${uniqueId}`, {
|
|
425
|
+
group: {
|
|
426
|
+
name: data.name,
|
|
427
|
+
code: data.code,
|
|
428
|
+
unique_code: data.uniqueCode,
|
|
429
|
+
qcode: data.qcode,
|
|
430
|
+
group_type: data.groupType,
|
|
431
|
+
members: data.members,
|
|
432
|
+
status: data.status,
|
|
433
|
+
enabled: data.enabled,
|
|
434
|
+
payload: data.payload
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
return decodeOne(response, groupMapper);
|
|
438
|
+
},
|
|
439
|
+
async delete (uniqueId) {
|
|
440
|
+
await transport.delete(`/groups/${uniqueId}`);
|
|
441
|
+
},
|
|
442
|
+
async recover (uniqueId) {
|
|
443
|
+
const response = await transport.put(`/groups/${uniqueId}/recover`, {});
|
|
444
|
+
return decodeOne(response, groupMapper);
|
|
445
|
+
},
|
|
446
|
+
async search (query, params) {
|
|
447
|
+
const queryParams = {
|
|
448
|
+
search: query
|
|
449
|
+
};
|
|
450
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
451
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
452
|
+
const response = await transport.post('/groups/search', {
|
|
453
|
+
search: query
|
|
454
|
+
}, {
|
|
455
|
+
params: queryParams
|
|
456
|
+
});
|
|
457
|
+
return decodePageResult(response, groupMapper);
|
|
458
|
+
},
|
|
459
|
+
async listDeleted (params) {
|
|
460
|
+
const queryParams = {};
|
|
461
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
462
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
463
|
+
const response = await transport.get('/groups/trash/show', {
|
|
464
|
+
params: queryParams
|
|
465
|
+
});
|
|
466
|
+
return decodePageResult(response, groupMapper);
|
|
467
|
+
},
|
|
468
|
+
async addMember (uniqueId, memberId) {
|
|
469
|
+
const response = await transport.post(`/groups/${uniqueId}/members`, {
|
|
470
|
+
groupmember: {
|
|
471
|
+
member_id: memberId
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
return decodeOne(response, groupMapper);
|
|
475
|
+
},
|
|
476
|
+
async removeMember (uniqueId, memberId) {
|
|
477
|
+
const response = await transport.delete(`/groups/${uniqueId}/members/${memberId}`);
|
|
478
|
+
return decodeOne(response, groupMapper);
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
const notificationMapper = {
|
|
484
|
+
type: 'Notification',
|
|
485
|
+
map: (resource)=>({
|
|
486
|
+
id: resource.id,
|
|
487
|
+
uniqueId: parseString(resource.attributes['unique_id']) || resource.id,
|
|
488
|
+
createdAt: parseDate(resource.attributes['created_at']) || new Date(),
|
|
489
|
+
updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
|
|
490
|
+
content: parseString(resource.attributes['content']) || '',
|
|
491
|
+
// Source
|
|
492
|
+
source: parseString(resource.attributes['source']),
|
|
493
|
+
sourceAlias: parseString(resource.attributes['source_alias']),
|
|
494
|
+
sourceId: parseString(resource.attributes['source_id']),
|
|
495
|
+
sourceType: parseString(resource.attributes['source_type']),
|
|
496
|
+
// URL
|
|
497
|
+
url: parseString(resource.attributes['url']),
|
|
498
|
+
// Status
|
|
499
|
+
status: parseStatus(resource.attributes['status']),
|
|
500
|
+
// Target
|
|
501
|
+
target: parseString(resource.attributes['target']),
|
|
502
|
+
targetId: parseString(resource.attributes['target_id']),
|
|
503
|
+
targetAlias: parseString(resource.attributes['target_alias']),
|
|
504
|
+
targetType: parseString(resource.attributes['target_type']),
|
|
505
|
+
targetEmail: parseString(resource.attributes['target_email']),
|
|
506
|
+
targetPhone: parseString(resource.attributes['target_phone']),
|
|
507
|
+
targetDeviceId: parseString(resource.attributes['target_device_id']),
|
|
508
|
+
// Multichannel
|
|
509
|
+
multichannel: parseBoolean(resource.attributes['multichannel']),
|
|
510
|
+
// Extra data
|
|
511
|
+
payload: resource.attributes['payload'],
|
|
512
|
+
// Expiration
|
|
513
|
+
expiresAt: parseDate(resource.attributes['expires_at']),
|
|
514
|
+
// Tracking
|
|
515
|
+
createdBy: parseString(resource.attributes['created_by']),
|
|
516
|
+
updatedBy: parseString(resource.attributes['updated_by'])
|
|
517
|
+
})
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
function createNotificationsService(transport, _config) {
|
|
521
|
+
return {
|
|
522
|
+
async list (params) {
|
|
523
|
+
const queryParams = {};
|
|
524
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
525
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
526
|
+
if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
|
|
527
|
+
if (params == null ? void 0 : params.targetId) queryParams['target_id'] = params.targetId;
|
|
528
|
+
if (params == null ? void 0 : params.sourceId) queryParams['source_id'] = params.sourceId;
|
|
529
|
+
if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
|
|
530
|
+
const response = await transport.get('/notifications', {
|
|
531
|
+
params: queryParams
|
|
532
|
+
});
|
|
533
|
+
return decodePageResult(response, notificationMapper);
|
|
534
|
+
},
|
|
535
|
+
async get (uniqueId) {
|
|
536
|
+
const response = await transport.get(`/notifications/${uniqueId}`);
|
|
537
|
+
return decodeOne(response, notificationMapper);
|
|
538
|
+
},
|
|
539
|
+
async create (data) {
|
|
540
|
+
const response = await transport.post('/notifications', {
|
|
541
|
+
notification: {
|
|
542
|
+
content: data.content,
|
|
543
|
+
source: data.source,
|
|
544
|
+
source_alias: data.sourceAlias,
|
|
545
|
+
source_id: data.sourceId,
|
|
546
|
+
source_type: data.sourceType,
|
|
547
|
+
url: data.url,
|
|
548
|
+
target: data.target,
|
|
549
|
+
target_id: data.targetId,
|
|
550
|
+
target_alias: data.targetAlias,
|
|
551
|
+
target_type: data.targetType,
|
|
552
|
+
target_email: data.targetEmail,
|
|
553
|
+
target_phone: data.targetPhone,
|
|
554
|
+
target_device_id: data.targetDeviceId,
|
|
555
|
+
multichannel: data.multichannel,
|
|
556
|
+
expires_at: data.expiresAt,
|
|
557
|
+
payload: data.payload
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
return decodeOne(response, notificationMapper);
|
|
561
|
+
},
|
|
562
|
+
async update (uniqueId, data) {
|
|
563
|
+
const response = await transport.put(`/notifications/${uniqueId}`, {
|
|
564
|
+
notification: {
|
|
565
|
+
content: data.content,
|
|
566
|
+
url: data.url,
|
|
567
|
+
status: data.status,
|
|
568
|
+
payload: data.payload
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
return decodeOne(response, notificationMapper);
|
|
572
|
+
},
|
|
573
|
+
async delete (uniqueId) {
|
|
574
|
+
await transport.delete(`/notifications/${uniqueId}`);
|
|
575
|
+
},
|
|
576
|
+
async markAsRead (uniqueId) {
|
|
577
|
+
const response = await transport.put(`/notifications/${uniqueId}/read`, {});
|
|
578
|
+
return decodeOne(response, notificationMapper);
|
|
579
|
+
},
|
|
580
|
+
async markAsUnread (uniqueId) {
|
|
581
|
+
const response = await transport.put(`/notifications/${uniqueId}/unread`, {});
|
|
582
|
+
return decodeOne(response, notificationMapper);
|
|
583
|
+
},
|
|
584
|
+
async listByTarget (targetId, params) {
|
|
585
|
+
const queryParams = {};
|
|
586
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
587
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
588
|
+
if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
|
|
589
|
+
if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
|
|
590
|
+
const response = await transport.get(`/notifications/target/${targetId}`, {
|
|
591
|
+
params: queryParams
|
|
592
|
+
});
|
|
593
|
+
return decodePageResult(response, notificationMapper);
|
|
594
|
+
},
|
|
595
|
+
async listUnread (params) {
|
|
596
|
+
const queryParams = {
|
|
597
|
+
status: 'pending'
|
|
598
|
+
};
|
|
599
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
600
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
601
|
+
if (params == null ? void 0 : params.targetId) queryParams['target_id'] = params.targetId;
|
|
602
|
+
if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
|
|
603
|
+
const response = await transport.get('/notifications/unread', {
|
|
604
|
+
params: queryParams
|
|
605
|
+
});
|
|
606
|
+
return decodePageResult(response, notificationMapper);
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
function createConversationsService(transport, _config) {
|
|
612
|
+
return {
|
|
613
|
+
async get (params) {
|
|
614
|
+
const queryParams = {};
|
|
615
|
+
if (params.page) queryParams['page'] = String(params.page);
|
|
616
|
+
if (params.perPage) queryParams['records'] = String(params.perPage);
|
|
617
|
+
if (params.includeFiles) queryParams['with'] = 'files';
|
|
618
|
+
const response = await transport.get(`/conversations/${params.context}`, {
|
|
619
|
+
params: queryParams
|
|
620
|
+
});
|
|
621
|
+
// Decode messages
|
|
622
|
+
const messages = decodeMany(response, messageMapper);
|
|
623
|
+
// Extract files and meta from response if available
|
|
624
|
+
const rawResponse = response;
|
|
625
|
+
const files = rawResponse.files || [];
|
|
626
|
+
const meta = rawResponse.meta || {};
|
|
627
|
+
return {
|
|
628
|
+
id: params.context,
|
|
629
|
+
context: params.context,
|
|
630
|
+
messages,
|
|
631
|
+
files,
|
|
632
|
+
meta
|
|
633
|
+
};
|
|
634
|
+
},
|
|
635
|
+
async listContexts () {
|
|
636
|
+
var _response_data;
|
|
637
|
+
const response = await transport.get('/conversations/contexts');
|
|
638
|
+
return ((_response_data = response.data) == null ? void 0 : _response_data.contexts) || [];
|
|
639
|
+
},
|
|
640
|
+
async deleteContext (context) {
|
|
641
|
+
await transport.delete(`/conversations/${context}`);
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
function createConversationsBlock(transport, config) {
|
|
647
|
+
return {
|
|
648
|
+
messages: createMessagesService(transport),
|
|
649
|
+
draftMessages: createDraftMessagesService(transport),
|
|
650
|
+
groups: createGroupsService(transport),
|
|
651
|
+
notifications: createNotificationsService(transport),
|
|
652
|
+
conversations: createConversationsService(transport)
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
const conversationsBlockMetadata = {
|
|
656
|
+
name: 'conversations',
|
|
657
|
+
version: '0.1.0',
|
|
658
|
+
description: 'Messaging, conversations, groups, and notifications management',
|
|
659
|
+
resourceTypes: [
|
|
660
|
+
'Message',
|
|
661
|
+
'DraftMessage',
|
|
662
|
+
'Group',
|
|
663
|
+
'Notification',
|
|
664
|
+
'Conversation'
|
|
665
|
+
]
|
|
666
|
+
};
|
|
667
|
+
|
|
668
|
+
export { conversationsBlockMetadata, createConversationsBlock, createConversationsService, createDraftMessagesService, createGroupsService, createMessagesService, createNotificationsService, draftMessageMapper, groupMapper, messageMapper, notificationMapper };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createConversationsBlock, conversationsBlockMetadata } from './lib/conversations.block';
|
|
2
|
+
export type { ConversationsBlock, ConversationsBlockConfig } from './lib/conversations.block';
|
|
3
|
+
export type { Message, CreateMessageRequest, UpdateMessageRequest, ListMessagesParams, DraftMessage, CreateDraftMessageRequest, UpdateDraftMessageRequest, ListDraftMessagesParams, Group, CreateGroupRequest, UpdateGroupRequest, ListGroupsParams, Notification, CreateNotificationRequest, UpdateNotificationRequest, ListNotificationsParams, Conversation, ConversationFile, ConversationMeta, GetConversationParams, } from './lib/types';
|
|
4
|
+
export type { MessagesService, DraftMessagesService, GroupsService, NotificationsService, ConversationsService, } from './lib/services';
|
|
5
|
+
export { createMessagesService, createDraftMessagesService, createGroupsService, createNotificationsService, createConversationsService, } from './lib/services';
|
|
6
|
+
export { messageMapper, draftMessageMapper, groupMapper, notificationMapper, } from './lib/mappers';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|