@twilio/conversations 2.1.0-rc.1 → 2.1.0-rc.5
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.
- package/CHANGELOG.md +34 -0
- package/NOTICE.txt +679 -0
- package/builds/browser.js +676 -587
- package/builds/browser.js.map +1 -1
- package/builds/lib.d.ts +287 -117
- package/builds/lib.js +676 -587
- package/builds/lib.js.map +1 -1
- package/builds/twilio-conversations.js +854 -909
- package/builds/twilio-conversations.min.js +2 -14
- package/dist/aggregated-delivery-receipt.js +6 -1
- package/dist/aggregated-delivery-receipt.js.map +1 -1
- package/dist/client.js +165 -142
- package/dist/client.js.map +1 -1
- package/dist/command-executor.js +16 -14
- package/dist/command-executor.js.map +1 -1
- package/dist/configuration.js +14 -10
- package/dist/configuration.js.map +1 -1
- package/dist/conversation.js +212 -153
- package/dist/conversation.js.map +1 -1
- package/dist/data/conversations.js +81 -77
- package/dist/data/conversations.js.map +1 -1
- package/dist/data/messages.js +42 -38
- package/dist/data/messages.js.map +1 -1
- package/dist/data/participants.js +93 -75
- package/dist/data/participants.js.map +1 -1
- package/dist/data/users.js +24 -22
- package/dist/data/users.js.map +1 -1
- package/dist/detailed-delivery-receipt.js +1 -1
- package/dist/detailed-delivery-receipt.js.map +1 -1
- package/dist/interfaces/attributes.js +4 -4
- package/dist/interfaces/attributes.js.map +1 -1
- package/dist/interfaces/notification-types.js +5 -5
- package/dist/interfaces/notification-types.js.map +1 -1
- package/dist/logger.js +36 -15
- package/dist/logger.js.map +1 -1
- package/dist/media.js +21 -9
- package/dist/media.js.map +1 -1
- package/dist/message-builder.js +10 -9
- package/dist/message-builder.js.map +1 -1
- package/dist/message.js +130 -81
- package/dist/message.js.map +1 -1
- package/dist/packages/conversations/package.json.js +1 -1
- package/dist/participant.js +85 -51
- package/dist/participant.js.map +1 -1
- package/dist/push-notification.js.map +1 -1
- package/dist/rest-paginator.js +16 -6
- package/dist/rest-paginator.js.map +1 -1
- package/dist/services/network.js +18 -14
- package/dist/services/network.js.map +1 -1
- package/dist/services/typing-indicator.js +20 -17
- package/dist/services/typing-indicator.js.map +1 -1
- package/dist/unsent-message.js.map +1 -1
- package/dist/user.js +85 -59
- package/dist/user.js.map +1 -1
- package/dist/util/deferred.js +3 -1
- package/dist/util/deferred.js.map +1 -1
- package/dist/util/index.js +6 -6
- package/dist/util/index.js.map +1 -1
- package/docs/classes/Client.html +24 -30
- package/docs/classes/Conversation.html +30 -30
- package/docs/classes/DetailedDeliveryReceipt.html +1 -1
- package/docs/classes/Message.html +7 -7
- package/docs/classes/MessageBuilder.html +2 -2
- package/docs/classes/Participant.html +7 -7
- package/docs/classes/User.html +7 -7
- package/docs/interfaces/CreateConversationOptions.html +1 -1
- package/package.json +23 -17
package/dist/data/users.js
CHANGED
@@ -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(
|
148
|
-
this.myself.on(
|
149
|
-
this.myself.on(
|
150
|
-
this.emit(
|
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 =
|
160
|
-
|
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(
|
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.
|
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(
|
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 =
|
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
|
-
|
194
|
-
if (
|
195
|
-
|
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
|
-
|
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
|
|
package/dist/data/users.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"users.js","sources":["../../src/data/users.ts"],"sourcesContent":["import { User, UserUpdatedEventArgs, UserUpdateReason } from
|
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,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;QACpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC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,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 ||
|
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 |
|
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
|
-
[
|
138
|
-
|
137
|
+
["string", "number", "boolean", "object"].includes(typeof value),
|
138
|
+
"a JSON type",
|
139
139
|
]);
|
140
140
|
const optionalAttributesValidator = declarativeTypeValidator.custom((value) => [
|
141
|
-
[
|
142
|
-
|
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
|
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 =
|
136
|
-
NotificationTypes.NEW_MESSAGE =
|
137
|
-
NotificationTypes.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 =
|
140
|
-
NotificationTypes.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 =
|
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(
|
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 =
|
165
|
-
|
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) {
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
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;
|
package/dist/logger.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"logger.js","sources":["../src/logger.ts"],"sourcesContent":["import * as loglevelLog from
|
1
|
+
{"version":3,"file":"logger.js","sources":["../src/logger.ts"],"sourcesContent":["import * as 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,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,kBAAkB,MAAM,GAAG,CAAC,CAAC,MAAM,CACpE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CACjB,CAAC;AACJ,CAAC;AAED,MAAM,GAAG,GAAuBA,sBAAW,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAC;AAE9E,MAAM,MAAM;IAGV,YAAoB,MAAc;QAF1B,WAAM,GAAG,EAAE,CAAC;QAGlB,IAAI,CAAC,MAAM;YACT,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;kBACxD,MAAM,GAAG,GAAG;kBACZ,EAAE,CAAC;KACV;IAED,OAAO,KAAK,CAAC,MAAc;QACzB,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC;KAC3B;IAED,QAAQ,CAAC,KAAmB;QAC1B,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;KACrB;IAED,OAAO,QAAQ,CAAC,KAAmB;QACjC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;KACrB;IAED,KAAK,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,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() {
|
159
|
+
get sid() {
|
160
|
+
return this.state.sid;
|
161
|
+
}
|
160
162
|
/**
|
161
163
|
* File name. Null if absent.
|
162
164
|
*/
|
163
|
-
get filename() {
|
165
|
+
get filename() {
|
166
|
+
return this.state.filename;
|
167
|
+
}
|
164
168
|
/**
|
165
169
|
* Content type of the media.
|
166
170
|
*/
|
167
|
-
get 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() {
|
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() {
|
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(
|
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
|
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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CAAC;KACrD;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;;;;;"}
|
package/dist/message-builder.js
CHANGED
@@ -204,16 +204,16 @@ class MessageBuilder {
|
|
204
204
|
* @param payload Media to add.
|
205
205
|
*/
|
206
206
|
addMedia(payload) {
|
207
|
-
if (typeof FormData ===
|
208
|
-
throw new Error(
|
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(
|
213
|
+
throw new Error("Media content in SendMediaOptions must contain non-empty contentType and media");
|
214
214
|
}
|
215
215
|
}
|
216
|
-
this.message.mediaContent.push([
|
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 >
|
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([
|
246
|
+
this.message.mediaContent.push(["body", body]);
|
246
247
|
});
|
247
248
|
this.emailHistories.forEach((history) => {
|
248
|
-
this.message.mediaContent.push([
|
249
|
+
this.message.mediaContent.push(["history", history]);
|
249
250
|
});
|
250
251
|
return this.message;
|
251
252
|
}
|
252
253
|
getPayloadContentType(payload) {
|
253
|
-
if (typeof FormData !==
|
254
|
-
return payload.get(
|
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
|
1
|
+
{"version":3,"file":"message-builder.js","sources":["../src/message-builder.ts"],"sourcesContent":["import { Limits } from \"./interfaces/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(private readonly limits: Limits, messagesEntity: Messages) {\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,YAA6B,MAAc,EAAE,cAAwB;QAAxC,WAAM,GAAN,MAAM,CAAQ;QACzC,IAAI,CAAC,OAAO,GAAG,IAAIA,2BAAa,CAAC,cAAc,CAAC,CAAC;QACjD,IAAI,CAAC,WAAW,GAAG,IAAI,GAAG,EAAuC,C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