@twilio/conversations 3.0.0-rc.9 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/README.md +39 -29
  2. package/builds/browser.esm.js +10838 -0
  3. package/builds/browser.esm.js.map +1 -0
  4. package/builds/browser.js +2494 -476
  5. package/builds/browser.js.map +1 -1
  6. package/builds/lib.d.ts +805 -70
  7. package/builds/lib.esm.d.ts +3178 -0
  8. package/builds/lib.esm.js +10837 -0
  9. package/builds/lib.js +2494 -476
  10. package/builds/lib.js.map +1 -1
  11. package/builds/twilio-conversations.js +29167 -26611
  12. package/builds/twilio-conversations.js.map +1 -0
  13. package/builds/twilio-conversations.min.js +2 -1
  14. package/builds/twilio-conversations.min.js.map +1 -0
  15. package/dist/aggregated-delivery-receipt.js +10 -5
  16. package/dist/aggregated-delivery-receipt.js.map +1 -1
  17. package/dist/channel-metadata-client.js +187 -0
  18. package/dist/channel-metadata-client.js.map +1 -0
  19. package/dist/client.js +266 -192
  20. package/dist/client.js.map +1 -1
  21. package/dist/command-executor.js +51 -14
  22. package/dist/command-executor.js.map +1 -1
  23. package/dist/configuration.js +23 -12
  24. package/dist/configuration.js.map +1 -1
  25. package/dist/content-client.js +180 -0
  26. package/dist/content-client.js.map +1 -0
  27. package/dist/content-template.js +304 -0
  28. package/dist/content-template.js.map +1 -0
  29. package/dist/conversation.js +213 -134
  30. package/dist/conversation.js.map +1 -1
  31. package/dist/data/conversations.js +70 -50
  32. package/dist/data/conversations.js.map +1 -1
  33. package/dist/data/messages.js +40 -27
  34. package/dist/data/messages.js.map +1 -1
  35. package/dist/data/participants.js +38 -32
  36. package/dist/data/participants.js.map +1 -1
  37. package/dist/data/users.js +19 -14
  38. package/dist/data/users.js.map +1 -1
  39. package/dist/detailed-delivery-receipt.js +9 -4
  40. package/dist/detailed-delivery-receipt.js.map +1 -1
  41. package/dist/index.js +26 -41
  42. package/dist/index.js.map +1 -1
  43. package/dist/interfaces/notification-types.js +9 -4
  44. package/dist/interfaces/notification-types.js.map +1 -1
  45. package/dist/interfaces/{attributes.js → rules.js} +26 -13
  46. package/dist/interfaces/rules.js.map +1 -0
  47. package/dist/logger.js +17 -28
  48. package/dist/logger.js.map +1 -1
  49. package/dist/media.js +40 -24
  50. package/dist/media.js.map +1 -1
  51. package/dist/message-builder.js +79 -12
  52. package/dist/message-builder.js.map +1 -1
  53. package/dist/message-recipients-client.js +231 -0
  54. package/dist/message-recipients-client.js.map +1 -0
  55. package/dist/message.js +258 -92
  56. package/dist/message.js.map +1 -1
  57. package/dist/node_modules/quick-lru/index.js +261 -0
  58. package/dist/node_modules/quick-lru/index.js.map +1 -0
  59. package/dist/node_modules/tslib/tslib.es6.js +15 -5
  60. package/dist/node_modules/tslib/tslib.es6.js.map +1 -1
  61. package/dist/packages/conversations/package.json.js +12 -7
  62. package/dist/packages/conversations/package.json.js.map +1 -1
  63. package/dist/participant.js +42 -38
  64. package/dist/participant.js.map +1 -1
  65. package/dist/push-notification.js +9 -4
  66. package/dist/push-notification.js.map +1 -1
  67. package/dist/rest-paginator.js +9 -4
  68. package/dist/rest-paginator.js.map +1 -1
  69. package/dist/services/network.js +11 -6
  70. package/dist/services/network.js.map +1 -1
  71. package/dist/services/typing-indicator.js +17 -11
  72. package/dist/services/typing-indicator.js.map +1 -1
  73. package/dist/unsent-message.js +14 -9
  74. package/dist/unsent-message.js.map +1 -1
  75. package/dist/user.js +40 -32
  76. package/dist/user.js.map +1 -1
  77. package/dist/util/deferred.js +9 -4
  78. package/dist/util/deferred.js.map +1 -1
  79. package/dist/util/index.js +44 -8
  80. package/dist/util/index.js.map +1 -1
  81. package/docs/assets/js/search.js +1 -1
  82. package/docs/classes/AggregatedDeliveryReceipt.html +1 -1
  83. package/docs/classes/ChannelMetadata.html +3050 -0
  84. package/docs/classes/Client.html +98 -27
  85. package/docs/classes/ContentTemplate.html +3116 -0
  86. package/docs/classes/ContentTemplateVariable.html +3116 -0
  87. package/docs/classes/Conversation.html +46 -9
  88. package/docs/classes/EmailRecipientDescriptor.html +3098 -0
  89. package/docs/classes/Message.html +99 -5
  90. package/docs/classes/MessageBuilder.html +41 -0
  91. package/docs/classes/Participant.html +2 -2
  92. package/docs/classes/UnknownRecipientDescriptor.html +3067 -0
  93. package/docs/index.html +892 -28
  94. package/docs/interfaces/ClientOptions.html +32 -0
  95. package/docs/interfaces/CreateConversationOptions.html +17 -0
  96. package/docs/modules.html +891 -27
  97. package/package.json +21 -19
  98. package/CHANGELOG.md +0 -509
  99. package/dist/interfaces/attributes.js.map +0 -1
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 CancellablePromise,\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 getContentTemporaryUrl(): CancellablePromise<string | null> {\n return new CancellablePromise(async (resolve, reject, onCancel) => {\n const fetchMediaRequest = this._fetchMcsMedia();\n let contentUrlRequest = this.mcsMedia?.getContentUrl();\n\n onCancel(() => {\n fetchMediaRequest.cancel();\n if (contentUrlRequest) {\n contentUrlRequest.cancel();\n }\n });\n\n try {\n if (!this.mcsMedia) {\n const mcsMedia = await fetchMediaRequest;\n contentUrlRequest = mcsMedia.getContentUrl();\n }\n resolve(contentUrlRequest ? await contentUrlRequest : null);\n } catch (e) {\n reject(e);\n }\n });\n }\n\n private _fetchMcsMedia(): CancellablePromise<McsMedia> {\n return new CancellablePromise(async (resolve, reject, onCancel) => {\n const request = this.services.mcsClient.get(this.state.sid);\n if (this.services.mcsClient) {\n onCancel(() => request.cancel());\n\n try {\n this.mcsMedia = await request;\n resolve(this.mcsMedia);\n } catch (e) {\n reject(e);\n }\n return;\n }\n\n reject(new Error(\"Media Content Service is unavailable\"));\n });\n }\n}\n\nexport { Media, MediaState, MediaServices, MediaCategory };\n"],"names":["McsMedia","CancellablePromise"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA;;AAEG;AACH,MAAM,KAAK,CAAA;AAKT;;AAEG;IACH,WAAY,CAAA,IAA2B,EAAE,QAAuB,EAAA;QALxD,IAAQ,CAAA,QAAA,GAAoB,IAAI,CAAC;AAMvC,QAAA,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,IAAI,IAAI,YAAYA,kBAAQ,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McsMedia,\n McsMediaCategory,\n McsMediaState,\n CancellablePromise,\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 MediaServices {\n mcsClient: McsClient;\n}\n\n/**\n * Represents a media information for a message in a conversation.\n */\nclass Media {\n private state: McsMediaState;\n private services: MediaServices;\n private mcsMedia: McsMedia | null = null;\n\n /**\n * @internal\n */\n constructor(data: McsMediaState | 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 ?? null,\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 getContentTemporaryUrl(): CancellablePromise<string | null> {\n return new CancellablePromise(async (resolve, reject, onCancel) => {\n const fetchMediaRequest = this.mcsMedia\n ? undefined\n : this._fetchMcsMedia();\n let contentUrlRequest = this.mcsMedia?.getContentUrl();\n\n onCancel(() => {\n if (fetchMediaRequest) {\n fetchMediaRequest.cancel();\n }\n if (contentUrlRequest) {\n contentUrlRequest.cancel();\n }\n });\n\n try {\n if (!contentUrlRequest) {\n const mcsMedia = await fetchMediaRequest;\n contentUrlRequest = mcsMedia?.getContentUrl();\n }\n resolve(contentUrlRequest ? await contentUrlRequest : null);\n } catch (e) {\n reject(e);\n }\n });\n }\n\n private _fetchMcsMedia(): CancellablePromise<McsMedia> {\n return new CancellablePromise(async (resolve, reject, onCancel) => {\n if (this.services.mcsClient === null) {\n reject(new Error(\"Media Content Service is unavailable\"));\n }\n\n const request = this.services.mcsClient.get(this.state.sid);\n onCancel(() => request.cancel());\n\n try {\n this.mcsMedia = await request;\n this.state = this.mcsMedia._state();\n resolve(this.mcsMedia);\n } catch (e) {\n reject(e);\n }\n });\n }\n\n /**\n * @internal\n */\n _state(): McsMediaState {\n return this.state;\n }\n}\n\nexport { Media, MediaServices, MediaCategory };\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA;;AAEG;AACH,MAAM,KAAK,CAAA;AAKT;;AAEG;IACH,WAAY,CAAA,IAA8B,EAAE,QAAuB,EAAA;;QAL3D,IAAQ,CAAA,QAAA,GAAoB,IAAI,CAAC;AAMvC,QAAA,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,IAAI,IAAI,YAAY,QAAQ,EAAE;AAC5B,YAAA,IAAI,CAAC,QAAQ,GAAG,IAAgB,CAAC;AAClC,SAAA;QAED,IAAI,CAAC,KAAK,GAAG;YACX,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,QAAQ,EAAE,IAAI,CAAC,QAAQ;AACvB,YAAA,QAAQ,EAAE,CAAA,EAAA,GAAA,IAAI,CAAC,QAAQ,mCAAI,IAAI;YAC/B,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC;KACH;AAED;;AAEG;AACH,IAAA,IAAW,GAAG,GAAA;AACZ,QAAA,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,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,iBAAA;AACD,gBAAA,OAAO,CAAC,iBAAiB,GAAG,MAAM,iBAAiB,GAAG,IAAI,CAAC,CAAC;AAC7D,aAAA;AAAC,YAAA,OAAO,CAAC,EAAE;gBACV,MAAM,CAAC,CAAC,CAAC,CAAC;AACX,aAAA;AACH,SAAC,CAAC,CAAC;KACJ;IAEO,cAAc,GAAA;QACpB,OAAO,IAAI,kBAAkB,CAAC,OAAO,OAAO,EAAE,MAAM,EAAE,QAAQ,KAAI;AAChE,YAAA,IAAI,IAAI,CAAC,QAAQ,CAAC,SAAS,KAAK,IAAI,EAAE;AACpC,gBAAA,MAAM,CAAC,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC,CAAC;AAC3D,aAAA;AAED,YAAA,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC5D,QAAQ,CAAC,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;YAEjC,IAAI;AACF,gBAAA,IAAI,CAAC,QAAQ,GAAG,MAAM,OAAO,CAAC;gBAC9B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;AACpC,gBAAA,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACxB,aAAA;AAAC,YAAA,OAAO,CAAC,EAAE;gBACV,MAAM,CAAC,CAAC,CAAC,CAAC;AACX,aAAA;AACH,SAAC,CAAC,CAAC;KACJ;AAED;;AAEG;IACH,MAAM,GAAA;QACJ,OAAO,IAAI,CAAC,KAAK,CAAC;KACnB;AACF;;;;"}
@@ -126,11 +126,20 @@ This software includes platform.js under the following license.
126
126
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
127
127
 
128
128
  */
129
- 'use strict';
129
+ var global =
130
+ typeof global !== "undefined"
131
+ ? global
132
+ : typeof self !== "undefined"
133
+ ? self
134
+ : typeof window !== "undefined"
135
+ ? window
136
+ : {};
130
137
 
131
- Object.defineProperty(exports, '__esModule', { value: true });
132
-
133
- var unsentMessage = require('./unsent-message.js');
138
+ import { __decorate, __metadata } from './node_modules/tslib/tslib.es6.js';
139
+ import { UnsentMessage } from './unsent-message.js';
140
+ import { ContentTemplateVariable } from './content-template.js';
141
+ import { validateTypes, array } from '@twilio/declarative-type-validator';
142
+ import { json, sendMediaOptions } from './interfaces/rules.js';
134
143
 
135
144
  /**
136
145
  * Message builder. Allows the message to be built and sent via method chaining.
@@ -153,7 +162,7 @@ class MessageBuilder {
153
162
  */
154
163
  constructor(limits, messagesEntity) {
155
164
  this.limits = limits;
156
- this.message = new unsentMessage.UnsentMessage(messagesEntity);
165
+ this.message = new UnsentMessage(messagesEntity);
157
166
  this.emailBodies = new Map();
158
167
  this.emailHistories = new Map();
159
168
  }
@@ -199,6 +208,25 @@ class MessageBuilder {
199
208
  this.emailHistories.set(contentType, history);
200
209
  return this;
201
210
  }
211
+ /**
212
+ * Adds {@link ContentTemplate} SID for the message alongside optional
213
+ * variables. When no variables provided, the default values will be used.
214
+ *
215
+ * Adding the content SID converts the message to a rich message. In this
216
+ * case, other fields are ignored and the message is sent using the content
217
+ * from the the {@link ContentTemplate}.
218
+ *
219
+ * Use {@link Client.getContentTemplates} to request all available
220
+ * {@link ContentTemplate}s.
221
+ *
222
+ * @param contentSid SID of the {@link ContentTemplate}
223
+ * @param variables Custom variables to resolve the template.
224
+ */
225
+ setContentTemplate(contentSid, contentVariables = []) {
226
+ this.message.contentSid = contentSid;
227
+ this.message.contentVariables = contentVariables;
228
+ return this;
229
+ }
202
230
  /**
203
231
  * Adds media to the message.
204
232
  * @param payload Media to add.
@@ -256,13 +284,52 @@ class MessageBuilder {
256
284
  buildAndSend() {
257
285
  return this.build().send();
258
286
  }
259
- getPayloadContentType(payload) {
260
- if (typeof FormData !== "undefined" && payload instanceof FormData) {
261
- return payload.get("Content-Type");
262
- }
263
- return payload.contentType;
264
- }
265
287
  }
288
+ __decorate([
289
+ validateTypes("string"),
290
+ __metadata("design:type", Function),
291
+ __metadata("design:paramtypes", [String]),
292
+ __metadata("design:returntype", MessageBuilder)
293
+ ], MessageBuilder.prototype, "setBody", null);
294
+ __decorate([
295
+ validateTypes("string"),
296
+ __metadata("design:type", Function),
297
+ __metadata("design:paramtypes", [String]),
298
+ __metadata("design:returntype", MessageBuilder)
299
+ ], MessageBuilder.prototype, "setSubject", null);
300
+ __decorate([
301
+ validateTypes(json),
302
+ __metadata("design:type", Function),
303
+ __metadata("design:paramtypes", [Object]),
304
+ __metadata("design:returntype", MessageBuilder)
305
+ ], MessageBuilder.prototype, "setAttributes", null);
306
+ __decorate([
307
+ validateTypes("string", [FormData, sendMediaOptions]),
308
+ __metadata("design:type", Function),
309
+ __metadata("design:paramtypes", [String, Object]),
310
+ __metadata("design:returntype", MessageBuilder)
311
+ ], MessageBuilder.prototype, "setEmailBody", null);
312
+ __decorate([
313
+ validateTypes("string", [FormData, sendMediaOptions]),
314
+ __metadata("design:type", Function),
315
+ __metadata("design:paramtypes", [String, Object]),
316
+ __metadata("design:returntype", MessageBuilder)
317
+ ], MessageBuilder.prototype, "setEmailHistory", null);
318
+ __decorate([
319
+ validateTypes("string", [
320
+ array("content variables", ContentTemplateVariable),
321
+ "undefined",
322
+ ]),
323
+ __metadata("design:type", Function),
324
+ __metadata("design:paramtypes", [String, Array]),
325
+ __metadata("design:returntype", MessageBuilder)
326
+ ], MessageBuilder.prototype, "setContentTemplate", null);
327
+ __decorate([
328
+ validateTypes([FormData, sendMediaOptions]),
329
+ __metadata("design:type", Function),
330
+ __metadata("design:paramtypes", [Object]),
331
+ __metadata("design:returntype", MessageBuilder)
332
+ ], MessageBuilder.prototype, "addMedia", null);
266
333
 
267
- exports.MessageBuilder = MessageBuilder;
334
+ export { MessageBuilder };
268
335
  //# sourceMappingURL=message-builder.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"message-builder.js","sources":["../src/message-builder.ts"],"sourcesContent":["import { CancellablePromise } from \"@twilio/mcs-client\";\nimport { 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 the email body with a given content type.\n * @param contentType Format of the body to set (text/plain or text/html).\n * @param body Body payload in the selected format.\n */\n setEmailBody(\n contentType: string,\n body: FormData | SendMediaOptions\n ): MessageBuilder {\n this.emailBodies.set(contentType, body);\n return this;\n }\n\n /**\n * Set the email history with a given content type.\n * @param contentType Format of the history to set (text/plain or text/html).\n * @param history History payload in the selected format.\n */\n setEmailHistory(\n contentType: string,\n history: FormData | SendMediaOptions\n ): MessageBuilder {\n this.emailHistories.set(contentType, 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.emailBodiesAllowedContentTypes.includes(key)) {\n throw new Error(`Unsupported email body content type ${key}`);\n }\n });\n this.emailHistories.forEach((_, key) => {\n if (!this.limits.emailHistoriesAllowedContentTypes.includes(key)) {\n throw new Error(`Unsupported email history content type ${key}`);\n }\n });\n if (\n this.emailBodies.size > this.limits.emailBodiesAllowedContentTypes.length\n ) {\n throw new Error(\n `Too many email bodies attached to the message (${this.emailBodies.size} > ${this.limits.emailBodiesAllowedContentTypes.length})`\n );\n }\n if (\n this.emailHistories.size >\n this.limits.emailHistoriesAllowedContentTypes.length\n ) {\n throw new Error(\n `Too many email histories attached to the message (${this.emailHistories.size} > ${this.limits.emailHistoriesAllowedContentTypes.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 /**\n * Prepares a message and sends it to the conversation.\n */\n buildAndSend(): CancellablePromise<number | null> {\n return this.build().send();\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA;;;;;;;;;;;;;;AAcG;AACH,MAAM,cAAc,CAAA;AAKlB;;AAEG;IACH,WACmB,CAAA,MAA0B,EAC3C,cAAwB,EAAA;QADP,IAAM,CAAA,MAAA,GAAN,MAAM,CAAoB;QAG3C,IAAI,CAAC,OAAO,GAAG,IAAIA,2BAAa,CAAC,cAAc,CAAC,CAAC;AACjD,QAAA,IAAI,CAAC,WAAW,GAAG,IAAI,GAAG,EAAuC,CAAC;AAClE,QAAA,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,EAAuC,CAAC;KACtE;AAED;;;AAGG;AACH,IAAA,OAAO,CAAC,IAAY,EAAA;AAClB,QAAA,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;AACzB,QAAA,OAAO,IAAI,CAAC;KACb;AAED;;;AAGG;AACH,IAAA,UAAU,CAAC,OAAe,EAAA;QACxB,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,GAAG,OAAO,CAAC;AAC5C,QAAA,OAAO,IAAI,CAAC;KACb;AAED;;;AAGG;AACH,IAAA,aAAa,CAAC,UAAqB,EAAA;AACjC,QAAA,IAAI,CAAC,OAAO,CAAC,UAAU,GAAG,UAAU,CAAC;AACrC,QAAA,OAAO,IAAI,CAAC;KACb;AAED;;;;AAIG;IACH,YAAY,CACV,WAAmB,EACnB,IAAiC,EAAA;QAEjC,IAAI,CAAC,WAAW,CAAC,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I,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;AACvD,SAAC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,OAAO,CAAC;KACrB;AAED;;AAEG;IACH,YAAY,GAAA;AACV,QAAA,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC;KAC5B;AAEO,IAAA,qBAAqB,CAC3B,OAAoC,EAAA;QAEpC,IAAI,OAAO,QAAQ,KAAK,WAAW,IAAI,OAAO,YAAY,QAAQ,EAAE;AAClE,YAAA,OAAO,OAAO,CAAC,GAAG,CAAC,cAAc,CAAW,CAAC;AAC9C,SAAA;QACD,OAAQ,OAA4B,CAAC,WAAW,CAAC;KAClD;AACF;;;;"}
1
+ {"version":3,"file":"message-builder.js","sources":["../src/message-builder.ts"],"sourcesContent":["import { CancellablePromise } from \"@twilio/mcs-client\";\nimport { ConversationLimits } from \"./interfaces/conversation-limits\";\nimport { SendMediaOptions } from \"./conversation\";\nimport { UnsentMessage } from \"./unsent-message\";\nimport { JSONValue } from \"./types\";\nimport { Messages } from \"./data/messages\";\nimport { ContentTemplateVariable } from \"./content-template\";\nimport { array, validateTypes } from \"@twilio/declarative-type-validator\";\nimport { json, sendMediaOptions } from \"./interfaces/rules\";\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 @validateTypes(\"string\")\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 @validateTypes(\"string\")\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 @validateTypes(json)\n setAttributes(attributes: JSONValue): MessageBuilder {\n this.message.attributes = attributes;\n return this;\n }\n\n /**\n * Set the email body with a given content type.\n * @param contentType Format of the body to set (text/plain or text/html).\n * @param body Body payload in the selected format.\n */\n @validateTypes(\"string\", [FormData, sendMediaOptions])\n setEmailBody(\n contentType: string,\n body: FormData | SendMediaOptions\n ): MessageBuilder {\n this.emailBodies.set(contentType, body);\n return this;\n }\n\n /**\n * Set the email history with a given content type.\n * @param contentType Format of the history to set (text/plain or text/html).\n * @param history History payload in the selected format.\n */\n @validateTypes(\"string\", [FormData, sendMediaOptions])\n setEmailHistory(\n contentType: string,\n history: FormData | SendMediaOptions\n ): MessageBuilder {\n this.emailHistories.set(contentType, history);\n return this;\n }\n\n /**\n * Adds {@link ContentTemplate} SID for the message alongside optional\n * variables. When no variables provided, the default values will be used.\n *\n * Adding the content SID converts the message to a rich message. In this\n * case, other fields are ignored and the message is sent using the content\n * from the the {@link ContentTemplate}.\n *\n * Use {@link Client.getContentTemplates} to request all available\n * {@link ContentTemplate}s.\n *\n * @param contentSid SID of the {@link ContentTemplate}\n * @param variables Custom variables to resolve the template.\n */\n @validateTypes(\"string\", [\n array(\"content variables\", ContentTemplateVariable),\n \"undefined\",\n ])\n setContentTemplate(\n contentSid: string,\n contentVariables: ContentTemplateVariable[] = []\n ): MessageBuilder {\n this.message.contentSid = contentSid;\n this.message.contentVariables = contentVariables;\n return this;\n }\n\n /**\n * Adds media to the message.\n * @param payload Media to add.\n */\n @validateTypes([FormData, sendMediaOptions])\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.emailBodiesAllowedContentTypes.includes(key)) {\n throw new Error(`Unsupported email body content type ${key}`);\n }\n });\n this.emailHistories.forEach((_, key) => {\n if (!this.limits.emailHistoriesAllowedContentTypes.includes(key)) {\n throw new Error(`Unsupported email history content type ${key}`);\n }\n });\n if (\n this.emailBodies.size > this.limits.emailBodiesAllowedContentTypes.length\n ) {\n throw new Error(\n `Too many email bodies attached to the message (${this.emailBodies.size} > ${this.limits.emailBodiesAllowedContentTypes.length})`\n );\n }\n if (\n this.emailHistories.size >\n this.limits.emailHistoriesAllowedContentTypes.length\n ) {\n throw new Error(\n `Too many email histories attached to the message (${this.emailHistories.size} > ${this.limits.emailHistoriesAllowedContentTypes.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 /**\n * Prepares a message and sends it to the conversation.\n */\n buildAndSend(): CancellablePromise<number | null> {\n return this.build().send();\n }\n}\n\nexport {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,mBAAmB,EAAE,uBAAuB,CAAC;QACnD,WAAW;KACZ,CAAC;;;oCAIC,cAAc,CAAA;AAIhB,CAAA,EAAA,cAAA,CAAA,SAAA,EAAA,oBAAA,EAAA,IAAA,CAAA,CAAA;AAOD,UAAA,CAAA;AADC,IAAA,aAAa,CAAC,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;;;oCACI,cAAc,CAAA;AAc7D,CAAA,EAAA,cAAA,CAAA,SAAA,EAAA,UAAA,EAAA,IAAA,CAAA;;;;"}
@@ -0,0 +1,231 @@
1
+ /*
2
+ @license
3
+ The following license applies to all parts of this software except as
4
+ documented below.
5
+
6
+ Copyright (c) 2019, Twilio, inc.
7
+ All rights reserved.
8
+
9
+ Redistribution and use in source and binary forms, with or without
10
+ modification, are permitted provided that the following conditions are
11
+ met:
12
+
13
+ 1. Redistributions of source code must retain the above copyright
14
+ notice, this list of conditions and the following disclaimer.
15
+
16
+ 2. Redistributions in binary form must reproduce the above copyright
17
+ notice, this list of conditions and the following disclaimer in
18
+ the documentation and/or other materials provided with the
19
+ distribution.
20
+
21
+ 3. Neither the name of Twilio nor the names of its contributors may
22
+ be used to endorse or promote products derived from this software
23
+ without specific prior written permission.
24
+
25
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29
+ HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
+
37
+ This software includes javascript-state-machine under the following license.
38
+
39
+ Copyright (c) 2012, 2013, 2014, 2015, Jake Gordon and contributors
40
+
41
+ Permission is hereby granted, free of charge, to any person obtaining a copy
42
+ of this software and associated documentation files (the "Software"), to deal
43
+ in the Software without restriction, including without limitation the rights
44
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
45
+ copies of the Software, and to permit persons to whom the Software is
46
+ furnished to do so, subject to the following conditions:
47
+
48
+ The above copyright notice and this permission notice shall be included in all
49
+ copies or substantial portions of the Software.
50
+
51
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
52
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
53
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
54
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
55
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
56
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
57
+
58
+ This software includes loglevel under the following license.
59
+
60
+ Copyright (c) 2013 Tim Perry
61
+
62
+ Permission is hereby granted, free of charge, to any person
63
+ obtaining a copy of this software and associated documentation
64
+ files (the "Software"), to deal in the Software without
65
+ restriction, including without limitation the rights to use,
66
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
67
+ copies of the Software, and to permit persons to whom the
68
+ Software is furnished to do so, subject to the following
69
+ conditions:
70
+
71
+ The above copyright notice and this permission notice shall be
72
+ included in all copies or substantial portions of the Software.
73
+
74
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
75
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
76
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
77
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
78
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
79
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
80
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
81
+ OTHER DEALINGS IN THE SOFTWARE.
82
+
83
+ This software includes q under the following license.
84
+
85
+ Copyright 2009–2014 Kristopher Michael Kowal. All rights reserved.
86
+ Permission is hereby granted, free of charge, to any person obtaining a copy
87
+ of this software and associated documentation files (the "Software"), to
88
+ deal in the Software without restriction, including without limitation the
89
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
90
+ sell copies of the Software, and to permit persons to whom the Software is
91
+ furnished to do so, subject to the following conditions:
92
+
93
+ The above copyright notice and this permission notice shall be included in
94
+ all copies or substantial portions of the Software.
95
+
96
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
97
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
98
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
99
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
100
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
101
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
102
+ IN THE SOFTWARE.
103
+
104
+ This software includes platform.js under the following license.
105
+
106
+ Copyright 2014 Benjamin Tan <https://d10.github.io/>
107
+ Copyright 2011-2015 John-David Dalton <http://allyoucanleet.com/>
108
+
109
+ Permission is hereby granted, free of charge, to any person obtaining
110
+ a copy of this software and associated documentation files (the
111
+ "Software"), to deal in the Software without restriction, including
112
+ without limitation the rights to use, copy, modify, merge, publish,
113
+ distribute, sublicense, and/or sell copies of the Software, and to
114
+ permit persons to whom the Software is furnished to do so, subject to
115
+ the following conditions:
116
+
117
+ The above copyright notice and this permission notice shall be
118
+ included in all copies or substantial portions of the Software.
119
+
120
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
121
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
122
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
123
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
124
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
125
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
126
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
127
+
128
+ */
129
+ var global =
130
+ typeof global !== "undefined"
131
+ ? global
132
+ : typeof self !== "undefined"
133
+ ? self
134
+ : typeof window !== "undefined"
135
+ ? window
136
+ : {};
137
+
138
+ import quickLru from './node_modules/quick-lru/index.js';
139
+ import { UriBuilder } from './util/index.js';
140
+ import { RestPaginator } from './rest-paginator.js';
141
+
142
+ /**
143
+ * Email recipient descriptor.
144
+ */
145
+ class EmailRecipientDescriptor {
146
+ /**
147
+ * @internal
148
+ */
149
+ constructor(recipient) {
150
+ /**
151
+ * Type of recipient.
152
+ */
153
+ this.type = "email";
154
+ this.messageSid = recipient.message_sid;
155
+ this.level = recipient.level;
156
+ this.name = recipient.name;
157
+ this.address = recipient.address;
158
+ }
159
+ }
160
+ /**
161
+ * Unknown recipient descriptor. Used to be able to handle recipient types that
162
+ * are not supported by the current version of the SDK.
163
+ */
164
+ class UnknownRecipientDescriptor {
165
+ /**
166
+ * @internal
167
+ */
168
+ constructor(recipient) {
169
+ this.type = recipient.type;
170
+ this.messageSid = recipient.message_sid;
171
+ this.rawData = JSON.stringify(recipient);
172
+ }
173
+ }
174
+ class MessageRecipientsClient {
175
+ constructor(services, configuration) {
176
+ this._services = services;
177
+ this._configuration = configuration;
178
+ this._cache = new quickLru({
179
+ maxSize: configuration.messageRecipientsCacheCapacity,
180
+ });
181
+ }
182
+ async getRecipientsFromMessage(conversationSid, messageSid) {
183
+ const key = `${conversationSid},${messageSid}`;
184
+ const cachedItem = this._cache.get(key);
185
+ if (cachedItem) {
186
+ return cachedItem.item;
187
+ }
188
+ const url = new UriBuilder(this._configuration.links.conversations)
189
+ .path(conversationSid)
190
+ .path("MessageRecipients")
191
+ .arg("MessageSid", messageSid)
192
+ .build();
193
+ const recipientsResponse = await this._services.commandExecutor.fetchResource(url);
194
+ const recipients = recipientsResponse.message_recipients.map((recipient) => this._wrapResponse(recipient));
195
+ if (recipients.length > 0) {
196
+ this._cache.set(key, { item: recipients });
197
+ }
198
+ return recipients;
199
+ }
200
+ async getRecipientsFromConversation(conversationSid, paginatorOptions) {
201
+ var _a, _b, _c, _d;
202
+ const url = new UriBuilder(this._configuration.links.conversations)
203
+ .path(conversationSid)
204
+ .path("MessageRecipients")
205
+ .arg("PageToken", (_a = paginatorOptions === null || paginatorOptions === void 0 ? void 0 : paginatorOptions.pageToken) !== null && _a !== void 0 ? _a : undefined)
206
+ .arg("PageSize", (_b = paginatorOptions === null || paginatorOptions === void 0 ? void 0 : paginatorOptions.pageSize) !== null && _b !== void 0 ? _b : undefined)
207
+ .build();
208
+ const recipientsResponse = await this._services.commandExecutor.fetchResource(url);
209
+ const allRecipients = recipientsResponse.message_recipients.map((recipient) => this._wrapResponse(recipient));
210
+ for (const recipient of allRecipients) {
211
+ const key = `${conversationSid},${recipient.messageSid}`;
212
+ const existingMessageRecipients = (_d = (_c = this._cache.get(key)) === null || _c === void 0 ? void 0 : _c.item) !== null && _d !== void 0 ? _d : [];
213
+ this._cache.set(key, { item: [...existingMessageRecipients, recipient] });
214
+ }
215
+ return new RestPaginator(allRecipients, (pageToken, pageSize) => this.getRecipientsFromConversation(conversationSid, {
216
+ pageToken,
217
+ pageSize,
218
+ }), recipientsResponse.meta.previous_token, recipientsResponse.meta.next_token);
219
+ }
220
+ _wrapResponse(recipient) {
221
+ switch (recipient.type) {
222
+ case "email":
223
+ return new EmailRecipientDescriptor(recipient);
224
+ default:
225
+ return new UnknownRecipientDescriptor(recipient);
226
+ }
227
+ }
228
+ }
229
+
230
+ export { EmailRecipientDescriptor, MessageRecipientsClient, UnknownRecipientDescriptor };
231
+ //# sourceMappingURL=message-recipients-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message-recipients-client.js","sources":["../src/message-recipients-client.ts"],"sourcesContent":["import { CommandExecutor } from \"./command-executor\";\nimport { Configuration } from \"./configuration\";\nimport QuickLRU from \"quick-lru\";\nimport {\n MessageRecipient,\n MessageRecipientsResponse,\n} from \"./interfaces/commands/message-recipients-response\";\nimport { Paginator } from \"./interfaces/paginator\";\nimport { UriBuilder } from \"./util\";\nimport { ResponseMeta } from \"./interfaces/commands/response-meta\";\nimport { RestPaginator } from \"./rest-paginator\";\n\ntype MessageRecipientsClientServices = {\n commandExecutor: CommandExecutor;\n};\n\ntype MessageRecipientsCacheEntry = {\n item: RecipientDescriptor[];\n};\n\n/**\n * Message recipient descriptor.\n */\ntype RecipientDescriptor =\n | EmailRecipientDescriptor\n | UnknownRecipientDescriptor;\n\n/**\n * Email recipient level.\n */\ntype EmailRecipientLevel = \"to\" | \"from\" | \"cc\";\n\n/**\n * Email recipient descriptor.\n */\nclass EmailRecipientDescriptor {\n /**\n * Type of recipient.\n */\n public readonly type = \"email\";\n\n /**\n * Sid of the message that this recipient belongs to.\n */\n public readonly messageSid: string;\n\n /**\n * Email recipient level.\n */\n public readonly level: EmailRecipientLevel;\n\n /**\n * Name of the recipient.\n */\n public readonly name: string;\n\n /**\n * Address of the recipient.\n */\n public readonly address: string;\n\n /**\n * @internal\n */\n public constructor(recipient: MessageRecipient) {\n this.messageSid = recipient.message_sid;\n this.level = recipient.level;\n this.name = recipient.name;\n this.address = recipient.address;\n }\n}\n\n/**\n * Unknown recipient descriptor. Used to be able to handle recipient types that\n * are not supported by the current version of the SDK.\n */\nclass UnknownRecipientDescriptor {\n /**\n * Type of recipient.\n */\n public readonly type: string;\n\n /**\n * Sid of the message that this recipient belongs to.\n */\n public readonly messageSid: string;\n\n /**\n * Recipient data as a JSON string.\n */\n public readonly rawData: string;\n\n /**\n * @internal\n */\n public constructor(recipient: MessageRecipient) {\n this.type = recipient.type;\n this.messageSid = recipient.message_sid;\n this.rawData = JSON.stringify(recipient);\n }\n}\n\nclass MessageRecipientsClient {\n private readonly _services: MessageRecipientsClientServices;\n private readonly _configuration: Configuration;\n private readonly _cache: QuickLRU<string, MessageRecipientsCacheEntry>;\n\n public constructor(\n services: MessageRecipientsClientServices,\n configuration: Configuration\n ) {\n this._services = services;\n this._configuration = configuration;\n this._cache = new QuickLRU({\n maxSize: configuration.messageRecipientsCacheCapacity,\n });\n }\n\n public async getRecipientsFromMessage(\n conversationSid: string,\n messageSid: string\n ): Promise<RecipientDescriptor[]> {\n const key = `${conversationSid},${messageSid}`;\n const cachedItem = this._cache.get(key);\n\n if (cachedItem) {\n return cachedItem.item;\n }\n\n const url = new UriBuilder(this._configuration.links.conversations)\n .path(conversationSid)\n .path(\"MessageRecipients\")\n .arg(\"MessageSid\", messageSid)\n .build();\n const recipientsResponse =\n await this._services.commandExecutor.fetchResource<\n void,\n MessageRecipientsResponse\n >(url);\n const recipients: RecipientDescriptor[] =\n recipientsResponse.message_recipients.map((recipient) =>\n this._wrapResponse(recipient)\n );\n\n if (recipients.length > 0) {\n this._cache.set(key, { item: recipients });\n }\n\n return recipients;\n }\n\n public async getRecipientsFromConversation(\n conversationSid: string,\n paginatorOptions?: {\n pageToken?: string;\n pageSize?: number;\n }\n ): Promise<Paginator<RecipientDescriptor>> {\n const url = new UriBuilder(this._configuration.links.conversations)\n .path(conversationSid)\n .path(\"MessageRecipients\")\n .arg(\"PageToken\", paginatorOptions?.pageToken ?? undefined)\n .arg(\"PageSize\", paginatorOptions?.pageSize ?? undefined)\n .build();\n const recipientsResponse =\n await this._services.commandExecutor.fetchResource<\n void,\n { message_recipients: MessageRecipient[] } & ResponseMeta\n >(url);\n const allRecipients = recipientsResponse.message_recipients.map(\n (recipient) => this._wrapResponse(recipient)\n );\n\n for (const recipient of allRecipients) {\n const key = `${conversationSid},${recipient.messageSid}`;\n const existingMessageRecipients = this._cache.get(key)?.item ?? [];\n this._cache.set(key, { item: [...existingMessageRecipients, recipient] });\n }\n\n return new RestPaginator<RecipientDescriptor>(\n allRecipients,\n (pageToken, pageSize) =>\n this.getRecipientsFromConversation(conversationSid, {\n pageToken,\n pageSize,\n }),\n recipientsResponse.meta.previous_token,\n recipientsResponse.meta.next_token\n );\n }\n\n private _wrapResponse(recipient: MessageRecipient): RecipientDescriptor {\n switch (recipient.type) {\n case \"email\":\n return new EmailRecipientDescriptor(recipient);\n default:\n return new UnknownRecipientDescriptor(recipient);\n }\n }\n}\n\nexport {\n MessageRecipientsClient,\n EmailRecipientDescriptor,\n UnknownRecipientDescriptor,\n RecipientDescriptor,\n EmailRecipientLevel,\n};\n"],"names":["QuickLRU"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA;;AAEG;AACH,MAAM,wBAAwB,CAAA;AA0B5B;;AAEG;AACH,IAAA,WAAA,CAAmB,SAA2B,EAAA;AA5B9C;;AAEG;QACa,IAAI,CAAA,IAAA,GA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