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