@23blocks/block-conversations 1.0.4 → 2.1.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.
Files changed (52) hide show
  1. package/dist/index.esm.js +512 -143
  2. package/dist/src/index.d.ts +4 -4
  3. package/dist/src/index.d.ts.map +1 -1
  4. package/dist/src/lib/conversations.block.d.ts +8 -1
  5. package/dist/src/lib/conversations.block.d.ts.map +1 -1
  6. package/dist/src/lib/mappers/context.mapper.d.ts +4 -0
  7. package/dist/src/lib/mappers/context.mapper.d.ts.map +1 -0
  8. package/dist/src/lib/mappers/index.d.ts +4 -0
  9. package/dist/src/lib/mappers/index.d.ts.map +1 -1
  10. package/dist/src/lib/mappers/message-file.mapper.d.ts +4 -0
  11. package/dist/src/lib/mappers/message-file.mapper.d.ts.map +1 -0
  12. package/dist/src/lib/mappers/source.mapper.d.ts +4 -0
  13. package/dist/src/lib/mappers/source.mapper.d.ts.map +1 -0
  14. package/dist/src/lib/mappers/user.mapper.d.ts +4 -0
  15. package/dist/src/lib/mappers/user.mapper.d.ts.map +1 -0
  16. package/dist/src/lib/services/availabilities.service.d.ts +11 -0
  17. package/dist/src/lib/services/availabilities.service.d.ts.map +1 -0
  18. package/dist/src/lib/services/contexts.service.d.ts +14 -0
  19. package/dist/src/lib/services/contexts.service.d.ts.map +1 -0
  20. package/dist/src/lib/services/draft-messages.service.d.ts.map +1 -1
  21. package/dist/src/lib/services/groups.service.d.ts.map +1 -1
  22. package/dist/src/lib/services/index.d.ts +7 -0
  23. package/dist/src/lib/services/index.d.ts.map +1 -1
  24. package/dist/src/lib/services/message-files.service.d.ts +12 -0
  25. package/dist/src/lib/services/message-files.service.d.ts.map +1 -0
  26. package/dist/src/lib/services/messages.service.d.ts.map +1 -1
  27. package/dist/src/lib/services/notification-settings.service.d.ts +10 -0
  28. package/dist/src/lib/services/notification-settings.service.d.ts.map +1 -0
  29. package/dist/src/lib/services/notifications.service.d.ts.map +1 -1
  30. package/dist/src/lib/services/sources.service.d.ts +9 -0
  31. package/dist/src/lib/services/sources.service.d.ts.map +1 -0
  32. package/dist/src/lib/services/users.service.d.ts +24 -0
  33. package/dist/src/lib/services/users.service.d.ts.map +1 -0
  34. package/dist/src/lib/services/websocket-tokens.service.d.ts +9 -0
  35. package/dist/src/lib/services/websocket-tokens.service.d.ts.map +1 -0
  36. package/dist/src/lib/types/availability.d.ts +13 -0
  37. package/dist/src/lib/types/availability.d.ts.map +1 -0
  38. package/dist/src/lib/types/context.d.ts +36 -0
  39. package/dist/src/lib/types/context.d.ts.map +1 -0
  40. package/dist/src/lib/types/index.d.ts +7 -0
  41. package/dist/src/lib/types/index.d.ts.map +1 -1
  42. package/dist/src/lib/types/message-file.d.ts +42 -0
  43. package/dist/src/lib/types/message-file.d.ts.map +1 -0
  44. package/dist/src/lib/types/notification-settings.d.ts +24 -0
  45. package/dist/src/lib/types/notification-settings.d.ts.map +1 -0
  46. package/dist/src/lib/types/source.d.ts +12 -0
  47. package/dist/src/lib/types/source.d.ts.map +1 -0
  48. package/dist/src/lib/types/user.d.ts +35 -0
  49. package/dist/src/lib/types/user.d.ts.map +1 -0
  50. package/dist/src/lib/types/websocket-token.d.ts +17 -0
  51. package/dist/src/lib/types/websocket-token.d.ts.map +1 -0
  52. package/package.json +1 -1
package/dist/index.esm.js CHANGED
@@ -139,51 +139,45 @@ function createMessagesService(transport, _config) {
139
139
  },
140
140
  async create (data) {
141
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
- }
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
173
170
  }
174
171
  });
175
172
  return decodeOne(response, messageMapper);
176
173
  },
177
174
  async update (uniqueId, data) {
178
175
  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
- }
176
+ message: {
177
+ content: data.content,
178
+ status: data.status,
179
+ enabled: data.enabled,
180
+ payload: data.payload
187
181
  }
188
182
  });
189
183
  return decodeOne(response, messageMapper);
@@ -298,51 +292,45 @@ function createDraftMessagesService(transport, _config) {
298
292
  },
299
293
  async create (data) {
300
294
  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
- }
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
332
323
  }
333
324
  });
334
325
  return decodeOne(response, draftMessageMapper);
335
326
  },
336
327
  async update (uniqueId, data) {
337
328
  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
- }
329
+ draft_message: {
330
+ content: data.content,
331
+ status: data.status,
332
+ enabled: data.enabled,
333
+ payload: data.payload
346
334
  }
347
335
  });
348
336
  return decodeOne(response, draftMessageMapper);
@@ -416,40 +404,34 @@ function createGroupsService(transport, _config) {
416
404
  },
417
405
  async create (data) {
418
406
  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
- }
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
434
419
  }
435
420
  });
436
421
  return decodeOne(response, groupMapper);
437
422
  },
438
423
  async update (uniqueId, data) {
439
424
  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
- }
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
453
435
  }
454
436
  });
455
437
  return decodeOne(response, groupMapper);
@@ -485,11 +467,8 @@ function createGroupsService(transport, _config) {
485
467
  },
486
468
  async addMember (uniqueId, memberId) {
487
469
  const response = await transport.post(`/groups/${uniqueId}/members`, {
488
- data: {
489
- type: 'GroupMember',
490
- attributes: {
491
- member_id: memberId
492
- }
470
+ groupmember: {
471
+ member_id: memberId
493
472
  }
494
473
  });
495
474
  return decodeOne(response, groupMapper);
@@ -559,40 +538,34 @@ function createNotificationsService(transport, _config) {
559
538
  },
560
539
  async create (data) {
561
540
  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
- }
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
582
558
  }
583
559
  });
584
560
  return decodeOne(response, notificationMapper);
585
561
  },
586
562
  async update (uniqueId, data) {
587
563
  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
- }
564
+ notification: {
565
+ content: data.content,
566
+ url: data.url,
567
+ status: data.status,
568
+ payload: data.payload
596
569
  }
597
570
  });
598
571
  return decodeOne(response, notificationMapper);
@@ -670,26 +643,422 @@ function createConversationsService(transport, _config) {
670
643
  };
671
644
  }
672
645
 
646
+ function createWebSocketTokensService(transport, _config) {
647
+ return {
648
+ async create (data) {
649
+ const response = await transport.post('/api/websocket_tokens', {
650
+ websocket_token: {
651
+ channel: data == null ? void 0 : data.channel,
652
+ user_id: data == null ? void 0 : data.userId
653
+ }
654
+ });
655
+ const result = response.data;
656
+ return {
657
+ token: result.token,
658
+ expiresAt: result.expiresAt ? new Date(result.expiresAt) : undefined,
659
+ channel: result.channel,
660
+ url: result.url
661
+ };
662
+ }
663
+ };
664
+ }
665
+
666
+ const contextMapper = {
667
+ type: 'Context',
668
+ map: (resource)=>({
669
+ id: resource.id,
670
+ uniqueId: parseString(resource.attributes['unique_id']) || resource.id,
671
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
672
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
673
+ name: parseString(resource.attributes['name']),
674
+ description: parseString(resource.attributes['description']),
675
+ contextType: parseString(resource.attributes['context_type']),
676
+ status: parseString(resource.attributes['status']),
677
+ metadata: resource.attributes['metadata'],
678
+ payload: resource.attributes['payload']
679
+ })
680
+ };
681
+
682
+ function createContextsService(transport, _config) {
683
+ return {
684
+ async list (params) {
685
+ const queryParams = {};
686
+ if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
687
+ if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
688
+ if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
689
+ if (params == null ? void 0 : params.contextType) queryParams['context_type'] = params.contextType;
690
+ if (params == null ? void 0 : params.search) queryParams['search'] = params.search;
691
+ if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
692
+ const response = await transport.get('/contexts', {
693
+ params: queryParams
694
+ });
695
+ return decodePageResult(response, contextMapper);
696
+ },
697
+ async get (uniqueId) {
698
+ const response = await transport.get(`/contexts/${uniqueId}`);
699
+ return decodeOne(response, contextMapper);
700
+ },
701
+ async create (data) {
702
+ const response = await transport.post('/contexts', {
703
+ context: {
704
+ name: data.name,
705
+ description: data.description,
706
+ context_type: data.contextType,
707
+ metadata: data.metadata,
708
+ payload: data.payload
709
+ }
710
+ });
711
+ return decodeOne(response, contextMapper);
712
+ },
713
+ async update (uniqueId, data) {
714
+ const response = await transport.put(`/contexts/${uniqueId}`, {
715
+ context: {
716
+ name: data.name,
717
+ description: data.description,
718
+ context_type: data.contextType,
719
+ status: data.status,
720
+ metadata: data.metadata,
721
+ payload: data.payload
722
+ }
723
+ });
724
+ return decodeOne(response, contextMapper);
725
+ },
726
+ async listGroups (contextUniqueId) {
727
+ const response = await transport.get(`/context/${contextUniqueId}/groups`);
728
+ return decodePageResult(response, groupMapper);
729
+ }
730
+ };
731
+ }
732
+
733
+ function createNotificationSettingsService(transport, _config) {
734
+ return {
735
+ async get (userUniqueId) {
736
+ var _response_data;
737
+ const response = await transport.get(`/users/${userUniqueId}/notifications/settings`);
738
+ const attrs = ((_response_data = response.data) == null ? void 0 : _response_data.attributes) || response.data || {};
739
+ return {
740
+ userUniqueId,
741
+ emailEnabled: attrs.email_enabled,
742
+ pushEnabled: attrs.push_enabled,
743
+ smsEnabled: attrs.sms_enabled,
744
+ inAppEnabled: attrs.in_app_enabled,
745
+ quietHoursStart: attrs.quiet_hours_start,
746
+ quietHoursEnd: attrs.quiet_hours_end,
747
+ timezone: attrs.timezone,
748
+ preferences: attrs.preferences,
749
+ payload: attrs.payload
750
+ };
751
+ },
752
+ async update (userUniqueId, data) {
753
+ var _response_data;
754
+ const response = await transport.put(`/users/${userUniqueId}/notifications/settings`, {
755
+ notification_settings: {
756
+ email_enabled: data.emailEnabled,
757
+ push_enabled: data.pushEnabled,
758
+ sms_enabled: data.smsEnabled,
759
+ in_app_enabled: data.inAppEnabled,
760
+ quiet_hours_start: data.quietHoursStart,
761
+ quiet_hours_end: data.quietHoursEnd,
762
+ timezone: data.timezone,
763
+ preferences: data.preferences,
764
+ payload: data.payload
765
+ }
766
+ });
767
+ const attrs = ((_response_data = response.data) == null ? void 0 : _response_data.attributes) || response.data || {};
768
+ return {
769
+ userUniqueId,
770
+ emailEnabled: attrs.email_enabled,
771
+ pushEnabled: attrs.push_enabled,
772
+ smsEnabled: attrs.sms_enabled,
773
+ inAppEnabled: attrs.in_app_enabled,
774
+ quietHoursStart: attrs.quiet_hours_start,
775
+ quietHoursEnd: attrs.quiet_hours_end,
776
+ timezone: attrs.timezone,
777
+ preferences: attrs.preferences,
778
+ payload: attrs.payload
779
+ };
780
+ }
781
+ };
782
+ }
783
+
784
+ function createAvailabilitiesService(transport, _config) {
785
+ return {
786
+ async get (userUniqueId) {
787
+ var _response_data;
788
+ const response = await transport.get(`/users/${userUniqueId}/status`);
789
+ const attrs = ((_response_data = response.data) == null ? void 0 : _response_data.attributes) || response.data || {};
790
+ return {
791
+ userUniqueId,
792
+ status: attrs.status || 'offline',
793
+ lastSeenAt: attrs.last_seen_at ? new Date(attrs.last_seen_at) : undefined,
794
+ customStatus: attrs.custom_status,
795
+ payload: attrs.payload
796
+ };
797
+ },
798
+ async goOnline (data) {
799
+ var _response_data;
800
+ const response = await transport.post('/users/status', {
801
+ availability: {
802
+ status: (data == null ? void 0 : data.status) || 'online',
803
+ custom_status: data == null ? void 0 : data.customStatus,
804
+ payload: data == null ? void 0 : data.payload
805
+ }
806
+ });
807
+ const attrs = ((_response_data = response.data) == null ? void 0 : _response_data.attributes) || response.data || {};
808
+ return {
809
+ userUniqueId: attrs.user_unique_id,
810
+ status: attrs.status || 'online',
811
+ lastSeenAt: attrs.last_seen_at ? new Date(attrs.last_seen_at) : undefined,
812
+ customStatus: attrs.custom_status,
813
+ payload: attrs.payload
814
+ };
815
+ },
816
+ async goOffline () {
817
+ await transport.delete('/users/status');
818
+ }
819
+ };
820
+ }
821
+
822
+ const messageFileMapper = {
823
+ type: 'MessageFile',
824
+ map: (resource)=>({
825
+ id: resource.id,
826
+ uniqueId: parseString(resource.attributes['unique_id']) || resource.id,
827
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
828
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
829
+ conversationUniqueId: parseString(resource.attributes['conversation_unique_id']),
830
+ messageUniqueId: parseString(resource.attributes['message_unique_id']),
831
+ name: parseString(resource.attributes['name']) || '',
832
+ originalName: parseString(resource.attributes['original_name']),
833
+ contentType: parseString(resource.attributes['content_type']),
834
+ size: parseOptionalNumber(resource.attributes['size']),
835
+ url: parseString(resource.attributes['url']),
836
+ thumbnailUrl: parseString(resource.attributes['thumbnail_url']),
837
+ status: parseString(resource.attributes['status']),
838
+ payload: resource.attributes['payload']
839
+ })
840
+ };
841
+
842
+ function createMessageFilesService(transport, _config) {
843
+ return {
844
+ async get (conversationUniqueId, fileUniqueId) {
845
+ const response = await transport.get(`/conversations/${conversationUniqueId}/files/${fileUniqueId}`);
846
+ return decodeOne(response, messageFileMapper);
847
+ },
848
+ async create (conversationUniqueId, data) {
849
+ const response = await transport.post(`/conversations/${conversationUniqueId}/files`, {
850
+ message_file: {
851
+ name: data.name,
852
+ content_type: data.contentType,
853
+ size: data.size,
854
+ url: data.url,
855
+ message_unique_id: data.messageUniqueId,
856
+ payload: data.payload
857
+ }
858
+ });
859
+ return decodeOne(response, messageFileMapper);
860
+ },
861
+ async delete (conversationUniqueId, fileUniqueId) {
862
+ await transport.delete(`/conversations/${conversationUniqueId}/files/${fileUniqueId}`);
863
+ },
864
+ async presign (conversationUniqueId, data) {
865
+ const response = await transport.put(`/conversations/${conversationUniqueId}/presign`, {
866
+ file: {
867
+ filename: data.filename,
868
+ content_type: data.contentType,
869
+ size: data.size
870
+ }
871
+ });
872
+ const result = response.data || response;
873
+ return {
874
+ uploadUrl: result.upload_url || result.uploadUrl,
875
+ fileUrl: result.file_url || result.fileUrl,
876
+ fields: result.fields,
877
+ expiresAt: result.expires_at ? new Date(result.expires_at) : undefined
878
+ };
879
+ }
880
+ };
881
+ }
882
+
883
+ const sourceMapper = {
884
+ type: 'Source',
885
+ map: (resource)=>({
886
+ id: resource.id,
887
+ uniqueId: parseString(resource.attributes['unique_id']) || resource.id,
888
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
889
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
890
+ name: parseString(resource.attributes['name']),
891
+ sourceType: parseString(resource.attributes['source_type']),
892
+ externalId: parseString(resource.attributes['external_id']),
893
+ status: parseString(resource.attributes['status']),
894
+ metadata: resource.attributes['metadata'],
895
+ payload: resource.attributes['payload']
896
+ })
897
+ };
898
+
899
+ function createSourcesService(transport, _config) {
900
+ return {
901
+ async get (uniqueId) {
902
+ const response = await transport.get(`/sources/${uniqueId}`);
903
+ return decodeOne(response, sourceMapper);
904
+ }
905
+ };
906
+ }
907
+
908
+ const conversationsUserMapper = {
909
+ type: 'User',
910
+ map: (resource)=>({
911
+ id: resource.id,
912
+ uniqueId: parseString(resource.attributes['unique_id']) || resource.id,
913
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
914
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
915
+ email: parseString(resource.attributes['email']),
916
+ name: parseString(resource.attributes['name']),
917
+ username: parseString(resource.attributes['username']),
918
+ avatarUrl: parseString(resource.attributes['avatar_url']),
919
+ status: parseString(resource.attributes['status']),
920
+ lastSeenAt: parseDate(resource.attributes['last_seen_at']),
921
+ payload: resource.attributes['payload']
922
+ })
923
+ };
924
+
925
+ function createUsersService(transport, _config) {
926
+ return {
927
+ async list (params) {
928
+ const queryParams = {};
929
+ if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
930
+ if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
931
+ if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
932
+ if (params == null ? void 0 : params.search) queryParams['search'] = params.search;
933
+ if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
934
+ const response = await transport.get('/users', {
935
+ params: queryParams
936
+ });
937
+ return decodePageResult(response, conversationsUserMapper);
938
+ },
939
+ async get (uniqueId) {
940
+ const response = await transport.get(`/users/${uniqueId}`);
941
+ return decodeOne(response, conversationsUserMapper);
942
+ },
943
+ async register (uniqueId, data) {
944
+ const response = await transport.post(`/users/${uniqueId}/register`, {
945
+ user: {
946
+ email: data == null ? void 0 : data.email,
947
+ name: data == null ? void 0 : data.name,
948
+ username: data == null ? void 0 : data.username,
949
+ avatar_url: data == null ? void 0 : data.avatarUrl,
950
+ payload: data == null ? void 0 : data.payload
951
+ }
952
+ });
953
+ return decodeOne(response, conversationsUserMapper);
954
+ },
955
+ async update (uniqueId, data) {
956
+ const response = await transport.put(`/users/${uniqueId}`, {
957
+ user: {
958
+ name: data.name,
959
+ username: data.username,
960
+ avatar_url: data.avatarUrl,
961
+ status: data.status,
962
+ payload: data.payload
963
+ }
964
+ });
965
+ return decodeOne(response, conversationsUserMapper);
966
+ },
967
+ async listGroups (uniqueId) {
968
+ const response = await transport.get(`/users/${uniqueId}/groups`);
969
+ return decodePageResult(response, groupMapper);
970
+ },
971
+ async listConversations (uniqueId, params) {
972
+ var _rawResponse_meta, _rawResponse_meta1, _rawResponse_meta2, _rawResponse_meta3;
973
+ const queryParams = {};
974
+ if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
975
+ if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
976
+ const response = await transport.get(`/users/${uniqueId}/conversations`, {
977
+ params: queryParams
978
+ });
979
+ // Return conversations with their messages
980
+ const rawResponse = response;
981
+ const data = rawResponse.data || [];
982
+ return {
983
+ data: data.map((conv)=>({
984
+ id: conv.id || conv.unique_id,
985
+ context: conv.context || conv.unique_id,
986
+ messages: [],
987
+ files: [],
988
+ meta: conv.meta || {}
989
+ })),
990
+ meta: {
991
+ totalCount: ((_rawResponse_meta = rawResponse.meta) == null ? void 0 : _rawResponse_meta.total_count) || data.length,
992
+ page: ((_rawResponse_meta1 = rawResponse.meta) == null ? void 0 : _rawResponse_meta1.page) || 1,
993
+ perPage: ((_rawResponse_meta2 = rawResponse.meta) == null ? void 0 : _rawResponse_meta2.per_page) || data.length,
994
+ totalPages: ((_rawResponse_meta3 = rawResponse.meta) == null ? void 0 : _rawResponse_meta3.total_pages) || 1
995
+ }
996
+ };
997
+ },
998
+ async listGroupConversations (uniqueId, params) {
999
+ var _rawResponse_meta, _rawResponse_meta1, _rawResponse_meta2, _rawResponse_meta3;
1000
+ const queryParams = {};
1001
+ if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
1002
+ if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
1003
+ const response = await transport.get(`/users/${uniqueId}/mygroups/conversations`, {
1004
+ params: queryParams
1005
+ });
1006
+ const rawResponse = response;
1007
+ const data = rawResponse.data || [];
1008
+ return {
1009
+ data: data.map((conv)=>({
1010
+ id: conv.id || conv.unique_id,
1011
+ context: conv.context || conv.unique_id,
1012
+ messages: [],
1013
+ files: [],
1014
+ meta: conv.meta || {}
1015
+ })),
1016
+ meta: {
1017
+ totalCount: ((_rawResponse_meta = rawResponse.meta) == null ? void 0 : _rawResponse_meta.total_count) || data.length,
1018
+ page: ((_rawResponse_meta1 = rawResponse.meta) == null ? void 0 : _rawResponse_meta1.page) || 1,
1019
+ perPage: ((_rawResponse_meta2 = rawResponse.meta) == null ? void 0 : _rawResponse_meta2.per_page) || data.length,
1020
+ totalPages: ((_rawResponse_meta3 = rawResponse.meta) == null ? void 0 : _rawResponse_meta3.total_pages) || 1
1021
+ }
1022
+ };
1023
+ },
1024
+ async listContextGroups (uniqueId, contextUniqueId) {
1025
+ const response = await transport.get(`/users/${uniqueId}/context/${contextUniqueId}/groups`);
1026
+ return decodePageResult(response, groupMapper);
1027
+ }
1028
+ };
1029
+ }
1030
+
673
1031
  function createConversationsBlock(transport, config) {
674
1032
  return {
675
1033
  messages: createMessagesService(transport),
676
1034
  draftMessages: createDraftMessagesService(transport),
677
1035
  groups: createGroupsService(transport),
678
1036
  notifications: createNotificationsService(transport),
679
- conversations: createConversationsService(transport)
1037
+ conversations: createConversationsService(transport),
1038
+ websocketTokens: createWebSocketTokensService(transport),
1039
+ contexts: createContextsService(transport),
1040
+ notificationSettings: createNotificationSettingsService(transport),
1041
+ availabilities: createAvailabilitiesService(transport),
1042
+ messageFiles: createMessageFilesService(transport),
1043
+ sources: createSourcesService(transport),
1044
+ users: createUsersService(transport)
680
1045
  };
681
1046
  }
682
1047
  const conversationsBlockMetadata = {
683
1048
  name: 'conversations',
684
1049
  version: '0.1.0',
685
- description: 'Messaging, conversations, groups, and notifications management',
1050
+ description: 'Messaging, conversations, groups, notifications, and real-time communication management',
686
1051
  resourceTypes: [
687
1052
  'Message',
688
1053
  'DraftMessage',
689
1054
  'Group',
690
1055
  'Notification',
691
- 'Conversation'
1056
+ 'Conversation',
1057
+ 'Context',
1058
+ 'MessageFile',
1059
+ 'Source',
1060
+ 'User'
692
1061
  ]
693
1062
  };
694
1063
 
695
- export { conversationsBlockMetadata, createConversationsBlock, createConversationsService, createDraftMessagesService, createGroupsService, createMessagesService, createNotificationsService, draftMessageMapper, groupMapper, messageMapper, notificationMapper };
1064
+ export { contextMapper, conversationsBlockMetadata, conversationsUserMapper, createAvailabilitiesService, createContextsService, createConversationsBlock, createConversationsService, createDraftMessagesService, createGroupsService, createMessageFilesService, createMessagesService, createNotificationSettingsService, createNotificationsService, createSourcesService, createUsersService, createWebSocketTokensService, draftMessageMapper, groupMapper, messageFileMapper, messageMapper, notificationMapper, sourceMapper };