@twilio/conversations 2.1.0-rc.1 → 2.1.0-rc.8

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 (87) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/NOTICE.txt +679 -0
  3. package/builds/browser.js +674 -587
  4. package/builds/browser.js.map +1 -1
  5. package/builds/lib.d.ts +319 -122
  6. package/builds/lib.js +674 -587
  7. package/builds/lib.js.map +1 -1
  8. package/builds/twilio-conversations.js +852 -909
  9. package/builds/twilio-conversations.min.js +2 -14
  10. package/dist/aggregated-delivery-receipt.js +6 -1
  11. package/dist/aggregated-delivery-receipt.js.map +1 -1
  12. package/dist/client.js +165 -142
  13. package/dist/client.js.map +1 -1
  14. package/dist/command-executor.js +16 -14
  15. package/dist/command-executor.js.map +1 -1
  16. package/dist/configuration.js +14 -10
  17. package/dist/configuration.js.map +1 -1
  18. package/dist/conversation.js +212 -153
  19. package/dist/conversation.js.map +1 -1
  20. package/dist/data/conversations.js +81 -77
  21. package/dist/data/conversations.js.map +1 -1
  22. package/dist/data/messages.js +42 -38
  23. package/dist/data/messages.js.map +1 -1
  24. package/dist/data/participants.js +93 -75
  25. package/dist/data/participants.js.map +1 -1
  26. package/dist/data/users.js +24 -22
  27. package/dist/data/users.js.map +1 -1
  28. package/dist/detailed-delivery-receipt.js +1 -1
  29. package/dist/detailed-delivery-receipt.js.map +1 -1
  30. package/dist/interfaces/attributes.js +4 -4
  31. package/dist/interfaces/attributes.js.map +1 -1
  32. package/dist/interfaces/notification-types.js +5 -5
  33. package/dist/interfaces/notification-types.js.map +1 -1
  34. package/dist/logger.js +36 -15
  35. package/dist/logger.js.map +1 -1
  36. package/dist/media.js +21 -9
  37. package/dist/media.js.map +1 -1
  38. package/dist/message-builder.js +10 -9
  39. package/dist/message-builder.js.map +1 -1
  40. package/dist/message.js +131 -83
  41. package/dist/message.js.map +1 -1
  42. package/dist/packages/conversations/package.json.js +1 -1
  43. package/dist/participant.js +85 -51
  44. package/dist/participant.js.map +1 -1
  45. package/dist/push-notification.js.map +1 -1
  46. package/dist/rest-paginator.js +16 -6
  47. package/dist/rest-paginator.js.map +1 -1
  48. package/dist/services/network.js +18 -14
  49. package/dist/services/network.js.map +1 -1
  50. package/dist/services/typing-indicator.js +20 -17
  51. package/dist/services/typing-indicator.js.map +1 -1
  52. package/dist/unsent-message.js.map +1 -1
  53. package/dist/user.js +85 -59
  54. package/dist/user.js.map +1 -1
  55. package/dist/util/deferred.js +3 -1
  56. package/dist/util/deferred.js.map +1 -1
  57. package/dist/util/index.js +6 -6
  58. package/dist/util/index.js.map +1 -1
  59. package/docs/assets/js/search.js +1 -1
  60. package/docs/classes/AggregatedDeliveryReceipt.html +0 -117
  61. package/docs/classes/Client.html +24 -147
  62. package/docs/classes/Conversation.html +30 -147
  63. package/docs/classes/DetailedDeliveryReceipt.html +1 -118
  64. package/docs/classes/Media.html +0 -117
  65. package/docs/classes/Message.html +7 -124
  66. package/docs/classes/MessageBuilder.html +2 -119
  67. package/docs/classes/Participant.html +7 -124
  68. package/docs/classes/PushNotification.html +0 -117
  69. package/docs/classes/RestPaginator.html +0 -117
  70. package/docs/classes/UnsentMessage.html +0 -117
  71. package/docs/classes/User.html +7 -124
  72. package/docs/index.html +60 -0
  73. package/docs/interfaces/ClientOptions.html +0 -117
  74. package/docs/interfaces/ConversationBindings.html +0 -117
  75. package/docs/interfaces/ConversationEmailBinding.html +0 -117
  76. package/docs/interfaces/ConversationLimits.html +3098 -0
  77. package/docs/interfaces/ConversationState.html +0 -117
  78. package/docs/interfaces/CreateConversationOptions.html +1 -118
  79. package/docs/interfaces/LastMessage.html +0 -117
  80. package/docs/interfaces/Paginator.html +0 -117
  81. package/docs/interfaces/ParticipantBindings.html +0 -117
  82. package/docs/interfaces/ParticipantEmailBinding.html +0 -117
  83. package/docs/interfaces/PushNotificationData.html +0 -117
  84. package/docs/interfaces/SendEmailOptions.html +0 -117
  85. package/docs/interfaces/SendMediaOptions.html +0 -117
  86. package/docs/modules.html +60 -0
  87. package/package.json +23 -17
@@ -144,10 +144,10 @@ class Users extends replayEventEmitter.ReplayEventEmitter {
144
144
  this.services = services;
145
145
  this.fifoStack = [];
146
146
  this.myself = myself;
147
- this.myself.on('updated', (args) => this.emit('userUpdated', args));
148
- this.myself.on('userSubscribed', () => this.emit('userSubscribed', this.myself));
149
- this.myself.on('userUnsubscribed', () => {
150
- this.emit('userUnsubscribed', this.myself);
147
+ this.myself.on("updated", (args) => this.emit("userUpdated", args));
148
+ this.myself.on("userSubscribed", () => this.emit("userSubscribed", this.myself));
149
+ this.myself.on("userUnsubscribed", () => {
150
+ this.emit("userUnsubscribed", this.myself);
151
151
  this.myself._ensureFetched();
152
152
  });
153
153
  this.subscribedUsers = new Map();
@@ -156,8 +156,8 @@ class Users extends replayEventEmitter.ReplayEventEmitter {
156
156
  if (this.subscribedUsers.has(user.identity)) {
157
157
  this.subscribedUsers.delete(user.identity);
158
158
  }
159
- let foundItemIndex = -1;
160
- let foundItem = this.fifoStack.find((item, index) => {
159
+ let foundItemIndex = 0;
160
+ const foundItem = this.fifoStack.find((item, index) => {
161
161
  if (item == user.identity) {
162
162
  foundItemIndex = index;
163
163
  return true;
@@ -167,41 +167,42 @@ class Users extends replayEventEmitter.ReplayEventEmitter {
167
167
  if (foundItem) {
168
168
  this.fifoStack.splice(foundItemIndex, 1);
169
169
  }
170
- this.emit('userUnsubscribed', user);
170
+ this.emit("userUnsubscribed", user);
171
171
  }
172
172
  handleSubscribeUser(user) {
173
+ var _a, _b;
173
174
  if (this.subscribedUsers.has(user.identity)) {
174
175
  return;
175
176
  }
176
177
  if (this.fifoStack.length >= this.configuration.userInfosToSubscribe) {
177
- this.subscribedUsers.get(this.fifoStack.shift()).unsubscribe();
178
+ const item = this.fifoStack.shift();
179
+ (_b = (_a = this.subscribedUsers) === null || _a === void 0 ? void 0 : _a.get(item)) === null || _b === void 0 ? void 0 : _b.unsubscribe();
178
180
  }
179
181
  this.fifoStack.push(user.identity);
180
182
  this.subscribedUsers.set(user.identity, user);
181
- this.emit('userSubscribed', user);
183
+ this.emit("userSubscribed", user);
182
184
  }
183
185
  /**
184
186
  * Gets user, if it's in subscribed list - then return the user object from it,
185
187
  * if not - then subscribes and adds user to the FIFO stack
186
188
  * @returns {Promise<User>} Fully initialized user
187
189
  */
188
- async getUser(identity, entityName = null) {
190
+ async getUser(identity = "", entityName = "") {
189
191
  await this.myself._ensureFetched();
190
192
  if (identity == this.myself.identity) {
191
193
  return this.myself;
192
194
  }
193
- let user$1 = this.subscribedUsers.get(identity);
194
- if (!user$1) {
195
- if (!entityName) {
196
- entityName = await this.getSyncUniqueName(identity);
197
- }
198
- user$1 = new user.User(identity, entityName, this.configuration, this.services);
199
- user$1.on('updated', (args) => this.emit('userUpdated', args));
200
- user$1.on('userSubscribed', () => this.handleSubscribeUser(user$1));
201
- user$1.on('userUnsubscribed', () => this.handleUnsubscribeUser(user$1));
202
- await user$1._ensureFetched();
195
+ const user$1 = this.subscribedUsers.get(identity);
196
+ if (user$1) {
197
+ return user$1;
203
198
  }
204
- return user$1;
199
+ entityName = entityName || (await this.getSyncUniqueName(identity));
200
+ const newUser = new user.User(identity, entityName, this.configuration, this.services);
201
+ newUser.on("updated", (args) => this.emit("userUpdated", args));
202
+ newUser.on("userSubscribed", () => this.handleSubscribeUser(newUser));
203
+ newUser.on("userUnsubscribed", () => this.handleUnsubscribeUser(newUser));
204
+ await newUser._ensureFetched();
205
+ return newUser;
205
206
  }
206
207
  /**
207
208
  * @returns {Promise<Array<User>>} returns list of subscribed User objects {@see User}
@@ -216,11 +217,12 @@ class Users extends replayEventEmitter.ReplayEventEmitter {
216
217
  * @returns {Promise<string>} User's sync unique name
217
218
  */
218
219
  async getSyncUniqueName(identity) {
220
+ var _a, _b;
219
221
  const url = new index.UriBuilder(this.configuration.links.users)
220
222
  .path(identity)
221
223
  .build();
222
224
  const response = await this.services.network.get(url);
223
- return response.body.sync_objects.user_info_map;
225
+ return (_b = (_a = response.body) === null || _a === void 0 ? void 0 : _a.sync_objects.user_info_map) !== null && _b !== void 0 ? _b : "";
224
226
  }
225
227
  }
226
228
 
@@ -1 +1 @@
1
- {"version":3,"file":"users.js","sources":["../../src/data/users.ts"],"sourcesContent":["import { User, UserUpdatedEventArgs, UserUpdateReason } from '../user';\nimport { Network } from '../services/network';\nimport { SyncClient } from 'twilio-sync';\nimport { UriBuilder } from '../util';\nimport { Configuration } from '../configuration';\nimport { CommandExecutor } from '../command-executor';\nimport { ReplayEventEmitter } from '@twilio/replay-event-emitter';\n\ntype UsersEvents = {\n userUpdated: (data: {\n user: User;\n updateReasons: UserUpdateReason[]\n }) => void;\n userSubscribed: (user: User) => void;\n userUnsubscribed: (user: User) => void;\n};\n\nexport interface UsersServices {\n network: Network;\n syncClient: SyncClient;\n commandExecutor: CommandExecutor;\n}\n\n/**\n * Container for known users\n */\nclass Users extends ReplayEventEmitter<UsersEvents> {\n private readonly configuration: Configuration;\n private readonly services: UsersServices;\n\n private subscribedUsers: Map<string, User>;\n private fifoStack: any;\n public readonly myself: User;\n\n constructor(myself: User, configuration: Configuration, services: UsersServices) {\n super();\n\n this.configuration = configuration;\n this.services = services;\n\n this.fifoStack = [];\n this.myself = myself;\n this.myself.on('updated', (args: UserUpdatedEventArgs) => this.emit('userUpdated', args));\n this.myself.on('userSubscribed', () => this.emit('userSubscribed', this.myself));\n this.myself.on('userUnsubscribed', () => {\n this.emit('userUnsubscribed', this.myself);\n this.myself._ensureFetched();\n });\n\n this.subscribedUsers = new Map<string, User>();\n }\n\n private handleUnsubscribeUser(user: User): void {\n if (this.subscribedUsers.has(user.identity)) {\n this.subscribedUsers.delete(user.identity);\n }\n let foundItemIndex = -1;\n let foundItem = this.fifoStack.find((item, index) => {\n if (item == user.identity) {\n foundItemIndex = index;\n return true;\n }\n return false;\n });\n if (foundItem) {\n this.fifoStack.splice(foundItemIndex, 1);\n }\n this.emit('userUnsubscribed', user);\n }\n\n private handleSubscribeUser(user: User): void {\n if (this.subscribedUsers.has(user.identity)) {\n return;\n }\n if (this.fifoStack.length >= this.configuration.userInfosToSubscribe) {\n this.subscribedUsers.get(this.fifoStack.shift()).unsubscribe();\n }\n this.fifoStack.push(user.identity);\n this.subscribedUsers.set(user.identity, user);\n this.emit('userSubscribed', user);\n }\n\n /**\n * Gets user, if it's in subscribed list - then return the user object from it,\n * if not - then subscribes and adds user to the FIFO stack\n * @returns {Promise<User>} Fully initialized user\n */\n async getUser(identity: string, entityName: string = null): Promise<User> {\n await this.myself._ensureFetched();\n\n if (identity == this.myself.identity) {\n return this.myself;\n }\n\n let user = this.subscribedUsers.get(identity);\n if (!user) {\n if (!entityName) {\n entityName = await this.getSyncUniqueName(identity);\n }\n\n user = new User(identity, entityName, this.configuration, this.services);\n user.on('updated', (args: UserUpdatedEventArgs) => this.emit('userUpdated', args));\n user.on('userSubscribed', () => this.handleSubscribeUser(user));\n user.on('userUnsubscribed', () => this.handleUnsubscribeUser(user));\n await user._ensureFetched();\n }\n\n return user;\n }\n\n /**\n * @returns {Promise<Array<User>>} returns list of subscribed User objects {@see User}\n */\n async getSubscribedUsers(): Promise<Array<User>> {\n await this.myself._ensureFetched();\n\n const users = [this.myself];\n this.subscribedUsers.forEach((user) => users.push(user));\n\n return users;\n }\n\n /**\n * @returns {Promise<string>} User's sync unique name\n */\n private async getSyncUniqueName(identity: string): Promise<string> {\n const url = new UriBuilder(this.configuration.links.users)\n .path(identity)\n .build();\n const response = await this.services.network.get(url);\n return response.body.sync_objects.user_info_map;\n }\n}\n\nexport { Users };\n"],"names":["ReplayEventEmitter","user","User","UriBuilder"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA;;;AAGA,MAAM,KAAM,SAAQA,qCAA+B;IAQjD,YAAY,MAAY,EA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AAC,QAAQ,CAAC,CAAC;YACzED,MAAI,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,IAA0B,KAAK,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC,CAAC;YACnFA,MAAI,CAAC,EAAE,CAAC,gBAAgB,EAAE,MAAM,IAAI,CAAC,mBAAmB,CAACA,MAAI,CAAC,CAAC,CAAC;YAChEA,MAAI,CAAC,EAAE,CAAC,kBAAkB,EAAE,MAAM,IAAI,CAAC,qBAAqB,CAACA,MAAI,CAAC,CAAC,CAAC;YACpE,MAAMA,MAAI,CAAC,cAAc,EAAE,CAAC;SAC7B;QAED,OAAOA,MAAI,CAAC;KACb;;;;IAKD,MAAM,kBAAkB;QACtB,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;QAEnC,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC5B,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAEzD,OAAO,KAAK,CAAC;KACd;;;;IAKO,MAAM,iBAAiB,CAAC,QAAgB;QAC9C,MAAM,GAAG,GAAG,IAAIE,gBAAU,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC;aACvD,IAAI,CAAC,QAAQ,CAAC;aACd,KAAK,EAAE,CAAC;QACX,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACtD,OAAO,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC;KACjD;;;;;"}
1
+ {"version":3,"file":"users.js","sources":["../../src/data/users.ts"],"sourcesContent":["import { User, UserUpdatedEventArgs, UserUpdateReason } from \"../user\";\nimport { Network } from \"../services/network\";\nimport { SyncClient } from \"twilio-sync\";\nimport { UriBuilder } from \"../util\";\nimport { Configuration } from \"../configuration\";\nimport { CommandExecutor } from \"../command-executor\";\nimport { ReplayEventEmitter } from \"@twilio/replay-event-emitter\";\nimport { UserResponse } from \"../interfaces/commands/user\";\n\ntype UsersEvents = {\n userUpdated: (data: {\n user: User;\n updateReasons: UserUpdateReason[];\n }) => void;\n userSubscribed: (user: User) => void;\n userUnsubscribed: (user: User) => void;\n};\n\nexport interface UsersServices {\n network: Network;\n syncClient: SyncClient;\n commandExecutor: CommandExecutor;\n}\n\n/**\n * Container for known users\n */\nclass Users extends ReplayEventEmitter<UsersEvents> {\n private readonly configuration: Configuration;\n private readonly services: UsersServices;\n\n private subscribedUsers: Map<string, User>;\n private fifoStack: string[];\n public readonly myself: User;\n\n constructor(\n myself: User,\n configuration: Configuration,\n services: UsersServices\n ) {\n super();\n\n this.configuration = configuration;\n this.services = services;\n\n this.fifoStack = [];\n this.myself = myself;\n this.myself.on(\"updated\", (args: UserUpdatedEventArgs) =>\n this.emit(\"userUpdated\", args)\n );\n this.myself.on(\"userSubscribed\", () =>\n this.emit(\"userSubscribed\", this.myself)\n );\n this.myself.on(\"userUnsubscribed\", () => {\n this.emit(\"userUnsubscribed\", this.myself);\n this.myself._ensureFetched();\n });\n\n this.subscribedUsers = new Map<string, User>();\n }\n\n private handleUnsubscribeUser(user: User): void {\n if (this.subscribedUsers.has(user.identity)) {\n this.subscribedUsers.delete(user.identity);\n }\n let foundItemIndex = 0;\n const foundItem = this.fifoStack.find((item, index) => {\n if (item == user.identity) {\n foundItemIndex = index;\n return true;\n }\n return false;\n });\n if (foundItem) {\n this.fifoStack.splice(foundItemIndex, 1);\n }\n this.emit(\"userUnsubscribed\", user);\n }\n\n private handleSubscribeUser(user: User): void {\n if (this.subscribedUsers.has(user.identity)) {\n return;\n }\n if (this.fifoStack.length >= this.configuration.userInfosToSubscribe) {\n const item = this.fifoStack.shift() as string;\n this.subscribedUsers?.get(item)?.unsubscribe();\n }\n this.fifoStack.push(user.identity);\n this.subscribedUsers.set(user.identity, user);\n this.emit(\"userSubscribed\", user);\n }\n\n /**\n * Gets user, if it's in subscribed list - then return the user object from it,\n * if not - then subscribes and adds user to the FIFO stack\n * @returns {Promise<User>} Fully initialized user\n */\n async getUser(identity = \"\", entityName = \"\"): Promise<User> {\n await this.myself._ensureFetched();\n\n if (identity == this.myself.identity) {\n return this.myself;\n }\n\n const user = this.subscribedUsers.get(identity);\n\n if (user) {\n return user;\n }\n\n entityName = entityName || (await this.getSyncUniqueName(identity));\n\n const newUser = new User(\n identity,\n entityName,\n this.configuration,\n this.services\n );\n\n newUser.on(\"updated\", (args: UserUpdatedEventArgs) =>\n this.emit(\"userUpdated\", args)\n );\n newUser.on(\"userSubscribed\", () => this.handleSubscribeUser(newUser));\n newUser.on(\"userUnsubscribed\", () => this.handleUnsubscribeUser(newUser));\n await newUser._ensureFetched();\n\n return newUser;\n }\n\n /**\n * @returns {Promise<Array<User>>} returns list of subscribed User objects {@see User}\n */\n async getSubscribedUsers(): Promise<Array<User>> {\n await this.myself._ensureFetched();\n\n const users = [this.myself];\n this.subscribedUsers.forEach((user) => users.push(user));\n\n return users;\n }\n\n /**\n * @returns {Promise<string>} User's sync unique name\n */\n private async getSyncUniqueName(identity: string): Promise<string> {\n const url = new UriBuilder(this.configuration.links.users)\n .path(identity)\n .build();\n const response = await this.services.network.get<UserResponse>(url);\n return response.body?.sync_objects.user_info_map ?? \"\";\n }\n}\n\nexport { Users };\n"],"names":["ReplayEventEmitter","user","User","UriBuilder"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA;;;AAGA,MAAM,KAAM,SAAQA,qCAA+B;IAQjD,YACE,MAAY,EACZ,aAA4B,EAC5B,QAAuB;QAEvB,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,aAAa,GAAG,aAAa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,CACd,CAAC;QAEF,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,IAA0B,KAC/C,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,CAC/B,CAAC;QACF,OAAO,CAAC,EAAE,CAAC,gBAAgB,EAAE,MAAM,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC;QACtE,OAAO,CAAC,EAAE,CAAC,kBAAkB,EAAE,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC;QAC1E,MAAM,OAAO,CAAC,cAAc,EAAE,CAAC;QAE/B,OAAO,OAAO,CAAC;KAChB;;;;IAKD,MAAM,kBAAkB;QACtB,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;QAEnC,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC5B,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAEzD,OAAO,KAAK,CAAC;KACd;;;;IAKO,MAAM,iBAAiB,CAAC,QAAgB;;QAC9C,MAAM,GAAG,GAAG,IAAIC,gBAAU,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC;aACvD,IAAI,CAAC,QAAQ,CAAC;aACd,KAAK,EAAE,CAAC;QACX,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAe,GAAG,CAAC,CAAC;QACpE,OAAO,MAAA,MAAA,QAAQ,CAAC,IAAI,0CAAE,YAAY,CAAC,aAAa,mCAAI,EAAE,CAAC;KACxD;;;;;"}
@@ -143,7 +143,7 @@ class DetailedDeliveryReceipt {
143
143
  this.conversationSid = descriptor.conversation_sid;
144
144
  this.channelMessageSid = descriptor.channel_message_sid;
145
145
  this.participantSid = descriptor.participant_sid;
146
- this.status = descriptor.status || 'queued';
146
+ this.status = descriptor.status || "queued";
147
147
  this.errorCode = descriptor.error_code || 0;
148
148
  this.dateCreated = descriptor.date_created;
149
149
  this.dateUpdated = descriptor.date_updated;
@@ -1 +1 @@
1
- {"version":3,"file":"detailed-delivery-receipt.js","sources":["../src/detailed-delivery-receipt.ts"],"sourcesContent":["/**\n * Message delivery status.\n */\ntype DeliveryStatus =\n | 'sent'\n | 'delivered'\n | 'failed'\n | 'read'\n | 'undelivered'\n | 'queued';\n\ninterface DetailedDeliveryReceiptDescriptor {\n sid: string;\n message_sid: string;\n conversation_sid: string;\n channel_message_sid: string;\n participant_sid: string;\n status: DeliveryStatus;\n error_code: number | null;\n date_created: string;\n date_updated: string;\n}\n\n/**\n * Represents a delivery receipt of a message.\n */\nclass DetailedDeliveryReceipt {\n /**\n * Unique identifier for the delivery receipt.\n */\n sid: string;\n\n /**\n * Unique identifier for the message in the conversation.\n */\n messageSid: string;\n\n /**\n * Unique identifier for the conversation.\n */\n conversationSid: string;\n\n /**\n * Unique identifier for the `‘channel’` message (e.g., `WAxx` for WhatsApp, `SMxx` for SMS).\n */\n channelMessageSid: string;\n\n /**\n * Unique identifier for the participant.\n */\n participantSid: string;\n\n /**\n * Status of the message delivery.\n */\n status: DeliveryStatus;\n\n /**\n * Numeric error code mapped from Status callback code. Information about the error codes can be found\n * [here](https://www.twilio.com/docs/sms/api/message-resource#delivery-related-errors).\n */\n errorCode: number | null;\n\n /**\n * Date this delivery receipt was created on.\n */\n dateCreated: string;\n\n /**\n * Date this delivery receipt was last updated on.\n */\n dateUpdated: string;\n\n /**\n * @internal\n */\n constructor(descriptor: DetailedDeliveryReceiptDescriptor) {\n this.sid = descriptor.sid;\n this.messageSid = descriptor.message_sid;\n this.conversationSid = descriptor.conversation_sid;\n this.channelMessageSid = descriptor.channel_message_sid;\n this.participantSid = descriptor.participant_sid;\n this.status = descriptor.status || 'queued';\n this.errorCode = descriptor.error_code || 0;\n this.dateCreated = descriptor.date_created;\n this.dateUpdated = descriptor.date_updated;\n }\n}\n\nexport {\n DetailedDeliveryReceipt,\n DetailedDeliveryReceiptDescriptor,\n DeliveryStatus\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA;;;AAGA,MAAM,uBAAuB;;;;IAkD3B,YAAY,UAA6C;QACvD,IAAI,CAAC,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC;QAC1B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC,WAAW,CAAC;QACzC,IAAI,CAAC,eAAe,GAAG,UAAU,CAAC,gBAAgB,CAAC;QACnD,IAAI,CAAC,iBAAiB,GAAG,UAAU,CAAC,mBAAmB,CAAC;QACxD,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC,eAAe,CAAC;QACjD,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,IAAI,QAAQ,CAAC;QAC5C,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC,UAAU,IAAI,CAAC,CAAC;QAC5C,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,YAAY,CAAC;QAC3C,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,YAAY,CAAC;KAC5C;;;;;"}
1
+ {"version":3,"file":"detailed-delivery-receipt.js","sources":["../src/detailed-delivery-receipt.ts"],"sourcesContent":["/**\n * Message delivery status.\n */\ntype DeliveryStatus =\n | \"sent\"\n | \"delivered\"\n | \"failed\"\n | \"read\"\n | \"undelivered\"\n | \"queued\";\n\ninterface DetailedDeliveryReceiptDescriptor {\n sid: string;\n message_sid: string;\n conversation_sid: string;\n channel_message_sid: string;\n participant_sid: string;\n status: DeliveryStatus;\n error_code: string | null;\n date_created: string;\n date_updated: string;\n}\n\n/**\n * Represents a delivery receipt of a message.\n */\nclass DetailedDeliveryReceipt {\n /**\n * Unique identifier for the delivery receipt.\n */\n sid: string;\n\n /**\n * Unique identifier for the message in the conversation.\n */\n messageSid: string;\n\n /**\n * Unique identifier for the conversation.\n */\n conversationSid: string;\n\n /**\n * Unique identifier for the `‘channel’` message (e.g., `WAxx` for WhatsApp, `SMxx` for SMS).\n */\n channelMessageSid: string;\n\n /**\n * Unique identifier for the participant.\n */\n participantSid: string;\n\n /**\n * Status of the message delivery.\n */\n status: DeliveryStatus;\n\n /**\n * Numeric error code mapped from Status callback code. Information about the error codes can be found\n * [here](https://www.twilio.com/docs/sms/api/message-resource#delivery-related-errors).\n */\n errorCode: string | 0;\n\n /**\n * Date this delivery receipt was created on.\n */\n dateCreated: string;\n\n /**\n * Date this delivery receipt was last updated on.\n */\n dateUpdated: string;\n\n /**\n * @internal\n */\n constructor(descriptor: DetailedDeliveryReceiptDescriptor) {\n this.sid = descriptor.sid;\n this.messageSid = descriptor.message_sid;\n this.conversationSid = descriptor.conversation_sid;\n this.channelMessageSid = descriptor.channel_message_sid;\n this.participantSid = descriptor.participant_sid;\n this.status = descriptor.status || \"queued\";\n this.errorCode = descriptor.error_code || 0;\n this.dateCreated = descriptor.date_created;\n this.dateUpdated = descriptor.date_updated;\n }\n}\n\nexport {\n DetailedDeliveryReceipt,\n DetailedDeliveryReceiptDescriptor,\n DeliveryStatus,\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA;;;AAGA,MAAM,uBAAuB;;;;IAkD3B,YAAY,UAA6C;QACvD,IAAI,CAAC,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC;QAC1B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC,WAAW,CAAC;QACzC,IAAI,CAAC,eAAe,GAAG,UAAU,CAAC,gBAAgB,CAAC;QACnD,IAAI,CAAC,iBAAiB,GAAG,UAAU,CAAC,mBAAmB,CAAC;QACxD,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC,eAAe,CAAC;QACjD,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,IAAI,QAAQ,CAAC;QAC5C,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC,UAAU,IAAI,CAAC,CAAC;QAC5C,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,YAAY,CAAC;QAC3C,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,YAAY,CAAC;KAC5C;;;;;"}
@@ -134,12 +134,12 @@ var declarativeTypeValidator = require('@twilio/declarative-type-validator');
134
134
 
135
135
  // Any JSON value
136
136
  const attributesValidator = declarativeTypeValidator.custom((value) => [
137
- ['string', 'number', 'boolean', 'object'].includes(typeof value),
138
- 'a JSON type'
137
+ ["string", "number", "boolean", "object"].includes(typeof value),
138
+ "a JSON type",
139
139
  ]);
140
140
  const optionalAttributesValidator = declarativeTypeValidator.custom((value) => [
141
- ['undefined', 'string', 'number', 'boolean', 'object'].includes(typeof value),
142
- 'an optional JSON type'
141
+ ["undefined", "string", "number", "boolean", "object"].includes(typeof value),
142
+ "an optional JSON type",
143
143
  ]);
144
144
 
145
145
  exports.attributesValidator = attributesValidator;
@@ -1 +1 @@
1
- {"version":3,"file":"attributes.js","sources":["../../src/interfaces/attributes.ts"],"sourcesContent":["import { custom } from '@twilio/declarative-type-validator';\n\n// Any JSON value\nexport const attributesValidator = custom((value) => [\n ['string', 'number', 'boolean', 'object'].includes(typeof value),\n 'a JSON type'\n]);\n\nexport const optionalAttributesValidator = custom((value) => [\n ['undefined', 'string', 'number', 'boolean', 'object'].includes(typeof value),\n 'an optional JSON type'\n]);\n"],"names":["custom"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;MACa,mBAAmB,GAAGA,+BAAM,CAAC,CAAC,KAAK,KAAK;IACjD,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,KAAK,CAAC;IAChE,aAAa;CAChB,EAAE;MAEU,2BAA2B,GAAGA,+BAAM,CAAC,CAAC,KAAK,KAAK;IACzD,CAAC,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,KAAK,CAAC;IAC7E,uBAAuB;CAC1B;;;;;"}
1
+ {"version":3,"file":"attributes.js","sources":["../../src/interfaces/attributes.ts"],"sourcesContent":["import { custom } from \"@twilio/declarative-type-validator\";\n\n// Any JSON value\nexport const attributesValidator = custom((value) => [\n [\"string\", \"number\", \"boolean\", \"object\"].includes(typeof value),\n \"a JSON type\",\n]);\n\nexport const optionalAttributesValidator = custom((value) => [\n [\"undefined\", \"string\", \"number\", \"boolean\", \"object\"].includes(typeof value),\n \"an optional JSON type\",\n]);\n"],"names":["custom"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;MACa,mBAAmB,GAAGA,+BAAM,CAAC,CAAC,KAAK,KAAK;IACnD,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,KAAK,CAAC;IAChE,aAAa;CACd,EAAE;MAEU,2BAA2B,GAAGA,+BAAM,CAAC,CAAC,KAAK,KAAK;IAC3D,CAAC,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,KAAK,CAAC;IAC7E,uBAAuB;CACxB;;;;;"}
@@ -132,12 +132,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
132
132
 
133
133
  class NotificationTypes {
134
134
  }
135
- NotificationTypes.TYPING_INDICATOR = 'twilio.ipmsg.typing_indicator';
136
- NotificationTypes.NEW_MESSAGE = 'twilio.conversations.new_message';
137
- NotificationTypes.ADDED_TO_CONVERSATION = 'twilio.conversations.added_to_conversation';
135
+ NotificationTypes.TYPING_INDICATOR = "twilio.ipmsg.typing_indicator";
136
+ NotificationTypes.NEW_MESSAGE = "twilio.conversations.new_message";
137
+ NotificationTypes.ADDED_TO_CONVERSATION = "twilio.conversations.added_to_conversation";
138
138
  // static readonly INVITED_TO_CHANNEL = 'twilio.channel.invited_to_channel';
139
- NotificationTypes.REMOVED_FROM_CONVERSATION = 'twilio.conversations.removed_from_conversation';
140
- NotificationTypes.CONSUMPTION_UPDATE = 'twilio.channel.consumption_update';
139
+ NotificationTypes.REMOVED_FROM_CONVERSATION = "twilio.conversations.removed_from_conversation";
140
+ NotificationTypes.CONSUMPTION_UPDATE = "twilio.channel.consumption_update";
141
141
 
142
142
  exports.NotificationTypes = NotificationTypes;
143
143
  //# sourceMappingURL=notification-types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"notification-types.js","sources":["../../src/interfaces/notification-types.ts"],"sourcesContent":["class NotificationTypes {\n static readonly TYPING_INDICATOR = 'twilio.ipmsg.typing_indicator';\n static readonly NEW_MESSAGE = 'twilio.conversations.new_message';\n static readonly ADDED_TO_CONVERSATION = 'twilio.conversations.added_to_conversation';\n // static readonly INVITED_TO_CHANNEL = 'twilio.channel.invited_to_channel';\n static readonly REMOVED_FROM_CONVERSATION = 'twilio.conversations.removed_from_conversation';\n static readonly CONSUMPTION_UPDATE = 'twilio.channel.consumption_update';\n}\n\nexport { NotificationTypes };"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAM,iBAAiB;;AACL,kCAAgB,GAAG,+BAA+B,CAAC;AACnD,6BAAW,GAAG,kCAAkC,CAAC;AACjD,uCAAqB,GAAG,4CAA4C,CAAC;AACrF;AACgB,2CAAyB,GAAG,gDAAgD,CAAC;AAC7E,oCAAkB,GAAG,mCAAmC;;;;"}
1
+ {"version":3,"file":"notification-types.js","sources":["../../src/interfaces/notification-types.ts"],"sourcesContent":["class NotificationTypes {\n static readonly TYPING_INDICATOR = \"twilio.ipmsg.typing_indicator\";\n static readonly NEW_MESSAGE = \"twilio.conversations.new_message\";\n static readonly ADDED_TO_CONVERSATION =\n \"twilio.conversations.added_to_conversation\";\n // static readonly INVITED_TO_CHANNEL = 'twilio.channel.invited_to_channel';\n static readonly REMOVED_FROM_CONVERSATION =\n \"twilio.conversations.removed_from_conversation\";\n static readonly CONSUMPTION_UPDATE = \"twilio.channel.consumption_update\";\n}\n\nexport { NotificationTypes };\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAM,iBAAiB;;AACL,kCAAgB,GAAG,+BAA+B,CAAC;AACnD,6BAAW,GAAG,kCAAkC,CAAC;AACjD,uCAAqB,GACnC,4CAA4C,CAAC;AAC/C;AACgB,2CAAyB,GACvC,gDAAgD,CAAC;AACnC,oCAAkB,GAAG,mCAAmC;;;;"}
package/dist/logger.js CHANGED
@@ -157,13 +157,14 @@ var loglevelLog__namespace = /*#__PURE__*/_interopNamespace(loglevelLog);
157
157
  function prepareLine(prefix, args) {
158
158
  return [`${new Date().toISOString()} Conversations ${prefix}:`].concat(Array.from(args));
159
159
  }
160
- const log = loglevelLog__namespace.getLogger('twilio-conversations'); // twilio-conversations is used by Flex SDK. Please DO NOT change
160
+ const log = loglevelLog__namespace.getLogger("twilio-conversations"); // twilio-conversations is used by Flex SDK. Please DO NOT change
161
161
  class Logger {
162
162
  constructor(prefix) {
163
- this.prefix = '';
164
- this.prefix = prefix !== null && prefix !== undefined && prefix.length > 0
165
- ? prefix + ' '
166
- : '';
163
+ this.prefix = "";
164
+ this.prefix =
165
+ prefix !== null && prefix !== undefined && prefix.length > 0
166
+ ? prefix + " "
167
+ : "";
167
168
  }
168
169
  static scope(prefix) {
169
170
  return new Logger(prefix);
@@ -174,16 +175,36 @@ class Logger {
174
175
  static setLevel(level) {
175
176
  log.setLevel(level);
176
177
  }
177
- trace(...args) { log.trace.apply(null, prepareLine(this.prefix + 'T', args)); }
178
- debug(...args) { log.debug.apply(null, prepareLine(this.prefix + 'D', args)); }
179
- info(...args) { log.info.apply(null, prepareLine(this.prefix + 'I', args)); }
180
- warn(...args) { log.warn.apply(null, prepareLine(this.prefix + 'W', args)); }
181
- error(...args) { log.error.apply(null, prepareLine(this.prefix + 'E', args)); }
182
- static trace(...args) { log.trace.apply(null, prepareLine('T', args)); }
183
- static debug(...args) { log.debug.apply(null, prepareLine('D', args)); }
184
- static info(...args) { log.info.apply(null, prepareLine('I', args)); }
185
- static warn(...args) { log.warn.apply(null, prepareLine('W', args)); }
186
- static error(...args) { log.error.apply(null, prepareLine('E', args)); }
178
+ trace(...args) {
179
+ log.trace.apply(null, prepareLine(this.prefix + "T", args));
180
+ }
181
+ debug(...args) {
182
+ log.debug.apply(null, prepareLine(this.prefix + "D", args));
183
+ }
184
+ info(...args) {
185
+ log.info.apply(null, prepareLine(this.prefix + "I", args));
186
+ }
187
+ warn(...args) {
188
+ log.warn.apply(null, prepareLine(this.prefix + "W", args));
189
+ }
190
+ error(...args) {
191
+ log.error.apply(null, prepareLine(this.prefix + "E", args));
192
+ }
193
+ static trace(...args) {
194
+ log.trace.apply(null, prepareLine("T", args));
195
+ }
196
+ static debug(...args) {
197
+ log.debug.apply(null, prepareLine("D", args));
198
+ }
199
+ static info(...args) {
200
+ log.info.apply(null, prepareLine("I", args));
201
+ }
202
+ static warn(...args) {
203
+ log.warn.apply(null, prepareLine("W", args));
204
+ }
205
+ static error(...args) {
206
+ log.error.apply(null, prepareLine("E", args));
207
+ }
187
208
  }
188
209
 
189
210
  exports.Logger = Logger;
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sources":["../src/logger.ts"],"sourcesContent":["import * as loglevelLog from 'loglevel';\n\nfunction prepareLine(prefix, args) {\n return [`${new Date().toISOString()} Conversations ${prefix}:`].concat(Array.from(args));\n}\n\nconst log: loglevelLog.Logger = loglevelLog.getLogger('twilio-conversations'); // twilio-conversations is used by Flex SDK. Please DO NOT change\n\nclass Logger {\n private prefix: string = '';\n\n private constructor(prefix: string) {\n this.prefix = prefix !== null && prefix !== undefined && prefix.length > 0\n ? prefix + ' '\n : '';\n }\n\n static scope(prefix: string): Logger {\n return new Logger(prefix);\n }\n\n setLevel(level: any) {\n log.setLevel(level);\n }\n\n static setLevel(level: any) {\n log.setLevel(level);\n }\n\n trace(...args) { log.trace.apply(null, prepareLine(this.prefix + 'T', args)); }\n\n debug(...args) { log.debug.apply(null, prepareLine(this.prefix + 'D', args)); }\n\n info(...args) { log.info.apply(null, prepareLine(this.prefix + 'I', args)); }\n\n warn(...args) { log.warn.apply(null, prepareLine(this.prefix + 'W', args)); }\n\n error(...args) { log.error.apply(null, prepareLine(this.prefix + 'E', args)); }\n\n static trace(...args) { log.trace.apply(null, prepareLine('T', args)); }\n\n static debug(...args) { log.debug.apply(null, prepareLine('D', args)); }\n\n static info(...args) { log.info.apply(null, prepareLine('I', args)); }\n\n static warn(...args) { log.warn.apply(null, prepareLine('W', args)); }\n\n static error(...args) { log.error.apply(null, prepareLine('E', args)); }\n\n}\n\nexport { Logger };\n"],"names":["loglevelLog"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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loglevelLog from \"loglevel\";\nimport { LogLevelDesc } from \"loglevel\";\n\nfunction prepareLine(prefix, args) {\n return [`${new Date().toISOString()} Conversations ${prefix}:`].concat(\n Array.from(args)\n );\n}\n\nconst log: loglevelLog.Logger = loglevelLog.getLogger(\"twilio-conversations\"); // twilio-conversations is used by Flex SDK. Please DO NOT change\n\nclass Logger {\n private prefix = \"\";\n\n private constructor(prefix: string) {\n this.prefix =\n prefix !== null && prefix !== undefined && prefix.length > 0\n ? prefix + \" \"\n : \"\";\n }\n\n static scope(prefix: string): Logger {\n return new Logger(prefix);\n }\n\n setLevel(level: LogLevelDesc) {\n log.setLevel(level);\n }\n\n static setLevel(level: LogLevelDesc) {\n log.setLevel(level);\n }\n\n trace(...args) {\n log.trace.apply(null, prepareLine(this.prefix + \"T\", args));\n }\n\n debug(...args) {\n log.debug.apply(null, prepareLine(this.prefix + \"D\", args));\n }\n\n info(...args) {\n log.info.apply(null, prepareLine(this.prefix + \"I\", args));\n }\n\n warn(...args) {\n log.warn.apply(null, prepareLine(this.prefix + \"W\", args));\n }\n\n error(...args) {\n log.error.apply(null, prepareLine(this.prefix + \"E\", args));\n }\n\n static trace(...args) {\n log.trace.apply(null, prepareLine(\"T\", args));\n }\n\n static debug(...args) {\n log.debug.apply(null, prepareLine(\"D\", args));\n }\n\n static info(...args) {\n log.info.apply(null, prepareLine(\"I\", args));\n }\n\n static warn(...args) {\n log.warn.apply(null, prepareLine(\"W\", args));\n }\n\n static error(...args) {\n log.error.apply(null, prepareLine(\"E\", args));\n }\n}\n\nexport { Logger };\n"],"names":["loglevelLog"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,SAAS,WAAW,CAAC,MAAM,EAAE,IAAI;IAC/B,OAAO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C,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,MAAM,GAAG,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;KAC5D;IAED,KAAK,CAAC,GAAG,IAAI;QACX,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,MAAM,GAAG,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;KAC7D;IAED,OAAO,KAAK,CAAC,GAAG,IAAI;QAClB,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;KAC/C;IAED,OAAO,KAAK,CAAC,GAAG,IAAI;QAClB,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;KAC/C;IAED,OAAO,IAAI,CAAC,GAAG,IAAI;QACjB,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;KAC9C;IAED,OAAO,IAAI,CAAC,GAAG,IAAI;QACjB,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;KAC9C;IAED,OAAO,KAAK,CAAC,GAAG,IAAI;QAClB,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;KAC/C;;;;;"}
package/dist/media.js CHANGED
@@ -150,29 +150,39 @@ class Media {
150
150
  category: data.category,
151
151
  filename: data.filename,
152
152
  contentType: data.contentType,
153
- size: data.size
153
+ size: data.size,
154
154
  };
155
155
  }
156
156
  /**
157
157
  * Server-assigned unique identifier for the media.
158
158
  */
159
- get sid() { return this.state.sid; }
159
+ get sid() {
160
+ return this.state.sid;
161
+ }
160
162
  /**
161
163
  * File name. Null if absent.
162
164
  */
163
- get filename() { return this.state.filename; }
165
+ get filename() {
166
+ return this.state.filename;
167
+ }
164
168
  /**
165
169
  * Content type of the media.
166
170
  */
167
- get contentType() { return this.state.contentType; }
171
+ get contentType() {
172
+ return this.state.contentType;
173
+ }
168
174
  /**
169
175
  * Size of the media in bytes.
170
176
  */
171
- get size() { return this.state.size; }
177
+ get size() {
178
+ return this.state.size;
179
+ }
172
180
  /**
173
181
  * Media category, can be one of the {@link MediaCategory} values.
174
182
  */
175
- get category() { return this.state.category; }
183
+ get category() {
184
+ return this.state.category;
185
+ }
176
186
  /**
177
187
  * Returns the direct content URL for the media.
178
188
  *
@@ -181,8 +191,9 @@ class Media {
181
191
  * Each call to this function produces a new temporary URL.
182
192
  */
183
193
  async getContentTemporaryUrl() {
194
+ var _a, _b;
184
195
  await this._fetchMcsMedia();
185
- return this.mcsMedia.getContentUrl();
196
+ return (_b = (_a = this.mcsMedia) === null || _a === void 0 ? void 0 : _a.getContentUrl()) !== null && _b !== void 0 ? _b : null;
186
197
  }
187
198
  /**
188
199
  * Returns cached direct content URL for the media.
@@ -194,8 +205,9 @@ class Media {
194
205
  * @returns {Promise<String>}
195
206
  */
196
207
  async getCachedTemporaryUrl() {
208
+ var _a, _b;
197
209
  await this._fetchMcsMedia();
198
- return this.mcsMedia.getCachedContentUrl();
210
+ return (_b = (_a = this.mcsMedia) === null || _a === void 0 ? void 0 : _a.getCachedContentUrl()) !== null && _b !== void 0 ? _b : null;
199
211
  }
200
212
  async _fetchMcsMedia() {
201
213
  if (!this.mcsMedia) {
@@ -203,7 +215,7 @@ class Media {
203
215
  this.mcsMedia = await this.services.mcsClient.get(this.state.sid);
204
216
  }
205
217
  else {
206
- throw new Error('Media Content Service is unavailable');
218
+ throw new Error("Media Content Service is unavailable");
207
219
  }
208
220
  }
209
221
  }
package/dist/media.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"media.js","sources":["../src/media.ts"],"sourcesContent":["import {\n McsClient,\n McsMedia,\n MediaCategory as McsMediaCategory\n} from '@twilio/mcs-client';\n\n/**\n * Category of media. Possible values are as follows:\n * * `'media'`\n * * `'body'`\n * * `'history'`\n */\ntype MediaCategory = McsMediaCategory;\n\ninterface MediaState {\n sid: string;\n category: MediaCategory;\n filename?: string;\n contentType: string;\n size: number;\n}\n\ninterface MediaServices {\n mcsClient: McsClient;\n}\n\n/**\n * Represents a media information for a message in a conversation.\n */\nclass Media {\n\n private state: MediaState;\n private services: MediaServices;\n private mcsMedia: McsMedia = null;\n\n /**\n * @internal\n */\n constructor(data: MediaState | McsMedia, services: MediaServices) {\n\n this.services = services;\n\n if (data instanceof McsMedia) {\n this.mcsMedia = data as McsMedia;\n }\n\n this.state = {\n sid: data.sid,\n category: data.category,\n filename: data.filename,\n contentType: data.contentType,\n size: data.size\n };\n }\n\n /**\n * Server-assigned unique identifier for the media.\n */\n public get sid(): string { return this.state.sid; }\n\n /**\n * File name. Null if absent.\n */\n public get filename(): string {return this.state.filename; }\n\n /**\n * Content type of the media.\n */\n public get contentType(): string { return this.state.contentType; }\n\n /**\n * Size of the media in bytes.\n */\n public get size(): number {return this.state.size; }\n\n /**\n * Media category, can be one of the {@link MediaCategory} values.\n */\n public get category(): MediaCategory { return this.state.category; }\n\n /**\n * Returns the direct content URL for the media.\n *\n * This URL is impermanent, it will expire in several minutes and cannot be cached.\n * If the URL becomes expired, you need to request a new one.\n * Each call to this function produces a new temporary URL.\n */\n public async getContentTemporaryUrl(): Promise<string> {\n await this._fetchMcsMedia();\n return this.mcsMedia.getContentUrl();\n }\n\n /**\n * Returns cached direct content URL for the media.\n *\n * This URL will expire in several minutes. This function does not refresh the URL and can be used to query it several times\n * without causing network traffic.\n * If the URL becomes expired, you need to request a new one using getContentTemporaryUrl().\n *\n * @returns {Promise<String>}\n */\n public async getCachedTemporaryUrl(): Promise<string> {\n await this._fetchMcsMedia();\n return this.mcsMedia.getCachedContentUrl();\n }\n\n private async _fetchMcsMedia() {\n if (!this.mcsMedia) {\n if (this.services.mcsClient) {\n this.mcsMedia = await this.services.mcsClient.get(this.state.sid);\n } else {\n throw new Error('Media Content Service is unavailable');\n }\n }\n }\n}\n\nexport {\n Media,\n MediaState,\n MediaServices,\n MediaCategory,\n};\n"],"names":["McsMedia"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA;;;AAGA,MAAM,KAAK;;;;IAST,YAAY,IAA2B,EAAE,QAAuB;QALxD,aAAQ,GAAa,IAAI,CAAC;QAOhC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,IAAI,IAAI,YAAYA,kBAAQ,EAAE;YAC5B,IAAI,CAAC,QAAQ,GAAG,IAAgB,CAAC;SAClC;QAED,IAAI,CAAC,KAAK,GAAG;YACX,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC;KACH;;;;IAKD,IAAW,GAAG,KAAa,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;;;;IAKnD,IAAW,QAAQ,KAAY,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE;;;;IAK5D,IAAW,WAAW,KAAa,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE;;;;IAKnE,IAAW,IAAI,KAAY,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;;;;IAKpD,IAAW,QAAQ,KAAoB,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE;;;;;;;;IAS7D,MAAM,sBAAsB;QACjC,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;QAC5B,OAAO,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAC;KACtC;;;;;;;;;;IAWM,MAAM,qBAAqB;QAChC,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;QAC5B,OAAO,IAAI,CAAC,QAAQ,CAAC,mBAAmB,EAAE,CAAC;KAC5C;IAEO,MAAM,cAAc;QAC1B,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAClB,IAAI,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE;gBAC3B,IAAI,CAAC,QAAQ,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;aACnE;iBAAM;gBACL,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;aACzD;SACF;KACF;;;;;"}
1
+ {"version":3,"file":"media.js","sources":["../src/media.ts"],"sourcesContent":["import {\n McsClient,\n McsMedia,\n MediaCategory as McsMediaCategory,\n} from \"@twilio/mcs-client\";\n\n/**\n * Category of media. Possible values are as follows:\n * * `'media'`\n * * `'body'`\n * * `'history'`\n */\ntype MediaCategory = McsMediaCategory;\n\ninterface MediaState {\n sid: string;\n category: MediaCategory;\n filename: string | null;\n contentType: string;\n size: number;\n}\n\ninterface MediaServices {\n mcsClient: McsClient;\n}\n\n/**\n * Represents a media information for a message in a conversation.\n */\nclass Media {\n private state: MediaState;\n private services: MediaServices;\n private mcsMedia: McsMedia | null = null;\n\n /**\n * @internal\n */\n constructor(data: MediaState | McsMedia, services: MediaServices) {\n this.services = services;\n\n if (data instanceof McsMedia) {\n this.mcsMedia = data as McsMedia;\n }\n\n this.state = {\n sid: data.sid,\n category: data.category,\n filename: data.filename,\n contentType: data.contentType,\n size: data.size,\n };\n }\n\n /**\n * Server-assigned unique identifier for the media.\n */\n public get sid(): string {\n return this.state.sid;\n }\n\n /**\n * File name. Null if absent.\n */\n public get filename(): string | null {\n return this.state.filename;\n }\n\n /**\n * Content type of the media.\n */\n public get contentType(): string {\n return this.state.contentType;\n }\n\n /**\n * Size of the media in bytes.\n */\n public get size(): number {\n return this.state.size;\n }\n\n /**\n * Media category, can be one of the {@link MediaCategory} values.\n */\n public get category(): MediaCategory {\n return this.state.category;\n }\n\n /**\n * Returns the direct content URL for the media.\n *\n * This URL is impermanent, it will expire in several minutes and cannot be cached.\n * If the URL becomes expired, you need to request a new one.\n * Each call to this function produces a new temporary URL.\n */\n public async getContentTemporaryUrl(): Promise<string | null> {\n await this._fetchMcsMedia();\n return this.mcsMedia?.getContentUrl() ?? null;\n }\n\n /**\n * Returns cached direct content URL for the media.\n *\n * This URL will expire in several minutes. This function does not refresh the URL and can be used to query it several times\n * without causing network traffic.\n * If the URL becomes expired, you need to request a new one using getContentTemporaryUrl().\n *\n * @returns {Promise<String>}\n */\n public async getCachedTemporaryUrl(): Promise<string | null> {\n await this._fetchMcsMedia();\n return this.mcsMedia?.getCachedContentUrl() ?? null;\n }\n\n private async _fetchMcsMedia() {\n if (!this.mcsMedia) {\n if (this.services.mcsClient) {\n this.mcsMedia = await this.services.mcsClient.get(this.state.sid);\n } else {\n throw new Error(\"Media Content Service is unavailable\");\n }\n }\n }\n}\n\nexport { Media, MediaState, MediaServices, MediaCategory };\n"],"names":["McsMedia"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA;;;AAGA,MAAM,KAAK;;;;IAQT,YAAY,IAA2B,EAAE,QAAuB;QALxD,aAAQ,GAAoB,IAAI,CAAC;QAMvC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,IAAI,IAAI,YAAYA,kBAAQ,EAAE;YAC5B,IAAI,CAAC,QAAQ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MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;aACzD;SACF;KACF;;;;;"}
@@ -204,16 +204,16 @@ class MessageBuilder {
204
204
  * @param payload Media to add.
205
205
  */
206
206
  addMedia(payload) {
207
- if (typeof FormData === 'undefined' && (payload instanceof FormData)) {
208
- throw new Error('Could not add FormData content whilst not in a browser');
207
+ if (typeof FormData === "undefined" && payload instanceof FormData) {
208
+ throw new Error("Could not add FormData content whilst not in a browser");
209
209
  }
210
210
  if (!(payload instanceof FormData)) {
211
211
  const mediaOptions = payload;
212
212
  if (!mediaOptions.contentType || !mediaOptions.media) {
213
- throw new Error('Media content in SendMediaOptions must contain non-empty contentType and media');
213
+ throw new Error("Media content in SendMediaOptions must contain non-empty contentType and media");
214
214
  }
215
215
  }
216
- this.message.mediaContent.push(['media', payload]);
216
+ this.message.mediaContent.push(["media", payload]);
217
217
  return this;
218
218
  }
219
219
  /**
@@ -233,7 +233,8 @@ class MessageBuilder {
233
233
  if (this.emailBodies.size > this.limits.emailBodiesAllowedMimeTypes.length) {
234
234
  throw new Error(`Too many email bodies attached to the message (${this.emailBodies.size} > ${this.limits.emailBodiesAllowedMimeTypes.length})`);
235
235
  }
236
- if (this.emailHistories.size > this.limits.emailHistoriesAllowedMimeTypes.length) {
236
+ if (this.emailHistories.size >
237
+ this.limits.emailHistoriesAllowedMimeTypes.length) {
237
238
  throw new Error(`Too many email histories attached to the message (${this.emailHistories.size} > ${this.limits.emailHistoriesAllowedMimeTypes.length})`);
238
239
  }
239
240
  if (this.message.mediaContent.length > this.limits.mediaAttachmentsCountLimit) {
@@ -242,16 +243,16 @@ class MessageBuilder {
242
243
  // @todo we don't know the sizes of the attachments in FormData
243
244
  // @todo insertion below makes build() method non-repeatable - probably move to UnsentMessage.send() or even sendV2()?
244
245
  this.emailBodies.forEach((body) => {
245
- this.message.mediaContent.push(['body', body]);
246
+ this.message.mediaContent.push(["body", body]);
246
247
  });
247
248
  this.emailHistories.forEach((history) => {
248
- this.message.mediaContent.push(['history', history]);
249
+ this.message.mediaContent.push(["history", history]);
249
250
  });
250
251
  return this.message;
251
252
  }
252
253
  getPayloadContentType(payload) {
253
- if (typeof FormData !== 'undefined' && (payload instanceof FormData)) {
254
- return payload.get('Content-Type');
254
+ if (typeof FormData !== "undefined" && payload instanceof FormData) {
255
+ return payload.get("Content-Type");
255
256
  }
256
257
  return payload.contentType;
257
258
  }
@@ -1 +1 @@
1
- {"version":3,"file":"message-builder.js","sources":["../src/message-builder.ts"],"sourcesContent":["import { Limits } from './interfaces/limits';\nimport { Conversation, SendMediaOptions } from './conversation';\nimport { UnsentMessage } from './unsent-message';\n\n/**\n * Message builder. Allows the message to be built and sent via method chaining.\n *\n * Example:\n *\n * ```ts\n * await testConversation.prepareMessage()\n * .setBody('Hello!')\n * .setAttributes({foo: 'bar'})\n * .addMedia(media1)\n * .addMedia(media2)\n * .build()\n * .send();\n * ```\n */\nclass MessageBuilder {\n private readonly message: UnsentMessage;\n private emailBodies: Map<string, FormData | SendMediaOptions>;\n private emailHistories: Map<string, FormData | SendMediaOptions>;\n\n /**\n * @internal\n */\n constructor(private readonly limits: Limits, messagesEntity: any) {\n this.message = new UnsentMessage(messagesEntity);\n this.emailBodies = new Map<string, FormData | SendMediaOptions>();\n this.emailHistories = new Map<string, FormData | SendMediaOptions>();\n }\n\n /**\n * Sets the message body.\n * @param text Contents of the body.\n */\n setBody(text: string): MessageBuilder {\n this.message.text = text;\n return this;\n }\n\n /**\n * Sets the message subject.\n * @param subject Contents of the subject.\n */\n setSubject(subject: string): MessageBuilder {\n this.message.emailOptions.subject = subject;\n return this;\n }\n\n /**\n * Sets the message attributes.\n * @param attributes Message attributes.\n */\n setAttributes(attributes: any): MessageBuilder {\n this.message.attributes = attributes;\n return this;\n }\n\n /**\n * Set email body with given MIME-type.\n * @param mimeType Format of the body to set (text/plain or text/html).\n * @param body Body payload in selected format.\n */\n setEmailBody(mimeType: string, body: FormData | SendMediaOptions): MessageBuilder {\n this.emailBodies.set(mimeType, body);\n return this;\n }\n\n /**\n * Set email history with given MIME-type.\n * @param mimeType Format of the history to set (text/plain or text/html).\n * @param history History payload in selected format.\n */\n setEmailHistory(mimeType: string, history: FormData | SendMediaOptions): MessageBuilder {\n this.emailHistories.set(mimeType, history);\n return this;\n }\n\n /**\n * Adds media to the message.\n * @param payload Media to add.\n */\n addMedia(payload: FormData | SendMediaOptions): MessageBuilder {\n if (typeof FormData === 'undefined' && (payload instanceof FormData)) {\n throw new Error('Could not add FormData content whilst not in a browser');\n }\n if (!(payload instanceof FormData)) {\n const mediaOptions = payload as SendMediaOptions;\n if (!mediaOptions.contentType || !mediaOptions.media) {\n throw new Error('Media content in SendMediaOptions must contain non-empty contentType and media');\n }\n }\n this.message.mediaContent.push(['media', payload]);\n return this;\n }\n\n /**\n * Builds the message, making it ready to be sent.\n */\n build(): UnsentMessage {\n this.emailBodies.forEach((_, key) => {\n if (!this.limits.emailBodiesAllowedMimeTypes.includes(key)) {\n throw new Error(`Unsupported email body MIME type ${key}`);\n }\n });\n this.emailHistories.forEach((_, key) => {\n if (!this.limits.emailHistoriesAllowedMimeTypes.includes(key)) {\n throw new Error(`Unsupported email history MIME type ${key}`);\n }\n });\n if (this.emailBodies.size > this.limits.emailBodiesAllowedMimeTypes.length) {\n throw new Error(`Too many email bodies attached to the message (${this.emailBodies.size} > ${this.limits.emailBodiesAllowedMimeTypes.length})`);\n }\n if (this.emailHistories.size > this.limits.emailHistoriesAllowedMimeTypes.length) {\n throw new Error(`Too many email histories attached to the message (${this.emailHistories.size} > ${this.limits.emailHistoriesAllowedMimeTypes.length})`);\n }\n\n if (this.message.mediaContent.length > this.limits.mediaAttachmentsCountLimit) {\n throw new Error(`Too many media attachments in the message (${this.message.mediaContent.length} > ${this.limits.mediaAttachmentsCountLimit})`);\n }\n\n // @todo we don't know the sizes of the attachments in FormData\n // @todo insertion below makes build() method non-repeatable - probably move to UnsentMessage.send() or even sendV2()?\n\n this.emailBodies.forEach((body) => {\n this.message.mediaContent.push(['body', body]);\n });\n\n this.emailHistories.forEach((history) => {\n this.message.mediaContent.push(['history', history]);\n });\n\n return this.message;\n }\n\n private getPayloadContentType(payload: FormData | SendMediaOptions): string {\n if (typeof FormData !== 'undefined' && (payload instanceof FormData)) {\n return payload.get('Content-Type') as string;\n }\n return (payload as SendMediaOptions).contentType;\n }\n}\n\nexport { MessageBuilder };\n"],"names":["UnsentMessage"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA;;;;;;;;;;;;;;;AAeA,MAAM,cAAc;;;;IAQlB,YAA6B,MAAc,EAAE,cAAmB;QAAnC,WAAM,GAAN,MAAM,CAAQ;QACzC,IAAI,CAAC,OAAO,GAAG,IAAIA,2BAAa,CAAC,cAAc,CAAC,CAAC;QACjD,IAAI,CAAC,WAAW,GAAG,IAAI,GAAG,EAAuC,CAAC;QAClE,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,EAAuC,CAAC;KACtE;;;;;IAMD,OAAO,CAAC,IAAY;QAClB,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;QACzB,OAAO,IAAI,CAAC;KACb;;;;;IAMD,UAAU,CAAC,OAAe;QACxB,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,GAAG,OAAO,CAAC;QAC5C,OAAO,IAAI,CAAC;KACb;;;;;IAMD,aAAa,CAAC,UAAe;QAC3B,IAAI,CAAC,OAAO,CAAC,UAAU,GAAG,UAAU,CAAC;QACrC,OAAO,IAAI,CAAC;KACb;;;;;;IAOD,YAAY,CAAC,QAAgB,EAAE,IAAiC;QAC9D,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACrC,OAAO,IAAI,CAAC;KACb;;;;;;IAOD,eAAe,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
1
+ {"version":3,"file":"message-builder.js","sources":["../src/message-builder.ts"],"sourcesContent":["import { ConversationLimits } from \"./interfaces/conversation-limits\";\nimport { SendMediaOptions } from \"./conversation\";\nimport { UnsentMessage } from \"./unsent-message\";\nimport { JSONValue } from \"./types\";\nimport { Messages } from \"./data/messages\";\n\n/**\n * Message builder. Allows the message to be built and sent via method chaining.\n *\n * Example:\n *\n * ```ts\n * await testConversation.prepareMessage()\n * .setBody('Hello!')\n * .setAttributes({foo: 'bar'})\n * .addMedia(media1)\n * .addMedia(media2)\n * .build()\n * .send();\n * ```\n */\nclass MessageBuilder {\n private readonly message: UnsentMessage;\n private emailBodies: Map<string, FormData | SendMediaOptions>;\n private emailHistories: Map<string, FormData | SendMediaOptions>;\n\n /**\n * @internal\n */\n constructor(\n private readonly limits: ConversationLimits,\n messagesEntity: Messages\n ) {\n this.message = new UnsentMessage(messagesEntity);\n this.emailBodies = new Map<string, FormData | SendMediaOptions>();\n this.emailHistories = new Map<string, FormData | SendMediaOptions>();\n }\n\n /**\n * Sets the message body.\n * @param text Contents of the body.\n */\n setBody(text: string): MessageBuilder {\n this.message.text = text;\n return this;\n }\n\n /**\n * Sets the message subject.\n * @param subject Contents of the subject.\n */\n setSubject(subject: string): MessageBuilder {\n this.message.emailOptions.subject = subject;\n return this;\n }\n\n /**\n * Sets the message attributes.\n * @param attributes Message attributes.\n */\n setAttributes(attributes: JSONValue): MessageBuilder {\n this.message.attributes = attributes;\n return this;\n }\n\n /**\n * Set email body with given MIME-type.\n * @param mimeType Format of the body to set (text/plain or text/html).\n * @param body Body payload in selected format.\n */\n setEmailBody(\n mimeType: string,\n body: FormData | SendMediaOptions\n ): MessageBuilder {\n this.emailBodies.set(mimeType, body);\n return this;\n }\n\n /**\n * Set email history with given MIME-type.\n * @param mimeType Format of the history to set (text/plain or text/html).\n * @param history History payload in selected format.\n */\n setEmailHistory(\n mimeType: string,\n history: FormData | SendMediaOptions\n ): MessageBuilder {\n this.emailHistories.set(mimeType, history);\n return this;\n }\n\n /**\n * Adds media to the message.\n * @param payload Media to add.\n */\n addMedia(payload: FormData | SendMediaOptions): MessageBuilder {\n if (typeof FormData === \"undefined\" && payload instanceof FormData) {\n throw new Error(\"Could not add FormData content whilst not in a browser\");\n }\n if (!(payload instanceof FormData)) {\n const mediaOptions = payload as SendMediaOptions;\n if (!mediaOptions.contentType || !mediaOptions.media) {\n throw new Error(\n \"Media content in SendMediaOptions must contain non-empty contentType and media\"\n );\n }\n }\n this.message.mediaContent.push([\"media\", payload]);\n return this;\n }\n\n /**\n * Builds the message, making it ready to be sent.\n */\n build(): UnsentMessage {\n this.emailBodies.forEach((_, key) => {\n if (!this.limits.emailBodiesAllowedMimeTypes.includes(key)) {\n throw new Error(`Unsupported email body MIME type ${key}`);\n }\n });\n this.emailHistories.forEach((_, key) => {\n if (!this.limits.emailHistoriesAllowedMimeTypes.includes(key)) {\n throw new Error(`Unsupported email history MIME type ${key}`);\n }\n });\n if (\n this.emailBodies.size > this.limits.emailBodiesAllowedMimeTypes.length\n ) {\n throw new Error(\n `Too many email bodies attached to the message (${this.emailBodies.size} > ${this.limits.emailBodiesAllowedMimeTypes.length})`\n );\n }\n if (\n this.emailHistories.size >\n this.limits.emailHistoriesAllowedMimeTypes.length\n ) {\n throw new Error(\n `Too many email histories attached to the message (${this.emailHistories.size} > ${this.limits.emailHistoriesAllowedMimeTypes.length})`\n );\n }\n\n if (\n this.message.mediaContent.length > this.limits.mediaAttachmentsCountLimit\n ) {\n throw new Error(\n `Too many media attachments in the message (${this.message.mediaContent.length} > ${this.limits.mediaAttachmentsCountLimit})`\n );\n }\n\n // @todo we don't know the sizes of the attachments in FormData\n // @todo insertion below makes build() method non-repeatable - probably move to UnsentMessage.send() or even sendV2()?\n\n this.emailBodies.forEach((body) => {\n this.message.mediaContent.push([\"body\", body]);\n });\n\n this.emailHistories.forEach((history) => {\n this.message.mediaContent.push([\"history\", history]);\n });\n\n return this.message;\n }\n\n private getPayloadContentType(\n payload: FormData | SendMediaOptions\n ): string | null {\n if (typeof FormData !== \"undefined\" && payload instanceof FormData) {\n return payload.get(\"Content-Type\") as string;\n }\n return (payload as SendMediaOptions).contentType;\n }\n}\n\nexport { MessageBuilder };\n"],"names":["UnsentMessage"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA;;;;;;;;;;;;;;;AAeA,MAAM,cAAc;;;;IAQlB,YACmB,MAA0B,EAC3C,cAAwB;QADP,WAAM,GAAN,MAAM,CAAoB;QAG3C,IAAI,CAAC,OAAO,GAAG,IAAIA,2BAAa,CAAC,cAAc,CAAC,CAAC;QACjD,IAAI,CAAC,WAAW,GAAG,IAAI,GAAG,EAAuC,CAAC;QAClE,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,EAAuC,CAAC;KACtE;;;;;IAMD,OAAO,CAAC,IAAY;QAClB,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;QACzB,OAAO,IAAI,CAAC;KACb;;;;;IAMD,UAAU,CAAC,OAAe;QACxB,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,GAAG,OAAO,CAAC;QAC5C,OAAO,IAAI,CAAC;KACb;;;;;IAMD,aAAa,CAAC,UAAqB;QACjC,IAAI,CAAC,OAAO,CAAC,UAAU,GAAG,UAAU,CAAC;QACrC,OAAO,IAAI,CAAC;KACb;;;;;;IAOD,YAAY,CACV,QAAgB,EAChB,IAAiC;QAEjC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACrC,OAAO,IAAI,CAAC;KACb;;;;;;IAOD,eAAe,CACb,QAAgB,EAChB,OAAoC;QAEpC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QA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