@twilio/conversations 3.0.0-canary.13 → 3.0.0-canary.2

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 (77) hide show
  1. package/README.md +22 -18
  2. package/builds/browser.js +729 -1639
  3. package/builds/browser.js.map +1 -1
  4. package/builds/lib.d.ts +72 -64
  5. package/builds/lib.js +729 -1639
  6. package/builds/lib.js.map +1 -1
  7. package/builds/twilio-conversations.js +17697 -17435
  8. package/builds/twilio-conversations.min.js +1 -1
  9. package/dist/aggregated-delivery-receipt.js +1 -1
  10. package/dist/aggregated-delivery-receipt.js.map +1 -1
  11. package/dist/client.js +69 -65
  12. package/dist/client.js.map +1 -1
  13. package/dist/command-executor.js +38 -13
  14. package/dist/command-executor.js.map +1 -1
  15. package/dist/conversation.js +81 -13
  16. package/dist/conversation.js.map +1 -1
  17. package/dist/data/conversations.js +16 -3
  18. package/dist/data/conversations.js.map +1 -1
  19. package/dist/data/messages.js +13 -19
  20. package/dist/data/messages.js.map +1 -1
  21. package/dist/data/participants.js +5 -3
  22. package/dist/data/participants.js.map +1 -1
  23. package/dist/data/users.js +2 -2
  24. package/dist/data/users.js.map +1 -1
  25. package/dist/message-builder.js.map +1 -1
  26. package/dist/message.js +7 -9
  27. package/dist/message.js.map +1 -1
  28. package/dist/node_modules/tslib/tslib.es6.js.map +1 -1
  29. package/dist/packages/conversations/package.json.js +1 -1
  30. package/dist/participant.js +33 -33
  31. package/dist/participant.js.map +1 -1
  32. package/dist/rest-paginator.js +11 -11
  33. package/dist/rest-paginator.js.map +1 -1
  34. package/dist/services/network.js +103 -11
  35. package/dist/services/network.js.map +1 -1
  36. package/dist/services/typing-indicator.js +13 -5
  37. package/dist/services/typing-indicator.js.map +1 -1
  38. package/dist/unsent-message.js.map +1 -1
  39. package/dist/user.js +1 -1
  40. package/dist/user.js.map +1 -1
  41. package/dist/util/index.js.map +1 -1
  42. package/package.json +16 -14
  43. package/docs/assets/css/main.css +0 -2660
  44. package/docs/assets/images/icons.png +0 -0
  45. package/docs/assets/images/icons@2x.png +0 -0
  46. package/docs/assets/images/widgets.png +0 -0
  47. package/docs/assets/images/widgets@2x.png +0 -0
  48. package/docs/assets/js/main.js +0 -248
  49. package/docs/assets/js/search.js +0 -1
  50. package/docs/classes/AggregatedDeliveryReceipt.html +0 -3184
  51. package/docs/classes/Client.html +0 -4239
  52. package/docs/classes/Conversation.html +0 -4354
  53. package/docs/classes/DetailedDeliveryReceipt.html +0 -3163
  54. package/docs/classes/Media.html +0 -3167
  55. package/docs/classes/Message.html +0 -3732
  56. package/docs/classes/MessageBuilder.html +0 -3277
  57. package/docs/classes/Participant.html +0 -3444
  58. package/docs/classes/PushNotification.html +0 -3130
  59. package/docs/classes/RestPaginator.html +0 -3160
  60. package/docs/classes/UnsentMessage.html +0 -3042
  61. package/docs/classes/User.html +0 -3349
  62. package/docs/index.html +0 -3505
  63. package/docs/interfaces/ClientOptions.html +0 -3034
  64. package/docs/interfaces/ConversationBindings.html +0 -3001
  65. package/docs/interfaces/ConversationEmailBinding.html +0 -3001
  66. package/docs/interfaces/ConversationLimits.html +0 -3098
  67. package/docs/interfaces/ConversationState.html +0 -3050
  68. package/docs/interfaces/ConversationUpdatedEventArgs.html +0 -3001
  69. package/docs/interfaces/CreateConversationOptions.html +0 -3066
  70. package/docs/interfaces/LastMessage.html +0 -3050
  71. package/docs/interfaces/Paginator.html +0 -3141
  72. package/docs/interfaces/ParticipantBindings.html +0 -3001
  73. package/docs/interfaces/ParticipantEmailBinding.html +0 -3001
  74. package/docs/interfaces/PushNotificationData.html +0 -3114
  75. package/docs/interfaces/SendEmailOptions.html +0 -3034
  76. package/docs/interfaces/SendMediaOptions.html +0 -3068
  77. package/docs/modules.html +0 -3506
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 } 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;
@@ -264,12 +251,16 @@ declare class Network {
264
251
  private cacheLifetime;
265
252
  private readonly cache;
266
253
  private timer;
254
+ private pendingRequests;
255
+ private isShutdownInitiated;
267
256
  constructor(configuration: any, services: any);
268
257
  private isExpired;
269
258
  private cleanupCache;
270
259
  pokeTimer(): void;
260
+ private responsePostProcess;
271
261
  private executeWithRetry;
272
- get<T>(url: string): Promise<TransportResult<T>>;
262
+ get(url: string): Promise<any>;
263
+ disconnect(): Promise<void>;
273
264
  }
274
265
  type UsersEvents = {
275
266
  userUpdated: (data: {
@@ -567,7 +558,7 @@ interface AggregatedDeliveryDescriptor {
567
558
  * Contains aggregated information about delivery statuses of a message across all participants
568
559
  * of a conversation.
569
560
  *
570
- * At any moment during the message delivery to a participant, the message can have zero or more of following
561
+ * At any moment during the message delivery to a participant, the message can have zero or more of the following
571
562
  * delivery statuses:
572
563
  * * Message is considered as **sent** to a participant if the nearest upstream carrier accepted the message.
573
564
  * * Message is considered as **delivered** to a participant if Twilio has received confirmation of message
@@ -731,8 +722,8 @@ interface MessageData {
731
722
  attributes?: JSONValue;
732
723
  dateUpdated: string;
733
724
  timestamp?: string;
734
- medias?: Media[];
735
- media?: Media;
725
+ medias: MediaState[] | null;
726
+ media: MediaState | null;
736
727
  memberSid?: string;
737
728
  delivery?: AggregatedDeliveryDescriptor;
738
729
  }
@@ -782,14 +773,15 @@ declare class Message extends ReplayEventEmitter<MessageEvents> {
782
773
  */
783
774
  get dateUpdated(): Date | null;
784
775
  /**
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,
776
+ * Index of this message in the conversation's list of messages.
777
+ *
778
+ * By design, the message indices may have arbitrary gaps between them,
787
779
  * that does not necessarily mean they were deleted or otherwise modified - just that
788
780
  * messages may have some non-contiguous indices even if they are being sent immediately one after another.
789
781
  *
790
782
  * Trying to use indices for some calculations is going to be unreliable.
791
783
  *
792
- * To calculate the number of unread messages it is better to use the read horizon API.
784
+ * To calculate the number of unread messages, it is better to use the Read Horizon API.
793
785
  * See {@link Conversation.getUnreadMessagesCount} for details.
794
786
  */
795
787
  get index(): number;
@@ -1024,6 +1016,7 @@ interface MessageResponse {
1024
1016
  media: {
1025
1017
  sid: string;
1026
1018
  size: string;
1019
+ category: string;
1027
1020
  content_type: string;
1028
1021
  filename: string;
1029
1022
  }[] | null;
@@ -1058,9 +1051,10 @@ declare class Messages extends ReplayEventEmitter<MessagesEvents> {
1058
1051
  constructor(conversation: Conversation, configuration: Configuration, services: MessagesServices);
1059
1052
  /**
1060
1053
  * Subscribe to the Messages Event Stream
1061
- * @param name - The name of Sync object for the Messages resource.
1054
+ * @param arg - Name of the Sync object, or the SyncList itself, that
1055
+ * represents the Messages resource.
1062
1056
  */
1063
- subscribe(name: string): Promise<SyncList>;
1057
+ subscribe(arg: string | SyncList): Promise<SyncList>;
1064
1058
  unsubscribe(): Promise<void>;
1065
1059
  /**
1066
1060
  * Send a message to the conversation. The message could include text and multiple media attachments.
@@ -1092,7 +1086,7 @@ declare class Messages extends ReplayEventEmitter<MessagesEvents> {
1092
1086
  */
1093
1087
  getMessages(pageSize: number | undefined, anchor: number | "end" | undefined, direction?: "forward" | "backwards"): Promise<SyncPaginator<Message>>;
1094
1088
  private _wrapPaginator;
1095
- private _upsertMessage;
1089
+ _upsertMessage(index: number, value: MessageData): Message;
1096
1090
  /**
1097
1091
  * Returns last messages from conversation
1098
1092
  * @param {Number} [pageSize] Number of messages to return in single chunk. By default it's 30.
@@ -1489,10 +1483,18 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1489
1483
  * Messages entity.
1490
1484
  */
1491
1485
  private readonly _messagesEntity;
1486
+ /**
1487
+ * Sync list containing messages.
1488
+ */
1489
+ private _messagesList?;
1492
1490
  /**
1493
1491
  * Participants entity.
1494
1492
  */
1495
1493
  private readonly _participantsEntity;
1494
+ /**
1495
+ * Sync map containing participants.
1496
+ */
1497
+ private _participantsMap?;
1496
1498
  /**
1497
1499
  * Source of the most recent update.
1498
1500
  */
@@ -1663,7 +1665,7 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1663
1665
  */
1664
1666
  getMessagesCount(): Promise<number>;
1665
1667
  /**
1666
- * Get unread messages count for the user if they are a participant of this
1668
+ * Get count of unread messages for the user if they are a participant of this
1667
1669
  * conversation. Rejects if the user is not a participant of the conversation.
1668
1670
  *
1669
1671
  * Use this method to obtain the number of unread messages together with
@@ -1671,12 +1673,19 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1671
1673
  * message indices which may have gaps. See {@link Message.index} for details.
1672
1674
  *
1673
1675
  * This method is semi-realtime. This means that this data will be eventually
1674
- * correct, but will also be possibly incorrect for a few seconds. The
1676
+ * correct, but it will also be possibly incorrect for a few seconds. The
1675
1677
  * Conversations system does not provide real time events for counter values
1676
1678
  * changes.
1677
1679
  *
1678
1680
  * This is useful for any UI badges, but it is not recommended to build any
1679
1681
  * core application logic based on these counters being accurate in real time.
1682
+ *
1683
+ * If the read horizon is not set, this function will return null. This could mean
1684
+ * that all messages in the conversation are unread, or that the read horizon system
1685
+ * is not being used. How to interpret this `null` value is up to the customer application.
1686
+ *
1687
+ * @return Number of unread messages based on the current read horizon set for
1688
+ * the user or `null` if the read horizon is not set.
1680
1689
  */
1681
1690
  getUnreadMessagesCount(): Promise<number | null>;
1682
1691
  /**
@@ -1702,7 +1711,7 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1702
1711
  * @param emailOptions Email options for the message.
1703
1712
  * @return Index of the new message.
1704
1713
  */
1705
- sendMessage(message: null | string | FormData | SendMediaOptions, messageAttributes?: JSONValue, emailOptions?: SendEmailOptions): Promise<number>;
1714
+ sendMessage(message: null | string | FormData | SendMediaOptions, messageAttributes?: JSONValue, emailOptions?: SendEmailOptions): Promise<Message>;
1706
1715
  /**
1707
1716
  * New interface to prepare for sending a message.
1708
1717
  * Use this instead of {@link Message.sendMessage}.
@@ -1717,7 +1726,7 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1717
1726
  setAllMessagesRead(): Promise<number>;
1718
1727
  /**
1719
1728
  * Set all messages in the conversation unread.
1720
- * @return Resulting unread messages count in the conversation.
1729
+ * @returns New count of unread messages after this update.
1721
1730
  */
1722
1731
  setAllMessagesUnread(): Promise<number>;
1723
1732
  /**
@@ -1746,7 +1755,7 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1746
1755
  * Set the last read message index to the current read horizon.
1747
1756
  * @param index Message index to set as last read. If null is provided, then
1748
1757
  * the behavior is identical to {@link Conversation.setAllMessagesUnread}.
1749
- * @returns Resulting unread messages count in the conversation.
1758
+ * @returns New count of unread messages after this update.
1750
1759
  */
1751
1760
  updateLastReadMessageIndex(index: number | null): Promise<number>;
1752
1761
  /**
@@ -1762,6 +1771,16 @@ declare class Conversation extends ReplayEventEmitter<ConversationEvents> {
1762
1771
  * @internal
1763
1772
  */
1764
1773
  _subscribe(): Promise<SyncDocument>;
1774
+ /**
1775
+ * Fetch participants and messages of the conversation. This method needs to
1776
+ * be called during conversation initialization to catch broken conversations
1777
+ * (broken conversations are conversations that have essential Sync entities
1778
+ * missing, i.e. the conversation document, the messages list or the
1779
+ * participant map). In case of this conversation being broken, the method
1780
+ * will throw an exception that will be caught and handled gracefully.
1781
+ * @internal
1782
+ */
1783
+ _fetchStreams(): Promise<void>;
1765
1784
  /**
1766
1785
  * Load the attributes of this conversation and instantiate its participants
1767
1786
  * and messages. This or _subscribe will need to be called before any events
@@ -1910,11 +1929,11 @@ type ClientEvents = {
1910
1929
  user: User;
1911
1930
  updateReasons: UserUpdateReason[];
1912
1931
  }) => void;
1913
- stateChanged: ({ state, error }: {
1914
- state: State;
1932
+ initialized: () => void;
1933
+ initFailed: ({ error }: {
1915
1934
  error?: ConnectionError;
1916
1935
  }) => void;
1917
- connectionStateChanged: (state: TwilsockConnectionState) => void;
1936
+ connectionStateChanged: (state: ConnectionState) => void;
1918
1937
  connectionError: (data: ConnectionError) => void;
1919
1938
  };
1920
1939
  /**
@@ -1927,7 +1946,7 @@ type ClientEvents = {
1927
1946
  * * `'denied'` - client connection is denied because of invalid JWT access
1928
1947
  * token. User must refresh token in order to proceed
1929
1948
  */
1930
- type ConnectionState = TwilsockConnectionState;
1949
+ type ConnectionState = "disconnected" | "connecting" | "connected";
1931
1950
  /**
1932
1951
  * State of the client. Possible values are as follows:
1933
1952
  * * `'failed'` - the client failed to initialize
@@ -1955,7 +1974,7 @@ interface ClientOptions {
1955
1974
  region?: string;
1956
1975
  productId?: string;
1957
1976
  twilsockClient?: TwilsockClient;
1958
- transport?: Transport;
1977
+ transport?: TwilsockClient;
1959
1978
  notificationsClient?: NotificationClient;
1960
1979
  syncClient?: SyncClient;
1961
1980
  typingIndicatorTimeoutOverride?: number;
@@ -1975,6 +1994,10 @@ interface ClientOptions {
1975
1994
  typingUri?: string;
1976
1995
  apiUri?: string;
1977
1996
  }
1997
+ type ConnectionError = {
1998
+ terminal: boolean;
1999
+ message: string;
2000
+ };
1978
2001
  /**
1979
2002
  * Options for {@link Client.createConversation}.
1980
2003
  */
@@ -2167,16 +2190,20 @@ declare class Client extends ReplayEventEmitter<ClientEvents> {
2167
2190
  */
2168
2191
  static readonly userUpdated = "userUpdated";
2169
2192
  /**
2170
- * Fired when the state of the client has been changed.
2193
+ * Fired when the client has completed initialization successfully.
2194
+ * @event
2195
+ */
2196
+ static readonly initialized = "initialized";
2197
+ /**
2198
+ * Fired when the client initialization failed.
2171
2199
  *
2172
2200
  * Parameters:
2173
2201
  * 1. object `data` - info object provided with the event. It has the
2174
- * following properties:
2175
- * * {@link State} `state` - the new client state
2202
+ * following property:
2176
2203
  * * Error? `error` - the initialization error if present
2177
2204
  * @event
2178
2205
  */
2179
- static readonly stateChanged = "stateChanged";
2206
+ static readonly initFailed = "initFailed";
2180
2207
  /**
2181
2208
  * Fired when the connection state of the client has been changed.
2182
2209
  *
@@ -2221,7 +2248,7 @@ declare class Client extends ReplayEventEmitter<ClientEvents> {
2221
2248
  /**
2222
2249
  * Client connection state.
2223
2250
  */
2224
- connectionState: ConnectionState;
2251
+ connectionState: ConnectionState | "unknown";
2225
2252
  /**
2226
2253
  * Promise that resolves on successful initialization.
2227
2254
  */
@@ -2285,26 +2312,6 @@ declare class Client extends ReplayEventEmitter<ClientEvents> {
2285
2312
  * initialization was completed.
2286
2313
  */
2287
2314
  get reachabilityEnabled(): boolean;
2288
- /**
2289
- * @deprecated Call constructor directly.
2290
- *
2291
- * Factory method to create a Conversations client instance.
2292
- *
2293
- * The factory method will automatically trigger connection.
2294
- * Do not use it if you need finer-grained control.
2295
- *
2296
- * Since this method returns an already-initialized client, some of the events
2297
- * will be lost because they happen *before* the initialization. It is
2298
- * recommended that `client.onWithReplay` is used as opposed to `client.on`
2299
- * for subscribing to client events. The `client.onWithReplay` will re-emit
2300
- * the most recent value for a given event if it emitted before the
2301
- * subscription.
2302
- *
2303
- * @param token Access token.
2304
- * @param options Options to customize the client.
2305
- * @returns Returns a fully initialized client.
2306
- */
2307
- static create(token: string, options?: ClientOptions | null): Promise<Client>;
2308
2315
  /**
2309
2316
  * Static method for push notification payload parsing. Returns parsed push as
2310
2317
  * a {@link PushNotification} object.
@@ -2340,7 +2347,7 @@ declare class Client extends ReplayEventEmitter<ClientEvents> {
2340
2347
  * @param conversationSid Conversation sid
2341
2348
  * @internal
2342
2349
  */
2343
- peekConversationBySid(conversationSid: string): Promise<Conversation>;
2350
+ private peekConversationBySid;
2344
2351
  /**
2345
2352
  * Get a known conversation by its unique identifier name.
2346
2353
  * @param uniqueName The unique identifier name of the conversation.
@@ -2440,4 +2447,5 @@ declare class NotificationTypes {
2440
2447
  static readonly REMOVED_FROM_CONVERSATION = "twilio.conversations.removed_from_conversation";
2441
2448
  static readonly CONSUMPTION_UPDATE = "twilio.channel.consumption_update";
2442
2449
  }
2443
- 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, CancellablePromise };
2450
+ 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 };
2451
+ export { JSONValue, JSONObject, JSONArray } from "@twilio/shared";