@twilio/conversations 3.0.0-canary.5 → 3.0.0-canary2.100

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 (53) hide show
  1. package/README.md +22 -18
  2. package/builds/browser.js +1360 -2410
  3. package/builds/browser.js.map +1 -1
  4. package/builds/lib.d.ts +74 -69
  5. package/builds/lib.js +1360 -2410
  6. package/builds/lib.js.map +1 -1
  7. package/builds/twilio-conversations.js +25229 -25615
  8. package/builds/twilio-conversations.min.js +1 -16
  9. package/dist/aggregated-delivery-receipt.js +1 -1
  10. package/dist/aggregated-delivery-receipt.js.map +1 -1
  11. package/dist/client.js +99 -70
  12. package/dist/client.js.map +1 -1
  13. package/dist/command-executor.js +30 -12
  14. package/dist/command-executor.js.map +1 -1
  15. package/dist/configuration.js.map +1 -1
  16. package/dist/conversation.js +92 -23
  17. package/dist/conversation.js.map +1 -1
  18. package/dist/data/conversations.js +21 -5
  19. package/dist/data/conversations.js.map +1 -1
  20. package/dist/data/messages.js +13 -19
  21. package/dist/data/messages.js.map +1 -1
  22. package/dist/data/participants.js +6 -4
  23. package/dist/data/participants.js.map +1 -1
  24. package/dist/data/users.js +4 -2
  25. package/dist/data/users.js.map +1 -1
  26. package/dist/detailed-delivery-receipt.js.map +1 -1
  27. package/dist/index.js +6 -4
  28. package/dist/index.js.map +1 -1
  29. package/dist/interfaces/attributes.js.map +1 -1
  30. package/dist/interfaces/notification-types.js.map +1 -1
  31. package/dist/logger.js +2 -4
  32. package/dist/logger.js.map +1 -1
  33. package/dist/media.js.map +1 -1
  34. package/dist/message-builder.js.map +1 -1
  35. package/dist/message.js +24 -21
  36. package/dist/message.js.map +1 -1
  37. package/dist/node_modules/tslib/tslib.es6.js +1 -1
  38. package/dist/node_modules/tslib/tslib.es6.js.map +1 -1
  39. package/dist/packages/conversations/package.json.js +1 -1
  40. package/dist/participant.js +2 -2
  41. package/dist/participant.js.map +1 -1
  42. package/dist/push-notification.js.map +1 -1
  43. package/dist/rest-paginator.js.map +1 -1
  44. package/dist/services/network.js +38 -15
  45. package/dist/services/network.js.map +1 -1
  46. package/dist/services/typing-indicator.js +7 -5
  47. package/dist/services/typing-indicator.js.map +1 -1
  48. package/dist/unsent-message.js.map +1 -1
  49. package/dist/user.js +2 -2
  50. package/dist/user.js.map +1 -1
  51. package/dist/util/deferred.js.map +1 -1
  52. package/dist/util/index.js.map +1 -1
  53. package/package.json +27 -23
package/builds/lib.d.ts CHANGED
@@ -1,8 +1,9 @@
1
+ /// <reference types="node" />
1
2
  import { SyncClient, SyncDocument, SyncList } from "twilio-sync";
2
3
  import { LogLevelDesc } from "loglevel";
3
- import { Transport, TwilsockClient, InitRegistration, ConnectionError, TransportResult } from "twilsock";
4
- import { ConnectionState as TwilsockConnectionState } from "twilsock";
4
+ import { TwilsockClient, InitRegistration, HttpResponse } from "twilsock";
5
5
  import { ReplayEventEmitter } from "@twilio/replay-event-emitter";
6
+ import { JSONValue } from "@twilio/shared";
6
7
  import { ChannelType, Notifications } from "@twilio/notifications";
7
8
  import { Notifications as NotificationClient } from "@twilio/notifications";
8
9
  import { CancellablePromise, McsClient, MediaCategory, McsMedia } from "@twilio/mcs-client";
@@ -112,7 +113,7 @@ declare class Configuration {
112
113
  constructor(options: ClientOptions, configurationResponse: ConfigurationResponse, logger: Logger);
113
114
  }
114
115
  interface CommandExecutorServices {
115
- transport: Transport;
116
+ transport: TwilsockClient;
116
117
  }
117
118
  declare class CommandExecutor {
118
119
  private _serviceUrl;
@@ -124,20 +125,6 @@ declare class CommandExecutor {
124
125
  fetchResource<REQ = void, RESP = void>(url: string, requestBody?: REQ): Promise<RESP>;
125
126
  mutateResource<REQ = void, RESP = void>(method: "post" | "delete", url: string, requestBody?: REQ): Promise<RESP>;
126
127
  }
127
- /**
128
- * Represents a JSON value.
129
- */
130
- type JSONValue = null | string | number | boolean | JSONObject | JSONArray;
131
- /**
132
- * Represents a JSON object.
133
- */
134
- type JSONObject = {
135
- [x: string]: JSONValue;
136
- };
137
- /**
138
- * Represents a JSON array.
139
- */
140
- type JSONArray = JSONValue[];
141
128
  type UserEvents = {
142
129
  updated: (data: {
143
130
  user: User;
@@ -269,7 +256,7 @@ declare class Network {
269
256
  private cleanupCache;
270
257
  pokeTimer(): void;
271
258
  private executeWithRetry;
272
- get<T>(url: string): Promise<TransportResult<T>>;
259
+ get<T>(url: string): Promise<HttpResponse>;
273
260
  }
274
261
  type UsersEvents = {
275
262
  userUpdated: (data: {
@@ -567,7 +554,7 @@ interface AggregatedDeliveryDescriptor {
567
554
  * Contains aggregated information about delivery statuses of a message across all participants
568
555
  * of a conversation.
569
556
  *
570
- * At any moment during the message delivery to a participant, the message can have zero or more of following
557
+ * At any moment during the message delivery to a participant, the message can have zero or more of the following
571
558
  * delivery statuses:
572
559
  * * Message is considered as **sent** to a participant if the nearest upstream carrier accepted the message.
573
560
  * * Message is considered as **delivered** to a participant if Twilio has received confirmation of message
@@ -731,8 +718,8 @@ interface MessageData {
731
718
  attributes?: JSONValue;
732
719
  dateUpdated: string;
733
720
  timestamp?: string;
734
- medias?: Media[];
735
- media?: Media;
721
+ medias: MediaState[] | null;
722
+ media: MediaState | null;
736
723
  memberSid?: string;
737
724
  delivery?: AggregatedDeliveryDescriptor;
738
725
  }
@@ -782,14 +769,15 @@ declare class Message extends ReplayEventEmitter<MessageEvents> {
782
769
  */
783
770
  get dateUpdated(): Date | null;
784
771
  /**
785
- * Index of the message in the conversation's messages list.
786
- * By design of the Conversations system, the message indices may have arbitrary gaps between them,
772
+ * Index of this message in the conversation's list of messages.
773
+ *
774
+ * By design, the message indices may have arbitrary gaps between them,
787
775
  * that does not necessarily mean they were deleted or otherwise modified - just that
788
776
  * messages may have some non-contiguous indices even if they are being sent immediately one after another.
789
777
  *
790
778
  * Trying to use indices for some calculations is going to be unreliable.
791
779
  *
792
- * To calculate the number of unread messages it is better to use the read horizon API.
780
+ * To calculate the number of unread messages, it is better to use the Read Horizon API.
793
781
  * See {@link Conversation.getUnreadMessagesCount} for details.
794
782
  */
795
783
  get index(): number;
@@ -872,7 +860,7 @@ declare class Message extends ReplayEventEmitter<MessageEvents> {
872
860
  * Get content URLs for all media attachments in the given set using a single operation.
873
861
  * @param contentSet Set of media attachments to query content URLs.
874
862
  */
875
- getTemporaryContentUrlsForMedia(contentSet: Media[] | null): CancellablePromise<Map<string, string>>;
863
+ getTemporaryContentUrlsForMedia(contentSet: Media[]): CancellablePromise<Map<string, string>>;
876
864
  /**
877
865
  * Get content URLs for all media attachments in the given set of media sids using a single operation.
878
866
  * @param mediaSids Set of media sids to query for the content URL.
@@ -1024,6 +1012,7 @@ interface MessageResponse {
1024
1012
  media: {
1025
1013
  sid: string;
1026
1014
  size: string;
1015
+ category: string;
1027
1016
  content_type: string;
1028
1017
  filename: string;
1029
1018
  }[] | null;
@@ -1058,9 +1047,10 @@ declare class Messages extends ReplayEventEmitter<MessagesEvents> {
1058
1047
  constructor(conversation: Conversation, configuration: Configuration, services: MessagesServices);
1059
1048
  /**
1060
1049
  * Subscribe to the Messages Event Stream
1061
- * @param name - The name of Sync object for the Messages resource.
1050
+ * @param arg - Name of the Sync object, or the SyncList itself, that
1051
+ * represents the Messages resource.
1062
1052
  */
1063
- subscribe(name: string): Promise<SyncList>;
1053
+ subscribe(arg: string | SyncList): Promise<SyncList>;
1064
1054
  unsubscribe(): Promise<void>;
1065
1055
  /**
1066
1056
  * Send a message to the conversation. The message could include text and multiple media attachments.
@@ -1092,7 +1082,7 @@ declare class Messages extends ReplayEventEmitter<MessagesEvents> {
1092
1082
  */
1093
1083
  getMessages(pageSize: number | undefined, anchor: number | "end" | undefined, direction?: "forward" | "backwards"): Promise<SyncPaginator<Message>>;
1094
1084
  private _wrapPaginator;
1095
- private _upsertMessage;
1085
+ _upsertMessage(index: number, value: MessageData): Message;
1096
1086
  /**
1097
1087
  * Returns last messages from conversation
1098
1088
  * @param {Number} [pageSize] Number of messages to return in single chunk. By default it's 30.
@@ -1110,7 +1100,10 @@ declare class UnsentMessage {
1110
1100
  private messagesEntity;
1111
1101
  text?: string;
1112
1102
  attributes: JSONValue;
1113
- mediaContent: [MediaCategory, FormData | SendMediaOptions][];
1103
+ mediaContent: [
1104
+ MediaCategory,
1105
+ FormData | SendMediaOptions
1106
+ ][];
1114
1107
  emailOptions: SendEmailOptions;
1115
1108
  /**
1116
1109
  * @internal
@@ -1486,10 +1479,18 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1486
1479
  * Messages entity.
1487
1480
  */
1488
1481
  private readonly _messagesEntity;
1482
+ /**
1483
+ * Sync list containing messages.
1484
+ */
1485
+ private _messagesList?;
1489
1486
  /**
1490
1487
  * Participants entity.
1491
1488
  */
1492
1489
  private readonly _participantsEntity;
1490
+ /**
1491
+ * Sync map containing participants.
1492
+ */
1493
+ private _participantsMap?;
1493
1494
  /**
1494
1495
  * Source of the most recent update.
1495
1496
  */
@@ -1660,7 +1661,7 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1660
1661
  */
1661
1662
  getMessagesCount(): Promise<number>;
1662
1663
  /**
1663
- * Get unread messages count for the user if they are a participant of this
1664
+ * Get count of unread messages for the user if they are a participant of this
1664
1665
  * conversation. Rejects if the user is not a participant of the conversation.
1665
1666
  *
1666
1667
  * Use this method to obtain the number of unread messages together with
@@ -1668,12 +1669,19 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1668
1669
  * message indices which may have gaps. See {@link Message.index} for details.
1669
1670
  *
1670
1671
  * This method is semi-realtime. This means that this data will be eventually
1671
- * correct, but will also be possibly incorrect for a few seconds. The
1672
+ * correct, but it will also be possibly incorrect for a few seconds. The
1672
1673
  * Conversations system does not provide real time events for counter values
1673
1674
  * changes.
1674
1675
  *
1675
1676
  * This is useful for any UI badges, but it is not recommended to build any
1676
1677
  * core application logic based on these counters being accurate in real time.
1678
+ *
1679
+ * If the read horizon is not set, this function will return null. This could mean
1680
+ * that all messages in the conversation are unread, or that the read horizon system
1681
+ * is not being used. How to interpret this `null` value is up to the customer application.
1682
+ *
1683
+ * @return Number of unread messages based on the current read horizon set for
1684
+ * the user or `null` if the read horizon is not set.
1677
1685
  */
1678
1686
  getUnreadMessagesCount(): Promise<number | null>;
1679
1687
  /**
@@ -1689,8 +1697,6 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1689
1697
  * argument, it will assume that the string is an identity or SID.
1690
1698
  * @param participant Identity, SID or the participant object to remove.
1691
1699
  */
1692
- /* eslint-disable @typescript-eslint/ban-ts-comment */
1693
- // @ts-ignore TODO: fix validateTypesAsync typing
1694
1700
  removeParticipant(participant: string | Participant): Promise<void>;
1695
1701
  /**
1696
1702
  * Send a message to the conversation.
@@ -1701,7 +1707,7 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1701
1707
  * @param emailOptions Email options for the message.
1702
1708
  * @return Index of the new message.
1703
1709
  */
1704
- sendMessage(message: null | string | FormData | SendMediaOptions, messageAttributes?: JSONValue, emailOptions?: SendEmailOptions): Promise<number>;
1710
+ sendMessage(message: null | string | FormData | SendMediaOptions, messageAttributes?: JSONValue, emailOptions?: SendEmailOptions): Promise<Message>;
1705
1711
  /**
1706
1712
  * New interface to prepare for sending a message.
1707
1713
  * Use this instead of {@link Message.sendMessage}.
@@ -1716,7 +1722,7 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1716
1722
  setAllMessagesRead(): Promise<number>;
1717
1723
  /**
1718
1724
  * Set all messages in the conversation unread.
1719
- * @return Resulting unread messages count in the conversation.
1725
+ * @returns New count of unread messages after this update.
1720
1726
  */
1721
1727
  setAllMessagesUnread(): Promise<number>;
1722
1728
  /**
@@ -1745,7 +1751,7 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1745
1751
  * Set the last read message index to the current read horizon.
1746
1752
  * @param index Message index to set as last read. If null is provided, then
1747
1753
  * the behavior is identical to {@link Conversation.setAllMessagesUnread}.
1748
- * @returns Resulting unread messages count in the conversation.
1754
+ * @returns New count of unread messages after this update.
1749
1755
  */
1750
1756
  updateLastReadMessageIndex(index: number | null): Promise<number>;
1751
1757
  /**
@@ -1761,6 +1767,16 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1761
1767
  * @internal
1762
1768
  */
1763
1769
  _subscribe(): Promise<SyncDocument>;
1770
+ /**
1771
+ * Fetch participants and messages of the conversation. This method needs to
1772
+ * be called during conversation initialization to catch broken conversations
1773
+ * (broken conversations are conversations that have essential Sync entities
1774
+ * missing, i.e. the conversation document, the messages list or the
1775
+ * participant map). In case of this conversation being broken, the method
1776
+ * will throw an exception that will be caught and handled gracefully.
1777
+ * @internal
1778
+ */
1779
+ _fetchStreams(): Promise<void>;
1764
1780
  /**
1765
1781
  * Load the attributes of this conversation and instantiate its participants
1766
1782
  * and messages. This or _subscribe will need to be called before any events
@@ -1833,7 +1849,7 @@ interface PushNotificationData {
1833
1849
  */
1834
1850
  media?: Media;
1835
1851
  /**
1836
- * Amount of the attached media of the message.
1852
+ * Count of the attached media of the message.
1837
1853
  */
1838
1854
  mediaCount?: number;
1839
1855
  }
@@ -1909,11 +1925,11 @@ type ClientEvents = {
1909
1925
  user: User;
1910
1926
  updateReasons: UserUpdateReason[];
1911
1927
  }) => void;
1912
- stateChanged: ({ state, error }: {
1913
- state: State;
1928
+ initialized: () => void;
1929
+ initFailed: ({ error }: {
1914
1930
  error?: ConnectionError;
1915
1931
  }) => void;
1916
- connectionStateChanged: (state: TwilsockConnectionState) => void;
1932
+ connectionStateChanged: (state: ConnectionState) => void;
1917
1933
  connectionError: (data: ConnectionError) => void;
1918
1934
  };
1919
1935
  /**
@@ -1926,7 +1942,7 @@ type ClientEvents = {
1926
1942
  * * `'denied'` - client connection is denied because of invalid JWT access
1927
1943
  * token. User must refresh token in order to proceed
1928
1944
  */
1929
- type ConnectionState = TwilsockConnectionState;
1945
+ type ConnectionState = "disconnected" | "connecting" | "connected";
1930
1946
  /**
1931
1947
  * State of the client. Possible values are as follows:
1932
1948
  * * `'failed'` - the client failed to initialize
@@ -1954,7 +1970,7 @@ interface ClientOptions {
1954
1970
  region?: string;
1955
1971
  productId?: string;
1956
1972
  twilsockClient?: TwilsockClient;
1957
- transport?: Transport;
1973
+ transport?: TwilsockClient;
1958
1974
  notificationsClient?: NotificationClient;
1959
1975
  syncClient?: SyncClient;
1960
1976
  typingIndicatorTimeoutOverride?: number;
@@ -1974,6 +1990,10 @@ interface ClientOptions {
1974
1990
  typingUri?: string;
1975
1991
  apiUri?: string;
1976
1992
  }
1993
+ type ConnectionError = {
1994
+ terminal: boolean;
1995
+ message: string;
1996
+ };
1977
1997
  /**
1978
1998
  * Options for {@link Client.createConversation}.
1979
1999
  */
@@ -2166,16 +2186,20 @@ declare class Client extends ReplayEventEmitter<ClientEvents> {
2166
2186
  */
2167
2187
  static readonly userUpdated = "userUpdated";
2168
2188
  /**
2169
- * Fired when the state of the client has been changed.
2189
+ * Fired when the client has completed initialization successfully.
2190
+ * @event
2191
+ */
2192
+ static readonly initialized = "initialized";
2193
+ /**
2194
+ * Fired when the client initialization failed.
2170
2195
  *
2171
2196
  * Parameters:
2172
2197
  * 1. object `data` - info object provided with the event. It has the
2173
- * following properties:
2174
- * * {@link State} `state` - the new client state
2198
+ * following property:
2175
2199
  * * Error? `error` - the initialization error if present
2176
2200
  * @event
2177
2201
  */
2178
- static readonly stateChanged = "stateChanged";
2202
+ static readonly initFailed = "initFailed";
2179
2203
  /**
2180
2204
  * Fired when the connection state of the client has been changed.
2181
2205
  *
@@ -2220,7 +2244,7 @@ declare class Client extends ReplayEventEmitter<ClientEvents> {
2220
2244
  /**
2221
2245
  * Client connection state.
2222
2246
  */
2223
- connectionState: ConnectionState;
2247
+ connectionState: ConnectionState | "unknown";
2224
2248
  /**
2225
2249
  * Promise that resolves on successful initialization.
2226
2250
  */
@@ -2284,26 +2308,6 @@ declare class Client extends ReplayEventEmitter<ClientEvents> {
2284
2308
  * initialization was completed.
2285
2309
  */
2286
2310
  get reachabilityEnabled(): boolean;
2287
- /**
2288
- * @deprecated Call constructor directly.
2289
- *
2290
- * Factory method to create a Conversations client instance.
2291
- *
2292
- * The factory method will automatically trigger connection.
2293
- * Do not use it if you need finer-grained control.
2294
- *
2295
- * Since this method returns an already-initialized client, some of the events
2296
- * will be lost because they happen *before* the initialization. It is
2297
- * recommended that `client.onWithReplay` is used as opposed to `client.on`
2298
- * for subscribing to client events. The `client.onWithReplay` will re-emit
2299
- * the most recent value for a given event if it emitted before the
2300
- * subscription.
2301
- *
2302
- * @param token Access token.
2303
- * @param options Options to customize the client.
2304
- * @returns Returns a fully initialized client.
2305
- */
2306
- static create(token: string, options?: ClientOptions | null): Promise<Client>;
2307
2311
  /**
2308
2312
  * Static method for push notification payload parsing. Returns parsed push as
2309
2313
  * a {@link PushNotification} object.
@@ -2339,7 +2343,7 @@ declare class Client extends ReplayEventEmitter<ClientEvents> {
2339
2343
  * @param conversationSid Conversation sid
2340
2344
  * @internal
2341
2345
  */
2342
- peekConversationBySid(conversationSid: string): Promise<Conversation>;
2346
+ private peekConversationBySid;
2343
2347
  /**
2344
2348
  * Get a known conversation by its unique identifier name.
2345
2349
  * @param uniqueName The unique identifier name of the conversation.
@@ -2439,4 +2443,5 @@ declare class NotificationTypes {
2439
2443
  static readonly REMOVED_FROM_CONVERSATION = "twilio.conversations.removed_from_conversation";
2440
2444
  static readonly CONSUMPTION_UPDATE = "twilio.channel.consumption_update";
2441
2445
  }
2442
- export { Conversation, ConversationBindings, ConversationEmailBinding, ConversationUpdateReason, ConversationStatus, NotificationLevel, ConversationState, ConversationUpdatedEventArgs, SendMediaOptions, SendEmailOptions, LastMessage, Participant, ParticipantUpdateReason, ParticipantType, ParticipantUpdatedEventArgs, ParticipantBindings, ParticipantEmailBinding, ParticipantEmailLevel, Message, MessageUpdateReason, MessageType, MessageUpdatedEventArgs, Media, MediaCategory$0 as MediaCategory, AggregatedDeliveryReceipt, DeliveryAmount, DetailedDeliveryReceipt, DeliveryStatus, RestPaginator, MessageBuilder, UnsentMessage, Paginator, ParticipantBindingOptions, User, UserUpdateReason, UserUpdatedEventArgs, PushNotification, PushNotificationType, PushNotificationDescriptor, PushNotificationData, NotificationTypes, Client, State, ConnectionState, NotificationsChannelType, ClientOptions, CreateConversationOptions, ConversationLimits, JSONValue, JSONObject, JSONArray };
2446
+ export { Conversation, ConversationBindings, ConversationEmailBinding, ConversationUpdateReason, ConversationStatus, NotificationLevel, ConversationState, ConversationUpdatedEventArgs, SendMediaOptions, SendEmailOptions, LastMessage, Participant, ParticipantUpdateReason, ParticipantType, ParticipantUpdatedEventArgs, ParticipantBindings, ParticipantEmailBinding, ParticipantEmailLevel, Message, MessageUpdateReason, MessageType, MessageUpdatedEventArgs, Media, MediaCategory$0 as MediaCategory, AggregatedDeliveryReceipt, DeliveryAmount, DetailedDeliveryReceipt, DeliveryStatus, RestPaginator, MessageBuilder, UnsentMessage, Paginator, ParticipantBindingOptions, User, UserUpdateReason, UserUpdatedEventArgs, PushNotification, PushNotificationType, PushNotificationDescriptor, PushNotificationData, NotificationTypes, Client, State, ConnectionState, NotificationsChannelType, ClientOptions, CreateConversationOptions, ConversationLimits, CancellablePromise };
2447
+ export { JSONValue, JSONObject, JSONArray } from "@twilio/shared";