@twilio/conversations 3.0.0-rc.8 → 3.0.1-rc.1

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 (158) hide show
  1. package/README.md +38 -28
  2. package/builds/browser.js +4327 -7903
  3. package/builds/browser.js.map +1 -1
  4. package/builds/lib.d.ts +629 -102
  5. package/builds/lib.js +4319 -7904
  6. package/builds/lib.js.map +1 -1
  7. package/builds/twilio-conversations.js +27540 -41958
  8. package/builds/twilio-conversations.min.js +200 -1
  9. package/dist/aggregated-delivery-receipt.js +10 -1
  10. package/dist/aggregated-delivery-receipt.js.map +1 -1
  11. package/dist/channel-metadata-client.js +192 -0
  12. package/dist/channel-metadata-client.js.map +1 -0
  13. package/dist/client.js +75 -123
  14. package/dist/client.js.map +1 -1
  15. package/dist/command-executor.js +81 -20
  16. package/dist/command-executor.js.map +1 -1
  17. package/dist/configuration.js +14 -3
  18. package/dist/configuration.js.map +1 -1
  19. package/dist/content-client.js +184 -0
  20. package/dist/content-client.js.map +1 -0
  21. package/dist/content-template.js +310 -0
  22. package/dist/content-template.js.map +1 -0
  23. package/dist/conversation.js +105 -22
  24. package/dist/conversation.js.map +1 -1
  25. package/dist/data/conversations.js +43 -5
  26. package/dist/data/conversations.js.map +1 -1
  27. package/dist/data/messages.js +26 -19
  28. package/dist/data/messages.js.map +1 -1
  29. package/dist/data/participants.js +15 -4
  30. package/dist/data/participants.js.map +1 -1
  31. package/dist/data/users.js +11 -2
  32. package/dist/data/users.js.map +1 -1
  33. package/dist/detailed-delivery-receipt.js +9 -0
  34. package/dist/detailed-delivery-receipt.js.map +1 -1
  35. package/dist/index.js +20 -2
  36. package/dist/index.js.map +1 -1
  37. package/dist/interfaces/notification-types.js +9 -0
  38. package/dist/interfaces/notification-types.js.map +1 -1
  39. package/dist/interfaces/{attributes.js → rules.js} +26 -7
  40. package/dist/interfaces/rules.js.map +1 -0
  41. package/dist/logger.js +9 -0
  42. package/dist/logger.js.map +1 -1
  43. package/dist/media.js +9 -0
  44. package/dist/media.js.map +1 -1
  45. package/dist/message-builder.js +77 -6
  46. package/dist/message-builder.js.map +1 -1
  47. package/dist/message.js +115 -22
  48. package/dist/message.js.map +1 -1
  49. package/dist/node_modules/quick-lru/index.js +265 -0
  50. package/dist/node_modules/quick-lru/index.js.map +1 -0
  51. package/dist/node_modules/tslib/tslib.es6.js +9 -0
  52. package/dist/node_modules/tslib/tslib.es6.js.map +1 -1
  53. package/dist/packages/conversations/package.json.js +10 -1
  54. package/dist/packages/conversations/package.json.js.map +1 -1
  55. package/dist/participant.js +45 -36
  56. package/dist/participant.js.map +1 -1
  57. package/dist/push-notification.js +9 -0
  58. package/dist/push-notification.js.map +1 -1
  59. package/dist/rest-paginator.js +20 -11
  60. package/dist/rest-paginator.js.map +1 -1
  61. package/dist/services/network.js +110 -11
  62. package/dist/services/network.js.map +1 -1
  63. package/dist/services/typing-indicator.js +22 -5
  64. package/dist/services/typing-indicator.js.map +1 -1
  65. package/dist/unsent-message.js +9 -0
  66. package/dist/unsent-message.js.map +1 -1
  67. package/dist/user.js +20 -3
  68. package/dist/user.js.map +1 -1
  69. package/dist/util/deferred.js +9 -0
  70. package/dist/util/deferred.js.map +1 -1
  71. package/dist/util/index.js +9 -0
  72. package/dist/util/index.js.map +1 -1
  73. package/docs/.nojekyll +1 -0
  74. package/docs/assets/highlight.css +113 -0
  75. package/docs/assets/main.js +58 -0
  76. package/docs/assets/search.js +1 -0
  77. package/docs/assets/style.css +1279 -0
  78. package/docs/classes/AggregatedDeliveryReceipt.html +144 -3182
  79. package/docs/classes/CancellablePromise.html +224 -3209
  80. package/docs/classes/CancellationError.html +112 -0
  81. package/docs/classes/ChannelMetadata.html +67 -0
  82. package/docs/classes/Client.html +701 -4237
  83. package/docs/classes/ContentTemplate.html +97 -0
  84. package/docs/classes/ContentTemplateVariable.html +90 -0
  85. package/docs/classes/Conversation.html +768 -4352
  86. package/docs/classes/DetailedDeliveryReceipt.html +116 -3162
  87. package/docs/classes/Media.html +119 -3165
  88. package/docs/classes/Message.html +417 -3730
  89. package/docs/classes/MessageBuilder.html +208 -3274
  90. package/docs/classes/Participant.html +258 -3442
  91. package/docs/classes/PushNotification.html +101 -3129
  92. package/docs/classes/RestPaginator.html +120 -3158
  93. package/docs/classes/UnsentMessage.html +63 -3040
  94. package/docs/classes/User.html +209 -3347
  95. package/docs/index.html +146 -3502
  96. package/docs/interfaces/ClientOptions.html +66 -3033
  97. package/docs/interfaces/ConversationBindings.html +109 -3000
  98. package/docs/interfaces/ConversationEmailBinding.html +109 -3000
  99. package/docs/interfaces/ConversationLimits.html +87 -3097
  100. package/docs/interfaces/ConversationState.html +66 -3049
  101. package/docs/interfaces/ConversationUpdatedEventArgs.html +109 -3000
  102. package/docs/interfaces/CreateConversationOptions.html +73 -3065
  103. package/docs/interfaces/LastMessage.html +66 -3049
  104. package/docs/interfaces/Paginator.html +110 -3139
  105. package/docs/interfaces/ParticipantBindingOptions.html +110 -0
  106. package/docs/interfaces/ParticipantBindings.html +109 -3000
  107. package/docs/interfaces/ParticipantEmailBinding.html +109 -3000
  108. package/docs/interfaces/PushNotificationData.html +94 -3113
  109. package/docs/interfaces/SendEmailOptions.html +59 -3033
  110. package/docs/interfaces/SendMediaOptions.html +75 -3067
  111. package/docs/modules.html +180 -3509
  112. package/docs/types/ChannelType.html +106 -0
  113. package/docs/types/ConnectionState.html +115 -0
  114. package/docs/types/ContentData.html +106 -0
  115. package/docs/types/ContentDataAction.html +107 -0
  116. package/docs/types/ContentDataActionOther.html +121 -0
  117. package/docs/types/ContentDataActionPhone.html +128 -0
  118. package/docs/types/ContentDataActionReply.html +133 -0
  119. package/docs/types/ContentDataActionUrl.html +128 -0
  120. package/docs/types/ContentDataCallToAction.html +131 -0
  121. package/docs/types/ContentDataCard.html +137 -0
  122. package/docs/types/ContentDataListItem.html +121 -0
  123. package/docs/types/ContentDataListPicker.html +134 -0
  124. package/docs/types/ContentDataLocation.html +134 -0
  125. package/docs/types/ContentDataMedia.html +129 -0
  126. package/docs/types/ContentDataOther.html +121 -0
  127. package/docs/types/ContentDataQuickReply.html +131 -0
  128. package/docs/types/ContentDataReply.html +119 -0
  129. package/docs/types/ContentDataText.html +125 -0
  130. package/docs/types/ConversationStatus.html +107 -0
  131. package/docs/types/ConversationUpdateReason.html +106 -0
  132. package/docs/types/DeliveryAmount.html +106 -0
  133. package/docs/types/DeliveryStatus.html +106 -0
  134. package/docs/types/JSONArray.html +106 -0
  135. package/docs/types/JSONObject.html +111 -0
  136. package/docs/types/JSONValue.html +106 -0
  137. package/docs/types/LogLevel.html +106 -0
  138. package/docs/types/MediaCategory.html +106 -0
  139. package/docs/types/MessageType.html +106 -0
  140. package/docs/types/MessageUpdateReason.html +106 -0
  141. package/docs/types/NotificationLevel.html +109 -0
  142. package/docs/types/NotificationsChannelType.html +110 -0
  143. package/docs/types/ParticipantEmailLevel.html +108 -0
  144. package/docs/types/ParticipantType.html +107 -0
  145. package/docs/types/ParticipantUpdateReason.html +106 -0
  146. package/docs/types/PushNotificationType.html +106 -0
  147. package/docs/types/State.html +110 -0
  148. package/docs/types/UserUpdateReason.html +106 -0
  149. package/package.json +22 -17
  150. package/CHANGELOG.md +0 -501
  151. package/dist/interfaces/attributes.js.map +0 -1
  152. package/docs/assets/css/main.css +0 -2660
  153. package/docs/assets/images/icons.png +0 -0
  154. package/docs/assets/images/icons@2x.png +0 -0
  155. package/docs/assets/images/widgets.png +0 -0
  156. package/docs/assets/images/widgets@2x.png +0 -0
  157. package/docs/assets/js/main.js +0 -248
  158. package/docs/assets/js/search.js +0 -1
package/dist/message.js CHANGED
@@ -128,6 +128,15 @@ This software includes platform.js under the following license.
128
128
  */
129
129
  'use strict';
130
130
 
131
+ var global =
132
+ typeof global !== "undefined"
133
+ ? global
134
+ : typeof self !== "undefined"
135
+ ? self
136
+ : typeof window !== "undefined"
137
+ ? window
138
+ : {};
139
+
131
140
  Object.defineProperty(exports, '__esModule', { value: true });
132
141
 
133
142
  var tslib_es6 = require('./node_modules/tslib/tslib.es6.js');
@@ -137,17 +146,21 @@ var mcsClient = require('@twilio/mcs-client');
137
146
  var media = require('./media.js');
138
147
  var aggregatedDeliveryReceipt = require('./aggregated-delivery-receipt.js');
139
148
  var declarativeTypeValidator = require('@twilio/declarative-type-validator');
140
- var attributes = require('./interfaces/attributes.js');
149
+ var rules = require('./interfaces/rules.js');
141
150
  var restPaginator = require('./rest-paginator.js');
142
151
  var detailedDeliveryReceipt = require('./detailed-delivery-receipt.js');
143
152
  var replayEventEmitter = require('@twilio/replay-event-emitter');
144
153
  var isEqual = require('lodash.isequal');
154
+ var contentTemplate = require('./content-template.js');
145
155
 
146
156
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
147
157
 
148
158
  var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
149
159
 
150
160
  const log = logger.Logger.scope("Message");
161
+ const XHR =
162
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
163
+ global["XMLHttpRequest"] || {};
151
164
  /**
152
165
  * A message in a conversation.
153
166
  */
@@ -156,7 +169,7 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
156
169
  * @internal
157
170
  */
158
171
  constructor(index$1, data, conversation, links, configuration, services) {
159
- var _a, _b, _c, _d;
172
+ var _a, _b, _c, _d, _e;
160
173
  super();
161
174
  this.conversation = conversation;
162
175
  this.links = links;
@@ -167,15 +180,13 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
167
180
  index: index$1,
168
181
  author: data.author,
169
182
  subject: data.subject,
183
+ contentSid: data.contentSid,
170
184
  body: (_a = data.text) !== null && _a !== void 0 ? _a : null,
171
185
  timestamp: data.timestamp ? new Date(data.timestamp) : null,
172
186
  dateUpdated: data.dateUpdated ? new Date(data.dateUpdated) : null,
173
187
  lastUpdatedBy: (_b = data.lastUpdatedBy) !== null && _b !== void 0 ? _b : null,
174
188
  attributes: index.parseAttributes(data.attributes, `Got malformed attributes for the message ${data.sid}`, log),
175
189
  type: (_c = data.type) !== null && _c !== void 0 ? _c : "text",
176
- media: data.type === "media" && data.media
177
- ? new media.Media(data.media, this.services)
178
- : null,
179
190
  medias: data.type === "media" && data.medias
180
191
  ? data.medias.map((m) => new media.Media(m, this.services))
181
192
  : data.type === "media" && data.media && !data.medias
@@ -187,6 +198,7 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
187
198
  aggregatedDeliveryReceipt: data.delivery
188
199
  ? new aggregatedDeliveryReceipt.AggregatedDeliveryReceipt(data.delivery)
189
200
  : null,
201
+ hasChannelMetadata: (_e = data.channelMetadata) !== null && _e !== void 0 ? _e : false,
190
202
  };
191
203
  }
192
204
  /**
@@ -207,6 +219,12 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
207
219
  get subject() {
208
220
  return this.state.subject;
209
221
  }
222
+ /**
223
+ * Unique identifier of {@link ContentTemplate} for this message.
224
+ */
225
+ get contentSid() {
226
+ return this.state.contentSid;
227
+ }
210
228
  /**
211
229
  * Body of the message.
212
230
  */
@@ -220,14 +238,15 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
220
238
  return this.state.dateUpdated;
221
239
  }
222
240
  /**
223
- * Index of the message in the conversation's messages list.
224
- * By design of the Conversations system, the message indices may have arbitrary gaps between them,
241
+ * Index of this message in the conversation's list of messages.
242
+ *
243
+ * By design, the message indices may have arbitrary gaps between them,
225
244
  * that does not necessarily mean they were deleted or otherwise modified - just that
226
245
  * messages may have some non-contiguous indices even if they are being sent immediately one after another.
227
246
  *
228
247
  * Trying to use indices for some calculations is going to be unreliable.
229
248
  *
230
- * To calculate the number of unread messages it is better to use the read horizon API.
249
+ * To calculate the number of unread messages, it is better to use the Read Horizon API.
231
250
  * See {@link Conversation.getUnreadMessagesCount} for details.
232
251
  */
233
252
  get index() {
@@ -257,13 +276,6 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
257
276
  get type() {
258
277
  return this.state.type;
259
278
  }
260
- /**
261
- * One of the attached media (if present).
262
- * @deprecated Use attachedMedia instead. Note that the latter is now an array.
263
- */
264
- get media() {
265
- return this.state.media;
266
- }
267
279
  /**
268
280
  * Return all media attachments, except email body/history attachments, without temporary urls.
269
281
  */
@@ -414,16 +426,13 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
414
426
  */
415
427
  async getDetailedDeliveryReceipts() {
416
428
  let paginator = await this._getDetailedDeliveryReceiptsPaginator();
417
- let detailedDeliveryReceipts = [];
418
- while (true) {
429
+ let detailedDeliveryReceipts = paginator.items;
430
+ while (paginator.hasNextPage) {
431
+ paginator = await paginator.nextPage();
419
432
  detailedDeliveryReceipts = [
420
433
  ...detailedDeliveryReceipts,
421
434
  ...paginator.items,
422
435
  ];
423
- if (!paginator.hasNextPage) {
424
- break;
425
- }
426
- paginator = await paginator.nextPage();
427
436
  }
428
437
  return detailedDeliveryReceipts;
429
438
  }
@@ -509,6 +518,90 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
509
518
  const response = await this.services.network.get(url);
510
519
  return new restPaginator.RestPaginator(response.body.delivery_receipts.map((x) => new detailedDeliveryReceipt.DetailedDeliveryReceipt(x)), (pageToken, pageSize) => this._getDetailedDeliveryReceiptsPaginator({ pageToken, pageSize }), response.body.meta.previous_token, response.body.meta.next_token);
511
520
  }
521
+ /**
522
+ * Get the {@link ContentData} for this message. Resolves to `null` when
523
+ * {@link Message.contentSid} is null.
524
+ */
525
+ getContentData() {
526
+ return new mcsClient.CancellablePromise(async (resolve, reject, onCancel) => {
527
+ if (this.state.contentSid === null) {
528
+ resolve(null);
529
+ return;
530
+ }
531
+ const bodies = this.getMediaByCategories(["body"]);
532
+ if (bodies === null) {
533
+ resolve(null);
534
+ return;
535
+ }
536
+ const twilioPrefix = "application/x-vnd.com.twilio.rich.";
537
+ const filteredMedias = bodies.filter((media) => media.contentType.startsWith(twilioPrefix));
538
+ if (filteredMedias.length === 0) {
539
+ resolve(null);
540
+ return;
541
+ }
542
+ const contentMedia = filteredMedias[0];
543
+ const urlPromise = contentMedia.getContentTemporaryUrl();
544
+ onCancel(() => {
545
+ urlPromise.cancel();
546
+ });
547
+ let url;
548
+ try {
549
+ url = await urlPromise;
550
+ }
551
+ catch (e) {
552
+ reject(e);
553
+ return;
554
+ }
555
+ if (url === null) {
556
+ resolve(null);
557
+ return;
558
+ }
559
+ const jsonStringPromise = new Promise((resolve, reject) => {
560
+ let isCancelled = false;
561
+ const xhr = new XHR();
562
+ xhr.open("GET", url !== null && url !== void 0 ? url : "", true);
563
+ xhr.responseType = "text";
564
+ xhr.onreadystatechange = () => {
565
+ if (xhr.readyState !== 4 || isCancelled) {
566
+ return;
567
+ }
568
+ resolve(xhr.responseText);
569
+ };
570
+ xhr.onerror = () => {
571
+ reject(xhr.statusText);
572
+ };
573
+ onCancel(() => {
574
+ isCancelled = true;
575
+ xhr.abort();
576
+ reject(new Error("XHR has been aborted"));
577
+ });
578
+ xhr.send();
579
+ });
580
+ let json;
581
+ try {
582
+ const jsonString = await jsonStringPromise;
583
+ json = JSON.parse(jsonString);
584
+ }
585
+ catch (e) {
586
+ reject(e);
587
+ return;
588
+ }
589
+ const dataType = contentMedia.contentType
590
+ .replace(twilioPrefix, "")
591
+ .replace(".", "/");
592
+ resolve(contentTemplate.parseVariant(dataType, json.data));
593
+ });
594
+ }
595
+ /**
596
+ * Get the {@link ChannelMetadata} for this message. Resolves to `null` if
597
+ * the message doesn't have any channel metadata.
598
+ */
599
+ async getChannelMetadata() {
600
+ if (!this.state.hasChannelMetadata) {
601
+ return null;
602
+ }
603
+ return await this.services.channelMetadataClient.getChannelMetadata(this.conversation.sid, this.sid);
604
+ }
512
605
  }
513
606
  /**
514
607
  * Fired when the properties or the body of the message has been updated.
@@ -538,7 +631,7 @@ tslib_es6.__decorate([
538
631
  tslib_es6.__metadata("design:returntype", Promise)
539
632
  ], Message.prototype, "updateBody", null);
540
633
  tslib_es6.__decorate([
541
- declarativeTypeValidator.validateTypesAsync(attributes.attributesValidator),
634
+ declarativeTypeValidator.validateTypesAsync(rules.json),
542
635
  tslib_es6.__metadata("design:type", Function),
543
636
  tslib_es6.__metadata("design:paramtypes", [Object]),
544
637
  tslib_es6.__metadata("design:returntype", Promise)
@@ -1 +1 @@
1
- {"version":3,"file":"message.js","sources":["../src/message.ts"],"sourcesContent":["import { parseAttributes, UriBuilder } from \"./util\";\nimport { Logger } from \"./logger\";\nimport { Conversation } from \"./conversation\";\nimport {\n CancellablePromise,\n McsClient,\n MediaCategory,\n} from \"@twilio/mcs-client\";\nimport { Media } from \"./media\";\nimport { Participant } from \"./participant\";\nimport {\n AggregatedDeliveryDescriptor,\n AggregatedDeliveryReceipt,\n} from \"./aggregated-delivery-receipt\";\nimport {\n validateTypes,\n validateTypesAsync,\n nonEmptyString,\n nonEmptyArray,\n} from \"@twilio/declarative-type-validator\";\nimport { attributesValidator } from \"./interfaces/attributes\";\nimport { Network } from \"./services/network\";\nimport { RestPaginator } from \"./rest-paginator\";\nimport { DetailedDeliveryReceipt } from \"./detailed-delivery-receipt\";\nimport { Paginator } from \"./interfaces/paginator\";\nimport { Configuration } from \"./configuration\";\nimport { CommandExecutor } from \"./command-executor\";\nimport { EditMessageRequest } from \"./interfaces/commands/edit-message\";\nimport { MessageResponse } from \"./interfaces/commands/message-response\";\nimport { ReplayEventEmitter } from \"@twilio/replay-event-emitter\";\nimport isEqual from \"lodash.isequal\";\nimport { JSONValue } from \"./types\";\nimport { ResponseMeta } from \"./interfaces/commands/response-meta\";\nimport { DeliveryReceiptResponse } from \"./interfaces/commands/delivery-receipt-response\";\n\ntype MessageEvents = {\n updated: (data: {\n message: Message;\n updateReasons: MessageUpdateReason[];\n }) => void;\n};\n\nconst log = Logger.scope(\"Message\");\n\ninterface MessageState {\n sid: string;\n index: number;\n author: string | null;\n subject: string | null;\n body: string | null;\n dateUpdated: Date | null;\n lastUpdatedBy: string | null;\n attributes: JSONValue;\n timestamp: Date | null;\n type: MessageType;\n media: Media | null;\n medias: Media[] | null;\n participantSid: string | null;\n aggregatedDeliveryReceipt: AggregatedDeliveryReceipt | null;\n}\n\ninterface MessageServices {\n mcsClient: McsClient;\n network: Network;\n commandExecutor: CommandExecutor;\n}\n\ninterface MessageLinks {\n self: string;\n conversation: string;\n messages_receipts: string;\n}\n\n/**\n * The reason for the `updated` event being emitted by a message.\n */\ntype MessageUpdateReason =\n | \"body\"\n | \"lastUpdatedBy\"\n | \"dateCreated\"\n | \"dateUpdated\"\n | \"attributes\"\n | \"author\"\n | \"deliveryReceipt\"\n | \"subject\";\n\n/**\n * Type of a message.\n */\ntype MessageType = \"text\" | \"media\";\n\ninterface MessageUpdatedEventArgs {\n message: Message;\n updateReasons: MessageUpdateReason[];\n}\n\nexport interface MessageData {\n sid: string;\n text?: string;\n type?: MessageType;\n author: string | null;\n subject: string | null;\n lastUpdatedBy?: string | null;\n attributes?: JSONValue;\n dateUpdated: string;\n timestamp?: string;\n medias?: Media[];\n media?: Media;\n memberSid?: string;\n delivery?: AggregatedDeliveryDescriptor;\n}\n\n/**\n * A message in a conversation.\n */\nclass Message extends ReplayEventEmitter<MessageEvents> {\n /**\n * Conversation that the message is in.\n */\n public readonly conversation: Conversation;\n\n private readonly links: MessageLinks;\n private readonly configuration: Configuration;\n private readonly services: MessageServices;\n\n private state: MessageState;\n\n /**\n * @internal\n */\n constructor(\n index: number,\n data: MessageData,\n conversation: Conversation,\n links: MessageLinks,\n configuration: Configuration,\n services: MessageServices\n ) {\n super();\n\n this.conversation = conversation;\n\n this.links = links;\n this.configuration = configuration;\n this.services = services;\n\n this.state = {\n sid: data.sid,\n index: index,\n author: data.author,\n subject: data.subject,\n body: data.text ?? null,\n timestamp: data.timestamp ? new Date(data.timestamp) : null,\n dateUpdated: data.dateUpdated ? new Date(data.dateUpdated) : null,\n lastUpdatedBy: data.lastUpdatedBy ?? null,\n attributes: parseAttributes(\n data.attributes,\n `Got malformed attributes for the message ${data.sid}`,\n log\n ),\n type: data.type ?? \"text\",\n media:\n data.type === \"media\" && data.media\n ? new Media(data.media, this.services)\n : null,\n medias:\n data.type === \"media\" && data.medias\n ? data.medias.map((m) => new Media(m, this.services))\n : data.type === \"media\" && data.media && !data.medias\n ? [\n new Media(\n { ...data.media, category: \"media\" } as Media,\n this.services\n ),\n ]\n : null,\n participantSid: data.memberSid ?? null,\n aggregatedDeliveryReceipt: data.delivery\n ? new AggregatedDeliveryReceipt(data.delivery)\n : null,\n };\n }\n\n /**\n * Fired when the properties or the body of the message has been updated.\n *\n * Parameters:\n * 1. object `data` - info object provided with the event. It has the following properties:\n * * {@link Message} message - the message in question\n * * {@link MessageUpdateReason}[] updateReasons - array of reasons for the update\n */\n static readonly updated = \"updated\";\n\n /**\n * The server-assigned unique identifier for the message.\n */\n public get sid(): string {\n return this.state.sid;\n }\n\n /**\n * Name of the user that sent the message.\n */\n public get author(): string | null {\n return this.state.author;\n }\n\n /**\n * Message subject. Used only in email conversations.\n */\n public get subject(): string | null {\n return this.state.subject;\n }\n\n /**\n * Body of the message.\n */\n public get body(): string | null {\n return this.state.body;\n }\n\n /**\n * Date this message was last updated on.\n */\n public get dateUpdated(): Date | null {\n return this.state.dateUpdated;\n }\n\n /**\n * Index of the message in the conversation's messages list.\n * By design of the Conversations system, the message indices may have arbitrary gaps between them,\n * that does not necessarily mean they were deleted or otherwise modified - just that\n * messages may have some non-contiguous indices even if they are being sent immediately one after another.\n *\n * Trying to use indices for some calculations is going to be unreliable.\n *\n * To calculate the number of unread messages it is better to use the read horizon API.\n * See {@link Conversation.getUnreadMessagesCount} for details.\n */\n public get index(): number {\n return this.state.index;\n }\n\n /**\n * Identity of the last user that updated the message.\n */\n public get lastUpdatedBy(): string | null {\n return this.state.lastUpdatedBy;\n }\n\n /**\n * Date this message was created on.\n */\n public get dateCreated(): Date | null {\n return this.state.timestamp;\n }\n\n /**\n * Custom attributes of the message.\n */\n public get attributes(): JSONValue {\n return this.state.attributes;\n }\n\n /**\n * Type of the message.\n */\n public get type(): MessageType {\n return this.state.type;\n }\n\n /**\n * One of the attached media (if present).\n * @deprecated Use attachedMedia instead. Note that the latter is now an array.\n */\n public get media(): Media | null {\n return this.state.media;\n }\n\n /**\n * Return all media attachments, except email body/history attachments, without temporary urls.\n */\n public get attachedMedia(): Array<Media> | null {\n return this.getMediaByCategories([\"media\"]);\n }\n\n /**\n * The server-assigned unique identifier of the authoring participant.\n */\n public get participantSid(): string | null {\n return this.state.participantSid;\n }\n\n /**\n * Aggregated information about the message delivery statuses across all participants of a conversation..\n */\n public get aggregatedDeliveryReceipt(): AggregatedDeliveryReceipt | null {\n return this.state.aggregatedDeliveryReceipt;\n }\n\n /**\n * Return a (possibly empty) array of media matching a specific set of categories.\n * Allowed category is so far only 'media'.\n * @param categories Array of categories to match.\n * @returns Array of media descriptors matching given categories.\n */\n public getMediaByCategories(categories: MediaCategory[]): Media[] | null {\n return (this.state.medias ?? []).filter((m) =>\n categories.includes(m.category)\n );\n }\n\n /**\n * Get a media descriptor for an email body attachment of a provided type.\n * Allowed body types are returned in the Conversation.limits().emailBodiesAllowedContentTypes array.\n * @param type Type of email body to request, defaults to `text/plain`.\n */\n @validateTypes([nonEmptyString, \"undefined\"])\n public getEmailBody(type = \"text/plain\"): Media | null {\n return (\n this.getMediaByCategories([\"body\"])\n ?.filter((m) => m.contentType == type)\n .shift() ?? null\n );\n }\n\n /**\n * Get a media descriptor for an email history attachment of a provided type.\n * Allowed body types are returned in the Conversation.limits().emailHistoriesAllowedContentTypes array.\n * @param type Type of email history to request, defaults to `text/plain`.\n */\n @validateTypes([nonEmptyString, \"undefined\"])\n public getEmailHistory(type = \"text/plain\"): Media | null {\n return (\n this.getMediaByCategories([\"history\"])\n ?.filter((m) => m.contentType == type)\n .shift() ?? null\n );\n }\n\n _update(data) {\n const updateReasons: MessageUpdateReason[] = [];\n\n if (\n (data.text || typeof data.text === \"string\") &&\n data.text !== this.state.body\n ) {\n this.state.body = data.text;\n updateReasons.push(\"body\");\n }\n\n if (data.subject && data.subject !== this.state.subject) {\n this.state.subject = data.subject;\n updateReasons.push(\"subject\");\n }\n\n if (data.lastUpdatedBy && data.lastUpdatedBy !== this.state.lastUpdatedBy) {\n this.state.lastUpdatedBy = data.lastUpdatedBy;\n updateReasons.push(\"lastUpdatedBy\");\n }\n\n if (data.author && data.author !== this.state.author) {\n this.state.author = data.author;\n updateReasons.push(\"author\");\n }\n\n if (\n data.dateUpdated &&\n new Date(data.dateUpdated).getTime() !==\n (this.state.dateUpdated && this.state.dateUpdated.getTime())\n ) {\n this.state.dateUpdated = new Date(data.dateUpdated);\n updateReasons.push(\"dateUpdated\");\n }\n\n if (\n data.timestamp &&\n new Date(data.timestamp).getTime() !==\n (this.state.timestamp && this.state.timestamp.getTime())\n ) {\n this.state.timestamp = new Date(data.timestamp);\n updateReasons.push(\"dateCreated\");\n }\n\n const updatedAttributes = parseAttributes(\n data.attributes,\n `Got malformed attributes for the message ${this.sid}`,\n log\n );\n if (!isEqual(this.state.attributes, updatedAttributes)) {\n this.state.attributes = updatedAttributes;\n updateReasons.push(\"attributes\");\n }\n\n const updatedAggregatedDelivery = data.delivery;\n const currentAggregatedDelivery = this.state.aggregatedDeliveryReceipt;\n const isUpdatedAggregateDeliveryValid =\n !!updatedAggregatedDelivery &&\n !!updatedAggregatedDelivery.total &&\n !!updatedAggregatedDelivery.delivered &&\n !!updatedAggregatedDelivery.failed &&\n !!updatedAggregatedDelivery.read &&\n !!updatedAggregatedDelivery.sent &&\n !!updatedAggregatedDelivery.undelivered;\n if (isUpdatedAggregateDeliveryValid) {\n if (!currentAggregatedDelivery) {\n this.state.aggregatedDeliveryReceipt = new AggregatedDeliveryReceipt(\n updatedAggregatedDelivery\n );\n updateReasons.push(\"deliveryReceipt\");\n } else if (\n !currentAggregatedDelivery._isEquals(updatedAggregatedDelivery)\n ) {\n currentAggregatedDelivery._update(updatedAggregatedDelivery);\n updateReasons.push(\"deliveryReceipt\");\n }\n }\n\n if (updateReasons.length > 0) {\n this.emit(\"updated\", { message: this, updateReasons: updateReasons });\n }\n }\n\n /**\n * Get the participant who is the author of the message.\n */\n public async getParticipant(): Promise<Participant> {\n let participant: Participant | null = null;\n if (this.state.participantSid) {\n participant = await this.conversation\n .getParticipantBySid(this.state.participantSid)\n .catch(() => {\n log.debug(\n `Participant with sid \"${this.participantSid}\" not found for message ${this.sid}`\n );\n return null;\n });\n }\n if (!participant && this.state.author) {\n participant = await this.conversation\n .getParticipantByIdentity(this.state.author)\n .catch(() => {\n log.debug(\n `Participant with identity \"${this.author}\" not found for message ${this.sid}`\n );\n return null;\n });\n }\n if (participant) {\n return participant;\n }\n let errorMesage = \"Participant with \";\n if (this.state.participantSid) {\n errorMesage += \"SID '\" + this.state.participantSid + \"' \";\n }\n if (this.state.author) {\n if (this.state.participantSid) {\n errorMesage += \"or \";\n }\n errorMesage += \"identity '\" + this.state.author + \"' \";\n }\n if (errorMesage === \"Participant with \") {\n errorMesage = \"Participant \";\n }\n errorMesage += \"was not found\";\n throw new Error(errorMesage);\n }\n\n /**\n * Get the delivery receipts of the message.\n */\n public async getDetailedDeliveryReceipts(): Promise<\n DetailedDeliveryReceipt[]\n > {\n let paginator: Paginator<DetailedDeliveryReceipt> =\n await this._getDetailedDeliveryReceiptsPaginator();\n let detailedDeliveryReceipts: DetailedDeliveryReceipt[] = [];\n\n while (true) {\n detailedDeliveryReceipts = [\n ...detailedDeliveryReceipts,\n ...paginator.items,\n ];\n\n if (!paginator.hasNextPage) {\n break;\n }\n\n paginator = await paginator.nextPage();\n }\n\n return detailedDeliveryReceipts;\n }\n\n /**\n * Remove the message.\n */\n public async remove(): Promise<Message> {\n await this.services.commandExecutor.mutateResource(\n \"delete\",\n this.links.self\n );\n\n return this;\n }\n\n /**\n * Edit the message body.\n * @param body New body of the message.\n */\n @validateTypesAsync(\"string\")\n public async updateBody(body: string): Promise<Message> {\n await this.services.commandExecutor.mutateResource<\n EditMessageRequest,\n MessageResponse\n >(\"post\", this.links.self, {\n body,\n });\n\n return this;\n }\n\n /**\n * Edit the message attributes.\n * @param attributes New attributes.\n */\n @validateTypesAsync(attributesValidator)\n public async updateAttributes(attributes: JSONValue): Promise<Message> {\n await this.services.commandExecutor.mutateResource<\n EditMessageRequest,\n MessageResponse\n >(\"post\", this.links.self, {\n attributes:\n typeof attributes !== \"undefined\"\n ? JSON.stringify(attributes)\n : undefined,\n });\n\n return this;\n }\n\n /**\n * Get content URLs for all media attachments in the given set using a single operation.\n * @param contentSet Set of media attachments to query content URLs.\n */\n @validateTypesAsync(nonEmptyArray(\"media\", Media))\n public getTemporaryContentUrlsForMedia(\n contentSet: Media[]\n ): CancellablePromise<Map<string, string>> {\n // We ignore existing mcsMedia members of each of the media entries.\n // Instead we just collect their sids and pull new descriptors from a mediaSet GET endpoint.\n const sids = contentSet.map((m) => m.sid);\n return this.getTemporaryContentUrlsForMediaSids(sids);\n }\n\n /**\n * Get content URLs for all media attachments in the given set of media sids using a single operation.\n * @param mediaSids Set of media sids to query for the content URL.\n */\n @validateTypesAsync(nonEmptyArray(\"strings\", \"string\"))\n public getTemporaryContentUrlsForMediaSids(\n mediaSids: string[]\n ): CancellablePromise<Map<string, string>> {\n return new CancellablePromise(async (resolve, reject, onCancel) => {\n const mediaGetRequest = this.services.mcsClient.mediaSetGetContentUrls(\n mediaSids ?? []\n );\n\n if (!this.services.mcsClient || !mediaSids) {\n reject(new Error(\"Media Content Service is unavailable\"));\n return;\n }\n\n onCancel(() => {\n mediaGetRequest.cancel();\n });\n\n try {\n const urls = await mediaGetRequest;\n resolve(urls);\n } catch (e) {\n reject(e);\n }\n });\n }\n\n /**\n * Get content URLs for all media attached to the message.\n */\n public getTemporaryContentUrlsForAttachedMedia(): CancellablePromise<\n Map<string, string>\n > {\n const media = this.attachedMedia;\n const sids = media?.map((m) => m.sid) ?? [];\n return this.getTemporaryContentUrlsForMediaSids(sids);\n }\n\n private async _getDetailedDeliveryReceiptsPaginator(options?: {\n pageToken?: string;\n pageSize?: number;\n }): Promise<Paginator<DetailedDeliveryReceipt>> {\n const messagesReceiptsUrl = this.configuration.links.messagesReceipts\n .replace(\"%s\", this.conversation.sid)\n .replace(\"%s\", this.sid);\n const url = new UriBuilder(messagesReceiptsUrl)\n .arg(\"PageToken\", options?.pageToken as string)\n .arg(\"PageSize\", options?.pageSize as number)\n .build();\n const response = await this.services.network.get<\n { delivery_receipts: DeliveryReceiptResponse[] } & ResponseMeta\n >(url);\n\n return new RestPaginator<DetailedDeliveryReceipt>(\n response.body.delivery_receipts.map(\n (x) => new DetailedDeliveryReceipt(x)\n ),\n (pageToken, pageSize) =>\n this._getDetailedDeliveryReceiptsPaginator({ pageToken, pageSize }),\n response.body.meta.previous_token,\n response.body.meta.next_token\n );\n }\n}\n\nexport {\n Message,\n MessageServices,\n MessageType,\n MessageUpdateReason,\n MessageUpdatedEventArgs,\n};\n"],"names":["Logger","ReplayEventEmitter","index","parseAttributes","Media","AggregatedDeliveryReceipt","isEqual","CancellablePromise","UriBuilder","RestPaginator","DetailedDeliveryReceipt","__decorate","validateTypes","nonEmptyString","validateTypesAsync","attributesValidator","nonEmptyArray"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAM,GAAG,GAAGA,aAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AAsEpC;;AAEG;AACH,MAAM,OAAQ,SAAQC,qCAAiC,CAAA;AAYrD;;AAEG;IACH,WACE,CAAAC,OAAa,EACb,IAAiB,EACjB,YAA0B,EAC1B,KAAmB,EACnB,aAA4B,EAC5B,QAAyB,EAAA;;AAEzB,QAAA,KAAK,EAAE,CAAC;AAER,QAAA,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;AAEjC,QAAA,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;AACnB,QAAA,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;AACnC,QAAA,IAAI,CAAC,Q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AAS,EAAE,QAAQ,CAAC,CAAC;;;8CAGpDT,4BAAkB,CAAA;AAsBpB,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,qCAAA,EAAA,IAAA,CAAA;;;;"}
1
+ {"version":3,"file":"message.js","sources":["../src/message.ts"],"sourcesContent":["import { parseAttributes, UriBuilder } from \"./util\";\nimport { Logger } from \"./logger\";\nimport { Conversation } from \"./conversation\";\nimport {\n CancellablePromise,\n McsClient,\n MediaCategory,\n} from \"@twilio/mcs-client\";\nimport { Media, MediaState } from \"./media\";\nimport { Participant } from \"./participant\";\nimport {\n AggregatedDeliveryDescriptor,\n AggregatedDeliveryReceipt,\n} from \"./aggregated-delivery-receipt\";\nimport {\n validateTypes,\n validateTypesAsync,\n nonEmptyString,\n nonEmptyArray,\n} from \"@twilio/declarative-type-validator\";\nimport { json } from \"./interfaces/rules\";\nimport { Network } from \"./services/network\";\nimport { RestPaginator } from \"./rest-paginator\";\nimport { DetailedDeliveryReceipt } from \"./detailed-delivery-receipt\";\nimport { Paginator } from \"./interfaces/paginator\";\nimport { Configuration } from \"./configuration\";\nimport { CommandExecutor } from \"./command-executor\";\nimport { EditMessageRequest } from \"./interfaces/commands/edit-message\";\nimport { MessageResponse } from \"./interfaces/commands/message-response\";\nimport { ReplayEventEmitter } from \"@twilio/replay-event-emitter\";\nimport isEqual from \"lodash.isequal\";\nimport { ContentData, parseVariant } from \"./content-template\";\nimport {\n ChannelMetadata,\n ChannelMetadataClient,\n} from \"./channel-metadata-client\";\nimport { JSONValue } from \"@twilio/shared\";\n\ntype MessageEvents = {\n updated: (data: {\n message: Message;\n updateReasons: MessageUpdateReason[];\n }) => void;\n};\n\nconst log = Logger.scope(\"Message\");\nconst XHR =\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n global[\"XMLHttpRequest\"] || require(\"xmlhttprequest\").XMLHttpRequest;\n\ninterface MessageState {\n sid: string;\n index: number;\n author: string | null;\n subject: string | null;\n contentSid: string | null;\n body: string | null;\n dateUpdated: Date | null;\n lastUpdatedBy: string | null;\n attributes: JSONValue;\n timestamp: Date | null;\n type: MessageType;\n medias: Media[] | null;\n participantSid: string | null;\n aggregatedDeliveryReceipt: AggregatedDeliveryReceipt | null;\n hasChannelMetadata: boolean;\n}\n\ninterface MessageServices {\n mcsClient: McsClient;\n network: Network;\n commandExecutor: CommandExecutor;\n channelMetadataClient: ChannelMetadataClient;\n}\n\ninterface MessageLinks {\n self: string;\n conversation: string;\n messages_receipts: string;\n}\n\n/**\n * The reason for the `updated` event being emitted by a message.\n */\ntype MessageUpdateReason =\n | \"body\"\n | \"lastUpdatedBy\"\n | \"dateCreated\"\n | \"dateUpdated\"\n | \"attributes\"\n | \"author\"\n | \"deliveryReceipt\"\n | \"subject\";\n\n/**\n * Type of a message.\n */\ntype MessageType = \"text\" | \"media\";\n\ninterface MessageUpdatedEventArgs {\n message: Message;\n updateReasons: MessageUpdateReason[];\n}\n\nexport interface MessageData {\n sid: string;\n text?: string;\n type?: MessageType;\n author: string | null;\n subject: string | null;\n contentSid: string | null;\n lastUpdatedBy?: string | null;\n attributes?: JSONValue;\n dateUpdated: string;\n timestamp?: string;\n medias: MediaState[] | null;\n media: MediaState | null;\n memberSid?: string;\n delivery?: AggregatedDeliveryDescriptor;\n channelMetadata?: boolean;\n}\n\n/**\n * A message in a conversation.\n */\nclass Message extends ReplayEventEmitter<MessageEvents> {\n /**\n * Conversation that the message is in.\n */\n public readonly conversation: Conversation;\n\n private readonly links: MessageLinks;\n private readonly configuration: Configuration;\n private readonly services: MessageServices;\n\n private state: MessageState;\n\n /**\n * @internal\n */\n constructor(\n index: number,\n data: MessageData,\n conversation: Conversation,\n links: MessageLinks,\n configuration: Configuration,\n services: MessageServices\n ) {\n super();\n\n this.conversation = conversation;\n\n this.links = links;\n this.configuration = configuration;\n this.services = services;\n\n this.state = {\n sid: data.sid,\n index: index,\n author: data.author,\n subject: data.subject,\n contentSid: data.contentSid,\n body: data.text ?? null,\n timestamp: data.timestamp ? new Date(data.timestamp) : null,\n dateUpdated: data.dateUpdated ? new Date(data.dateUpdated) : null,\n lastUpdatedBy: data.lastUpdatedBy ?? null,\n attributes: parseAttributes(\n data.attributes,\n `Got malformed attributes for the message ${data.sid}`,\n log\n ),\n type: data.type ?? \"text\",\n medias:\n data.type === \"media\" && data.medias\n ? data.medias.map((m) => new Media(m, this.services))\n : data.type === \"media\" && data.media && !data.medias\n ? [\n new Media(\n { ...data.media, category: \"media\" } as Media,\n this.services\n ),\n ]\n : null,\n participantSid: data.memberSid ?? null,\n aggregatedDeliveryReceipt: data.delivery\n ? new AggregatedDeliveryReceipt(data.delivery)\n : null,\n hasChannelMetadata: data.channelMetadata ?? false,\n };\n }\n\n /**\n * Fired when the properties or the body of the message has been updated.\n *\n * Parameters:\n * 1. object `data` - info object provided with the event. It has the following properties:\n * * {@link Message} message - the message in question\n * * {@link MessageUpdateReason}[] updateReasons - array of reasons for the update\n */\n static readonly updated = \"updated\";\n\n /**\n * The server-assigned unique identifier for the message.\n */\n public get sid(): string {\n return this.state.sid;\n }\n\n /**\n * Name of the user that sent the message.\n */\n public get author(): string | null {\n return this.state.author;\n }\n\n /**\n * Message subject. Used only in email conversations.\n */\n public get subject(): string | null {\n return this.state.subject;\n }\n\n /**\n * Unique identifier of {@link ContentTemplate} for this message.\n */\n public get contentSid(): string | null {\n return this.state.contentSid;\n }\n\n /**\n * Body of the message.\n */\n public get body(): string | null {\n return this.state.body;\n }\n\n /**\n * Date this message was last updated on.\n */\n public get dateUpdated(): Date | null {\n return this.state.dateUpdated;\n }\n\n /**\n * Index of this message in the conversation's list of messages.\n *\n * By design, the message indices may have arbitrary gaps between them,\n * that does not necessarily mean they were deleted or otherwise modified - just that\n * messages may have some non-contiguous indices even if they are being sent immediately one after another.\n *\n * Trying to use indices for some calculations is going to be unreliable.\n *\n * To calculate the number of unread messages, it is better to use the Read Horizon API.\n * See {@link Conversation.getUnreadMessagesCount} for details.\n */\n public get index(): number {\n return this.state.index;\n }\n\n /**\n * Identity of the last user that updated the message.\n */\n public get lastUpdatedBy(): string | null {\n return this.state.lastUpdatedBy;\n }\n\n /**\n * Date this message was created on.\n */\n public get dateCreated(): Date | null {\n return this.state.timestamp;\n }\n\n /**\n * Custom attributes of the message.\n */\n public get attributes(): JSONValue {\n return this.state.attributes;\n }\n\n /**\n * Type of the message.\n */\n public get type(): MessageType {\n return this.state.type;\n }\n\n /**\n * Return all media attachments, except email body/history attachments, without temporary urls.\n */\n public get attachedMedia(): Array<Media> | null {\n return this.getMediaByCategories([\"media\"]);\n }\n\n /**\n * The server-assigned unique identifier of the authoring participant.\n */\n public get participantSid(): string | null {\n return this.state.participantSid;\n }\n\n /**\n * Aggregated information about the message delivery statuses across all participants of a conversation..\n */\n public get aggregatedDeliveryReceipt(): AggregatedDeliveryReceipt | null {\n return this.state.aggregatedDeliveryReceipt;\n }\n\n /**\n * Return a (possibly empty) array of media matching a specific set of categories.\n * Allowed category is so far only 'media'.\n * @param categories Array of categories to match.\n * @returns Array of media descriptors matching given categories.\n */\n public getMediaByCategories(categories: MediaCategory[]): Media[] | null {\n return (this.state.medias ?? []).filter((m) =>\n categories.includes(m.category)\n );\n }\n\n /**\n * Get a media descriptor for an email body attachment of a provided type.\n * Allowed body types are returned in the Conversation.limits().emailBodiesAllowedContentTypes array.\n * @param type Type of email body to request, defaults to `text/plain`.\n */\n @validateTypes([nonEmptyString, \"undefined\"])\n public getEmailBody(type = \"text/plain\"): Media | null {\n return (\n this.getMediaByCategories([\"body\"])\n ?.filter((m) => m.contentType == type)\n .shift() ?? null\n );\n }\n\n /**\n * Get a media descriptor for an email history attachment of a provided type.\n * Allowed body types are returned in the Conversation.limits().emailHistoriesAllowedContentTypes array.\n * @param type Type of email history to request, defaults to `text/plain`.\n */\n @validateTypes([nonEmptyString, \"undefined\"])\n public getEmailHistory(type = \"text/plain\"): Media | null {\n return (\n this.getMediaByCategories([\"history\"])\n ?.filter((m) => m.contentType == type)\n .shift() ?? null\n );\n }\n\n _update(data) {\n const updateReasons: MessageUpdateReason[] = [];\n\n if (\n (data.text || typeof data.text === \"string\") &&\n data.text !== this.state.body\n ) {\n this.state.body = data.text;\n updateReasons.push(\"body\");\n }\n\n if (data.subject && data.subject !== this.state.subject) {\n this.state.subject = data.subject;\n updateReasons.push(\"subject\");\n }\n\n if (data.lastUpdatedBy && data.lastUpdatedBy !== this.state.lastUpdatedBy) {\n this.state.lastUpdatedBy = data.lastUpdatedBy;\n updateReasons.push(\"lastUpdatedBy\");\n }\n\n if (data.author && data.author !== this.state.author) {\n this.state.author = data.author;\n updateReasons.push(\"author\");\n }\n\n if (\n data.dateUpdated &&\n new Date(data.dateUpdated).getTime() !==\n (this.state.dateUpdated && this.state.dateUpdated.getTime())\n ) {\n this.state.dateUpdated = new Date(data.dateUpdated);\n updateReasons.push(\"dateUpdated\");\n }\n\n if (\n data.timestamp &&\n new Date(data.timestamp).getTime() !==\n (this.state.timestamp && this.state.timestamp.getTime())\n ) {\n this.state.timestamp = new Date(data.timestamp);\n updateReasons.push(\"dateCreated\");\n }\n\n const updatedAttributes = parseAttributes(\n data.attributes,\n `Got malformed attributes for the message ${this.sid}`,\n log\n );\n if (!isEqual(this.state.attributes, updatedAttributes)) {\n this.state.attributes = updatedAttributes;\n updateReasons.push(\"attributes\");\n }\n\n const updatedAggregatedDelivery = data.delivery;\n const currentAggregatedDelivery = this.state.aggregatedDeliveryReceipt;\n const isUpdatedAggregateDeliveryValid =\n !!updatedAggregatedDelivery &&\n !!updatedAggregatedDelivery.total &&\n !!updatedAggregatedDelivery.delivered &&\n !!updatedAggregatedDelivery.failed &&\n !!updatedAggregatedDelivery.read &&\n !!updatedAggregatedDelivery.sent &&\n !!updatedAggregatedDelivery.undelivered;\n if (isUpdatedAggregateDeliveryValid) {\n if (!currentAggregatedDelivery) {\n this.state.aggregatedDeliveryReceipt = new AggregatedDeliveryReceipt(\n updatedAggregatedDelivery\n );\n updateReasons.push(\"deliveryReceipt\");\n } else if (\n !currentAggregatedDelivery._isEquals(updatedAggregatedDelivery)\n ) {\n currentAggregatedDelivery._update(updatedAggregatedDelivery);\n updateReasons.push(\"deliveryReceipt\");\n }\n }\n\n if (updateReasons.length > 0) {\n this.emit(\"updated\", { message: this, updateReasons: updateReasons });\n }\n }\n\n /**\n * Get the participant who is the author of the message.\n */\n public async getParticipant(): Promise<Participant> {\n let participant: Participant | null = null;\n if (this.state.participantSid) {\n participant = await this.conversation\n .getParticipantBySid(this.state.participantSid)\n .catch(() => {\n log.debug(\n `Participant with sid \"${this.participantSid}\" not found for message ${this.sid}`\n );\n return null;\n });\n }\n if (!participant && this.state.author) {\n participant = await this.conversation\n .getParticipantByIdentity(this.state.author)\n .catch(() => {\n log.debug(\n `Participant with identity \"${this.author}\" not found for message ${this.sid}`\n );\n return null;\n });\n }\n if (participant) {\n return participant;\n }\n let errorMesage = \"Participant with \";\n if (this.state.participantSid) {\n errorMesage += \"SID '\" + this.state.participantSid + \"' \";\n }\n if (this.state.author) {\n if (this.state.participantSid) {\n errorMesage += \"or \";\n }\n errorMesage += \"identity '\" + this.state.author + \"' \";\n }\n if (errorMesage === \"Participant with \") {\n errorMesage = \"Participant \";\n }\n errorMesage += \"was not found\";\n throw new Error(errorMesage);\n }\n\n /**\n * Get the delivery receipts of the message.\n */\n public async getDetailedDeliveryReceipts(): Promise<\n DetailedDeliveryReceipt[]\n > {\n let paginator: Paginator<DetailedDeliveryReceipt> =\n await this._getDetailedDeliveryReceiptsPaginator();\n let detailedDeliveryReceipts: DetailedDeliveryReceipt[] = paginator.items;\n\n while (paginator.hasNextPage) {\n paginator = await paginator.nextPage();\n detailedDeliveryReceipts = [\n ...detailedDeliveryReceipts,\n ...paginator.items,\n ];\n }\n\n return detailedDeliveryReceipts;\n }\n\n /**\n * Remove the message.\n */\n public async remove(): Promise<Message> {\n await this.services.commandExecutor.mutateResource(\n \"delete\",\n this.links.self\n );\n\n return this;\n }\n\n /**\n * Edit the message body.\n * @param body New body of the message.\n */\n @validateTypesAsync(\"string\")\n public async updateBody(body: string): Promise<Message> {\n await this.services.commandExecutor.mutateResource<\n EditMessageRequest,\n MessageResponse\n >(\"post\", this.links.self, {\n body,\n });\n\n return this;\n }\n\n /**\n * Edit the message attributes.\n * @param attributes New attributes.\n */\n @validateTypesAsync(json)\n public async updateAttributes(attributes: JSONValue): Promise<Message> {\n await this.services.commandExecutor.mutateResource<\n EditMessageRequest,\n MessageResponse\n >(\"post\", this.links.self, {\n attributes:\n typeof attributes !== \"undefined\"\n ? JSON.stringify(attributes)\n : undefined,\n });\n\n return this;\n }\n\n /**\n * Get content URLs for all media attachments in the given set using a single operation.\n * @param contentSet Set of media attachments to query content URLs.\n */\n @validateTypesAsync(nonEmptyArray(\"media\", Media))\n public getTemporaryContentUrlsForMedia(\n contentSet: Media[]\n ): CancellablePromise<Map<string, string>> {\n // We ignore existing mcsMedia members of each of the media entries.\n // Instead we just collect their sids and pull new descriptors from a mediaSet GET endpoint.\n const sids = contentSet.map((m) => m.sid);\n return this.getTemporaryContentUrlsForMediaSids(sids);\n }\n\n /**\n * Get content URLs for all media attachments in the given set of media sids using a single operation.\n * @param mediaSids Set of media sids to query for the content URL.\n */\n @validateTypesAsync(nonEmptyArray(\"strings\", \"string\"))\n public getTemporaryContentUrlsForMediaSids(\n mediaSids: string[]\n ): CancellablePromise<Map<string, string>> {\n return new CancellablePromise(async (resolve, reject, onCancel) => {\n const mediaGetRequest = this.services.mcsClient.mediaSetGetContentUrls(\n mediaSids ?? []\n );\n\n if (!this.services.mcsClient || !mediaSids) {\n reject(new Error(\"Media Content Service is unavailable\"));\n return;\n }\n\n onCancel(() => {\n mediaGetRequest.cancel();\n });\n\n try {\n const urls = await mediaGetRequest;\n resolve(urls);\n } catch (e) {\n reject(e);\n }\n });\n }\n\n /**\n * Get content URLs for all media attached to the message.\n */\n public getTemporaryContentUrlsForAttachedMedia(): CancellablePromise<\n Map<string, string>\n > {\n const media = this.attachedMedia;\n const sids = media?.map((m) => m.sid) ?? [];\n return this.getTemporaryContentUrlsForMediaSids(sids);\n }\n\n private async _getDetailedDeliveryReceiptsPaginator(options?: {\n pageToken?: string;\n pageSize?: number;\n }): Promise<Paginator<DetailedDeliveryReceipt>> {\n const messagesReceiptsUrl = this.configuration.links.messagesReceipts\n .replace(\"%s\", this.conversation.sid)\n .replace(\"%s\", this.sid);\n const url = new UriBuilder(messagesReceiptsUrl)\n .arg(\"PageToken\", options?.pageToken as string)\n .arg(\"PageSize\", options?.pageSize as number)\n .build();\n const response = await this.services.network.get(url);\n\n return new RestPaginator<DetailedDeliveryReceipt>(\n response.body.delivery_receipts.map(\n (x) => new DetailedDeliveryReceipt(x)\n ),\n (pageToken, pageSize) =>\n this._getDetailedDeliveryReceiptsPaginator({ pageToken, pageSize }),\n response.body.meta.previous_token,\n response.body.meta.next_token\n );\n }\n\n /**\n * Get the {@link ContentData} for this message. Resolves to `null` when\n * {@link Message.contentSid} is null.\n */\n public getContentData(): CancellablePromise<ContentData | null> {\n return new CancellablePromise(async (resolve, reject, onCancel) => {\n if (this.state.contentSid === null) {\n resolve(null);\n return;\n }\n\n const bodies = this.getMediaByCategories([\"body\"]);\n\n if (bodies === null) {\n resolve(null);\n return;\n }\n\n const twilioPrefix = \"application/x-vnd.com.twilio.rich.\";\n const filteredMedias = bodies.filter((media) =>\n media.contentType.startsWith(twilioPrefix)\n );\n\n if (filteredMedias.length === 0) {\n resolve(null);\n return;\n }\n\n const contentMedia = filteredMedias[0];\n const urlPromise = contentMedia.getContentTemporaryUrl();\n\n onCancel(() => {\n urlPromise.cancel();\n });\n\n let url: string | null;\n\n try {\n url = await urlPromise;\n } catch (e) {\n reject(e);\n return;\n }\n\n if (url === null) {\n resolve(null);\n return;\n }\n\n const jsonStringPromise = new Promise<string>((resolve, reject) => {\n let isCancelled = false;\n const xhr = new XHR();\n xhr.open(\"GET\", url ?? \"\", true);\n xhr.responseType = \"text\";\n xhr.onreadystatechange = () => {\n if (xhr.readyState !== 4 || isCancelled) {\n return;\n }\n resolve(xhr.responseText);\n };\n xhr.onerror = () => {\n reject(xhr.statusText);\n };\n onCancel(() => {\n isCancelled = true;\n xhr.abort();\n reject(new Error(\"XHR has been aborted\"));\n });\n xhr.send();\n });\n\n let json;\n\n try {\n const jsonString = await jsonStringPromise;\n json = JSON.parse(jsonString);\n } catch (e) {\n reject(e);\n return;\n }\n\n const dataType = contentMedia.contentType\n .replace(twilioPrefix, \"\")\n .replace(\".\", \"/\");\n\n resolve(parseVariant(dataType, json.data));\n });\n }\n\n /**\n * Get the {@link ChannelMetadata} for this message. Resolves to `null` if\n * the message doesn't have any channel metadata.\n */\n public async getChannelMetadata(): Promise<ChannelMetadata | null> {\n if (!this.state.hasChannelMetadata) {\n return null;\n }\n\n return await this.services.channelMetadataClient.getChannelMetadata(\n this.conversation.sid,\n this.sid\n );\n }\n}\n\nexport {\n Message,\n MessageServices,\n MessageType,\n MessageUpdateReason,\n MessageUpdatedEventArgs,\n};\n"],"names":["Logger","ReplayEventEmitter","index","parseAttributes","Media","AggregatedDeliveryReceipt","isEqual","CancellablePromise","UriBuilder","RestPaginator","DetailedDeliveryReceipt","parseVariant","__decorate","validateTypes","nonEmptyString","validateTypesAsync","json","nonEmptyArray"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAM,GAAG,GAAGA,aAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AACpC,MAAM,GAAG;AACP;AACA,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAwC,CAAC;AA0EvE;;AAEG;AACH,MAAM,OAAQ,SAAQC,qCAAiC,CAAA;AAYrD;;AAEG;IACH,WACE,CAAAC,OAAa,EACb,IAAiB,EACjB,YAA0B,EAC1B,KAAmB,EACnB,aAA4B,EAC5B,QAAyB,EAAA;;AA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AA;AAMjD,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,iBAAA,EAAA,IAAA,CAAA,CAAA;AAwKYQ,oBAAA,CAAA;IADZG,2CAAkB,CAAC,QAAQ,CAAC;;;;AAU5B,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,YAAA,EAAA,IAAA,CAAA,CAAA;AAOYH,oBAAA,CAAA;IADZG,2CAAkB,CAACC,UAAI,CAAC;;;;AAaxB,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,kBAAA,EAAA,IAAA,CAAA,CAAA;AAMDJ,oBAAA,CAAA;AAAC,IAAAG,2CAAkB,CAACE,sCAAa,CAAC,OAAO,EAAEb,WAAK,CAAC,CAAC;;;8CAG/CG,4BAAkB,CAAA;AAKpB,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,iCAAA,EAAA,IAAA,CAAA,CAAA;AAMDK,oBAAA,CAAA;AAAC,IAAAG,2CAAkB,CAACE,sCAAa,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;;;8CAGpDV,4BAAkB,CAAA;AAsBpB,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,qCAAA,EAAA,IAAA,CAAA;;;;"}
@@ -0,0 +1,265 @@
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
+ 'use strict';
130
+
131
+ var global =
132
+ typeof global !== "undefined"
133
+ ? global
134
+ : typeof self !== "undefined"
135
+ ? self
136
+ : typeof window !== "undefined"
137
+ ? window
138
+ : {};
139
+
140
+ Object.defineProperty(exports, '__esModule', { value: true });
141
+
142
+ class QuickLRU {
143
+ constructor(options = {}) {
144
+ if (!(options.maxSize && options.maxSize > 0)) {
145
+ throw new TypeError('`maxSize` must be a number greater than 0');
146
+ }
147
+
148
+ this.maxSize = options.maxSize;
149
+ this.onEviction = options.onEviction;
150
+ this.cache = new Map();
151
+ this.oldCache = new Map();
152
+ this._size = 0;
153
+ }
154
+
155
+ _set(key, value) {
156
+ this.cache.set(key, value);
157
+ this._size++;
158
+
159
+ if (this._size >= this.maxSize) {
160
+ this._size = 0;
161
+
162
+ if (typeof this.onEviction === 'function') {
163
+ for (const [key, value] of this.oldCache.entries()) {
164
+ this.onEviction(key, value);
165
+ }
166
+ }
167
+
168
+ this.oldCache = this.cache;
169
+ this.cache = new Map();
170
+ }
171
+ }
172
+
173
+ get(key) {
174
+ if (this.cache.has(key)) {
175
+ return this.cache.get(key);
176
+ }
177
+
178
+ if (this.oldCache.has(key)) {
179
+ const value = this.oldCache.get(key);
180
+ this.oldCache.delete(key);
181
+ this._set(key, value);
182
+ return value;
183
+ }
184
+ }
185
+
186
+ set(key, value) {
187
+ if (this.cache.has(key)) {
188
+ this.cache.set(key, value);
189
+ } else {
190
+ this._set(key, value);
191
+ }
192
+
193
+ return this;
194
+ }
195
+
196
+ has(key) {
197
+ return this.cache.has(key) || this.oldCache.has(key);
198
+ }
199
+
200
+ peek(key) {
201
+ if (this.cache.has(key)) {
202
+ return this.cache.get(key);
203
+ }
204
+
205
+ if (this.oldCache.has(key)) {
206
+ return this.oldCache.get(key);
207
+ }
208
+ }
209
+
210
+ delete(key) {
211
+ const deleted = this.cache.delete(key);
212
+ if (deleted) {
213
+ this._size--;
214
+ }
215
+
216
+ return this.oldCache.delete(key) || deleted;
217
+ }
218
+
219
+ clear() {
220
+ this.cache.clear();
221
+ this.oldCache.clear();
222
+ this._size = 0;
223
+ }
224
+
225
+ * keys() {
226
+ for (const [key] of this) {
227
+ yield key;
228
+ }
229
+ }
230
+
231
+ * values() {
232
+ for (const [, value] of this) {
233
+ yield value;
234
+ }
235
+ }
236
+
237
+ * [Symbol.iterator]() {
238
+ for (const item of this.cache) {
239
+ yield item;
240
+ }
241
+
242
+ for (const item of this.oldCache) {
243
+ const [key] = item;
244
+ if (!this.cache.has(key)) {
245
+ yield item;
246
+ }
247
+ }
248
+ }
249
+
250
+ get size() {
251
+ let oldCacheSize = 0;
252
+ for (const key of this.oldCache.keys()) {
253
+ if (!this.cache.has(key)) {
254
+ oldCacheSize++;
255
+ }
256
+ }
257
+
258
+ return Math.min(this._size + oldCacheSize, this.maxSize);
259
+ }
260
+ }
261
+
262
+ var quickLru = QuickLRU;
263
+
264
+ exports["default"] = quickLru;
265
+ //# sourceMappingURL=index.js.map