@twilio/conversations 3.0.0-rc.9 → 3.0.1-rc.102

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 (88) hide show
  1. package/README.md +38 -28
  2. package/builds/browser.js +1659 -264
  3. package/builds/browser.js.map +1 -1
  4. package/builds/lib.d.ts +650 -25
  5. package/builds/lib.js +1650 -264
  6. package/builds/lib.js.map +1 -1
  7. package/builds/twilio-conversations.js +4300 -1842
  8. package/builds/twilio-conversations.min.js +1 -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 +70 -10
  14. package/dist/client.js.map +1 -1
  15. package/dist/command-executor.js +48 -6
  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 +59 -16
  24. package/dist/conversation.js.map +1 -1
  25. package/dist/data/conversations.js +25 -3
  26. package/dist/data/conversations.js.map +1 -1
  27. package/dist/data/messages.js +23 -6
  28. package/dist/data/messages.js.map +1 -1
  29. package/dist/data/participants.js +17 -8
  30. package/dist/data/participants.js.map +1 -1
  31. package/dist/data/users.js +9 -0
  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 +14 -0
  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 +156 -12
  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 +11 -2
  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 +9 -0
  60. package/dist/rest-paginator.js.map +1 -1
  61. package/dist/services/network.js +9 -0
  62. package/dist/services/network.js.map +1 -1
  63. package/dist/services/typing-indicator.js +9 -0
  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/assets/js/search.js +1 -1
  74. package/docs/classes/AggregatedDeliveryReceipt.html +1 -1
  75. package/docs/classes/ChannelMetadata.html +3050 -0
  76. package/docs/classes/Client.html +64 -25
  77. package/docs/classes/ContentTemplate.html +3116 -0
  78. package/docs/classes/ContentTemplateVariable.html +3116 -0
  79. package/docs/classes/Conversation.html +14 -9
  80. package/docs/classes/Message.html +76 -5
  81. package/docs/classes/MessageBuilder.html +41 -0
  82. package/docs/classes/Participant.html +2 -2
  83. package/docs/index.html +849 -25
  84. package/docs/interfaces/ClientOptions.html +16 -0
  85. package/docs/modules.html +848 -24
  86. package/package.json +18 -14
  87. package/CHANGELOG.md +0 -509
  88. package/dist/interfaces/attributes.js.map +0 -1
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -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
  class NotificationTypes {
@@ -1 +1 @@
1
- {"version":3,"file":"notification-types.js","sources":["../../src/interfaces/notification-types.ts"],"sourcesContent":["class NotificationTypes {\n static readonly TYPING_INDICATOR = \"twilio.ipmsg.typing_indicator\";\n static readonly NEW_MESSAGE = \"twilio.conversations.new_message\";\n static readonly ADDED_TO_CONVERSATION =\n \"twilio.conversations.added_to_conversation\";\n // static readonly INVITED_TO_CHANNEL = 'twilio.channel.invited_to_channel';\n static readonly REMOVED_FROM_CONVERSATION =\n \"twilio.conversations.removed_from_conversation\";\n static readonly CONSUMPTION_UPDATE = \"twilio.channel.consumption_update\";\n}\n\nexport { NotificationTypes };\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAM,iBAAiB,CAAA;;AACL,iBAAgB,CAAA,gBAAA,GAAG,+BAA+B,CAAC;AACnD,iBAAW,CAAA,WAAA,GAAG,kCAAkC,CAAC;AACjD,iBAAqB,CAAA,qBAAA,GACnC,4CAA4C,CAAC;AAC/C;AACgB,iBAAyB,CAAA,yBAAA,GACvC,gDAAgD,CAAC;AACnC,iBAAkB,CAAA,kBAAA,GAAG,mCAAmC;;;;"}
1
+ {"version":3,"file":"notification-types.js","sources":["../../src/interfaces/notification-types.ts"],"sourcesContent":["class NotificationTypes {\n static readonly TYPING_INDICATOR = \"twilio.ipmsg.typing_indicator\";\n static readonly NEW_MESSAGE = \"twilio.conversations.new_message\";\n static readonly ADDED_TO_CONVERSATION =\n \"twilio.conversations.added_to_conversation\";\n // static readonly INVITED_TO_CHANNEL = 'twilio.channel.invited_to_channel';\n static readonly REMOVED_FROM_CONVERSATION =\n \"twilio.conversations.removed_from_conversation\";\n static readonly CONSUMPTION_UPDATE = \"twilio.channel.consumption_update\";\n}\n\nexport { NotificationTypes };\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAM,iBAAiB,CAAA;;AACL,iBAAgB,CAAA,gBAAA,GAAG,+BAA+B,CAAC;AACnD,iBAAW,CAAA,WAAA,GAAG,kCAAkC,CAAC;AACjD,iBAAqB,CAAA,qBAAA,GACnC,4CAA4C,CAAC;AAC/C;AACgB,iBAAyB,CAAA,yBAAA,GACvC,gDAAgD,CAAC;AACnC,iBAAkB,CAAA,kBAAA,GAAG,mCAAmC;;;;"}
@@ -128,20 +128,39 @@ 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 declarativeTypeValidator = require('@twilio/declarative-type-validator');
134
143
 
135
- // Any JSON value
136
- const attributesValidator = declarativeTypeValidator.custom((value) => [
144
+ const json = declarativeTypeValidator.custom((value) => [
137
145
  ["string", "number", "boolean", "object"].includes(typeof value),
138
146
  "a JSON type",
139
147
  ]);
140
- const optionalAttributesValidator = declarativeTypeValidator.custom((value) => [
148
+ const optionalJson = declarativeTypeValidator.custom((value) => [
141
149
  ["undefined", "string", "number", "boolean", "object"].includes(typeof value),
142
150
  "an optional JSON type",
143
151
  ]);
144
-
145
- exports.attributesValidator = attributesValidator;
146
- exports.optionalAttributesValidator = optionalAttributesValidator;
147
- //# sourceMappingURL=attributes.js.map
152
+ const sendMediaOptions = declarativeTypeValidator.objectSchema("send media options", {
153
+ contentType: [declarativeTypeValidator.literal(null), "string"],
154
+ filename: ["string", "undefined"],
155
+ media: [
156
+ declarativeTypeValidator.literal("null"),
157
+ "string",
158
+ ...(typeof Buffer === "function" ? [Buffer] : []),
159
+ ...(typeof Blob === "function" ? [Blob] : []),
160
+ ],
161
+ });
162
+
163
+ exports.json = json;
164
+ exports.optionalJson = optionalJson;
165
+ exports.sendMediaOptions = sendMediaOptions;
166
+ //# sourceMappingURL=rules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rules.js","sources":["../../src/interfaces/rules.ts"],"sourcesContent":["import {\n custom,\n literal,\n objectSchema,\n} from \"@twilio/declarative-type-validator\";\n\nexport const json = custom((value) => [\n [\"string\", \"number\", \"boolean\", \"object\"].includes(typeof value),\n \"a JSON type\",\n]);\n\nexport const optionalJson = custom((value) => [\n [\"undefined\", \"string\", \"number\", \"boolean\", \"object\"].includes(typeof value),\n \"an optional JSON type\",\n]);\n\nexport const sendMediaOptions = objectSchema(\"send media options\", {\n contentType: [literal(null), \"string\"],\n filename: [\"string\", \"undefined\"],\n media: [\n literal(\"null\"),\n \"string\",\n ...(typeof Buffer === \"function\" ? [Buffer] : []),\n ...(typeof Blob === \"function\" ? [Blob] : []),\n ],\n});\n"],"names":["custom","objectSchema","literal"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMa,MAAA,IAAI,GAAGA,+BAAM,CAAC,CAAC,KAAK,KAAK;AACpC,IAAA,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,KAAK,CAAC;IAChE,aAAa;AACd,CAAA,EAAE;AAEU,MAAA,YAAY,GAAGA,+BAAM,CAAC,CAAC,KAAK,KAAK;AAC5C,IAAA,CAAC,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,KAAK,CAAC;IAC7E,uBAAuB;AACxB,CAAA,EAAE;AAEU,MAAA,gBAAgB,GAAGC,qCAAY,CAAC,oBAAoB,EAAE;IACjE,WAAW,EAAE,CAACC,gCAAO,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC;AACtC,IAAA,QAAQ,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC;AACjC,IAAA,KAAK,EAAE;QACLA,gCAAO,CAAC,MAAM,CAAC;QACf,QAAQ;AACR,QAAA,IAAI,OAAO,MAAM,KAAK,UAAU,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;AACjD,QAAA,IAAI,OAAO,IAAI,KAAK,UAAU,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;AAC9C,KAAA;AACF,CAAA;;;;;;"}
package/dist/logger.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 loglevelLog = require('loglevel');
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sources":["../src/logger.ts"],"sourcesContent":["import * as loglevelLog from \"loglevel\";\nimport { LogLevelDesc } from \"loglevel\";\n\nfunction prepareLine(prefix, args) {\n return [`${new Date().toISOString()} Conversations ${prefix}:`].concat(\n Array.from(args)\n );\n}\n\nconst log: loglevelLog.Logger = loglevelLog.getLogger(\"twilio-conversations\"); // twilio-conversations is used by Flex SDK. Please DO NOT change\n\nclass Logger {\n private prefix = \"\";\n\n private constructor(prefix: string) {\n this.prefix =\n prefix !== null && prefix !== undefined && prefix.length > 0\n ? prefix + \" \"\n : \"\";\n }\n\n static scope(prefix: string): Logger {\n return new Logger(prefix);\n }\n\n setLevel(level: LogLevelDesc) {\n log.setLevel(level);\n }\n\n static setLevel(level: LogLevelDesc) {\n log.setLevel(level);\n }\n\n trace(...args) {\n log.trace.apply(null, prepareLine(this.prefix + \"T\", args));\n }\n\n debug(...args) {\n log.debug.apply(null, prepareLine(this.prefix + \"D\", args));\n }\n\n info(...args) {\n log.info.apply(null, prepareLine(this.prefix + \"I\", args));\n }\n\n warn(...args) {\n log.warn.apply(null, prepareLine(this.prefix + \"W\", args));\n }\n\n error(...args) {\n log.error.apply(null, prepareLine(this.prefix + \"E\", args));\n }\n\n static trace(...args) {\n log.trace.apply(null, prepareLine(\"T\", args));\n }\n\n static debug(...args) {\n log.debug.apply(null, prepareLine(\"D\", args));\n }\n\n static info(...args) {\n log.info.apply(null, prepareLine(\"I\", args));\n }\n\n static warn(...args) {\n log.warn.apply(null, prepareLine(\"W\", args));\n }\n\n static error(...args) {\n log.error.apply(null, prepareLine(\"E\", args));\n }\n}\n\nexport { Logger };\n"],"names":["loglevelLog"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,SAAS,WAAW,CAAC,MAAM,EAAE,IAAI,EAAA;IAC/B,OAAO,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA,eAAA,EAAkB,MAAM,CAAA,CAAA,CAAG,CAAC,CAAC,MAAM,CACpE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CACjB,CAAC;AACJ,CAAC;AAED,MAAM,GAAG,GAAuBA,sBAAW,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAC;AAE9E,MAAM,MAAM,CAAA;AAGV,IAAA,WAAA,CAAoB,MAAc,EAAA;QAF1B,IAAM,CAAA,MAAA,GAAG,EAAE,CAAC;AAGlB,QAAA,IAAI,CAAC,MAAM;YACT,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;kBACxD,MAAM,GAAG,GAAG;kBACZ,EAAE,CAAC;KACV;IAED,OAAO,KAAK,CAAC,MAAc,EAAA;AACzB,QAAA,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC;KAC3B;AAED,IAAA,QAAQ,CAAC,KAAmB,EAAA;AAC1B,QAAA,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;KACrB;IAED,OAAO,QAAQ,CAAC,KAAmB,EAAA;AACjC,QAAA,GAAG,CAAC,QAAQ,CAAC,KAAK,C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AAC,GAAG,IAAI,EAAA;AACjB,QAAA,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;KAC9C;AAED,IAAA,OAAO,IAAI,CAAC,GAAG,IAAI,EAAA;AACjB,QAAA,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;KAC9C;AAED,IAAA,OAAO,KAAK,CAAC,GAAG,IAAI,EAAA;AAClB,QAAA,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;KAC/C;AACF;;;;"}
1
+ {"version":3,"file":"logger.js","sources":["../src/logger.ts"],"sourcesContent":["import * as loglevelLog from \"loglevel\";\nimport { LogLevelDesc } from \"loglevel\";\n\nfunction prepareLine(prefix, args) {\n return [`${new Date().toISOString()} Conversations ${prefix}:`].concat(\n Array.from(args)\n );\n}\n\nconst log: loglevelLog.Logger = loglevelLog.getLogger(\"twilio-conversations\"); // twilio-conversations is used by Flex SDK. Please DO NOT change\n\nclass Logger {\n private prefix = \"\";\n\n private constructor(prefix: string) {\n this.prefix =\n prefix !== null && prefix !== undefined && prefix.length > 0\n ? prefix + \" \"\n : \"\";\n }\n\n static scope(prefix: string): Logger {\n return new Logger(prefix);\n }\n\n setLevel(level: LogLevelDesc) {\n log.setLevel(level);\n }\n\n static setLevel(level: LogLevelDesc) {\n log.setLevel(level);\n }\n\n trace(...args) {\n log.trace.apply(null, prepareLine(this.prefix + \"T\", args));\n }\n\n debug(...args) {\n log.debug.apply(null, prepareLine(this.prefix + \"D\", args));\n }\n\n info(...args) {\n log.info.apply(null, prepareLine(this.prefix + \"I\", args));\n }\n\n warn(...args) {\n log.warn.apply(null, prepareLine(this.prefix + \"W\", args));\n }\n\n error(...args) {\n log.error.apply(null, prepareLine(this.prefix + \"E\", args));\n }\n\n static trace(...args) {\n log.trace.apply(null, prepareLine(\"T\", args));\n }\n\n static debug(...args) {\n log.debug.apply(null, prepareLine(\"D\", args));\n }\n\n static info(...args) {\n log.info.apply(null, prepareLine(\"I\", args));\n }\n\n static warn(...args) {\n log.warn.apply(null, prepareLine(\"W\", args));\n }\n\n static error(...args) {\n log.error.apply(null, prepareLine(\"E\", args));\n }\n}\n\nexport { Logger };\n"],"names":["loglevelLog"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,SAAS,WAAW,CAAC,MAAM,EAAE,IAAI,EAAA;IAC/B,OAAO,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA,eAAA,EAAkB,MAAM,CAAA,CAAA,CAAG,CAAC,CAAC,MAAM,CACpE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CACjB,CAAC;AACJ,CAAC;AAED,MAAM,GAAG,GAAuBA,sBAAW,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAC;AAE9E,MAAM,MAAM,CAAA;AAGV,IAAA,WAAA,CAAoB,MAAc,EAAA;QAF1B,IAAM,CAAA,MAAA,GAAG,EAAE,CAAC;AAGlB,QAAA,IAAI,CAAC,MAAM;YACT,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;kBACxD,MAAM,GAAG,GAAG;kBACZ,EAAE,CAAC;KACV;IAED,OAAO,KAAK,CAAC,MAAc,EAAA;AACzB,QAAA,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC;KAC3B;AAED,IAAA,QAAQ,CAAC,KAAmB,EAAA;AAC1B,QAAA,GAAG,CAAC,QAAQ,CAAC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AC,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;KAC/C;AAED,IAAA,OAAO,IAAI,CAAC,GAAG,IAAI,EAAA;AACjB,QAAA,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;KAC9C;AAED,IAAA,OAAO,IAAI,CAAC,GAAG,IAAI,EAAA;AACjB,QAAA,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;KAC9C;AAED,IAAA,OAAO,KAAK,CAAC,GAAG,IAAI,EAAA;AAClB,QAAA,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;KAC/C;AACF;;;;"}
package/dist/media.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 mcsClient = require('@twilio/mcs-client');
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,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;YACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,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,CAAC;KACvB;AAED;;AAEG;AACH,IAAA,IAAW,QAAQ,GAAA;AACjB,QAAA,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;KAC5B;AAED;;AAEG;AACH,IAAA,IAAW,WAAW,GAAA;AACpB,QAAA,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC;KAC/B;AAED;;AAEG;AACH,IAAA,IAAW,IAAI,GAAA;AACb,QAAA,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;KACxB;AAED;;AAEG;AACH,IAAA,IAAW,QAAQ,GAAA;A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E;gBAC3B,QAAQ,CAAC,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;gBAEjC,IAAI;AACF,oBAAA,IAAI,CAAC,QAAQ,GAAG,MAAM,OAAO,CAAC;AAC9B,oBAAA,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACxB,iBAAA;AAAC,gBAAA,OAAO,CAAC,EAAE;oBACV,MAAM,CAAC,CAAC,CAAC,CAAC;AACX,iBAAA;gBACD,OAAO;AACR,aAAA;AAED,YAAA,MAAM,CAAC,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC,CAAC;AAC5D,SAAC,CAAC,CAAC;KACJ;AACF;;;;"}
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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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
 
142
+ var tslib_es6 = require('./node_modules/tslib/tslib.es6.js');
133
143
  var unsentMessage = require('./unsent-message.js');
144
+ var contentTemplate = require('./content-template.js');
145
+ var declarativeTypeValidator = require('@twilio/declarative-type-validator');
146
+ var rules = require('./interfaces/rules.js');
134
147
 
135
148
  /**
136
149
  * Message builder. Allows the message to be built and sent via method chaining.
@@ -199,6 +212,25 @@ class MessageBuilder {
199
212
  this.emailHistories.set(contentType, history);
200
213
  return this;
201
214
  }
215
+ /**
216
+ * Adds {@link ContentTemplate} SID for the message alongside optional
217
+ * variables. When no variables provided, the default values will be used.
218
+ *
219
+ * Adding the content SID converts the message to a rich message. In this
220
+ * case, other fields are ignored and the message is sent using the content
221
+ * from the the {@link ContentTemplate}.
222
+ *
223
+ * Use {@link Client.getContentTemplates} to request all available
224
+ * {@link ContentTemplate}s.
225
+ *
226
+ * @param contentSid SID of the {@link ContentTemplate}
227
+ * @param variables Custom variables to resolve the template.
228
+ */
229
+ setContentTemplate(contentSid, contentVariables = []) {
230
+ this.message.contentSid = contentSid;
231
+ this.message.contentVariables = contentVariables;
232
+ return this;
233
+ }
202
234
  /**
203
235
  * Adds media to the message.
204
236
  * @param payload Media to add.
@@ -256,13 +288,52 @@ class MessageBuilder {
256
288
  buildAndSend() {
257
289
  return this.build().send();
258
290
  }
259
- getPayloadContentType(payload) {
260
- if (typeof FormData !== "undefined" && payload instanceof FormData) {
261
- return payload.get("Content-Type");
262
- }
263
- return payload.contentType;
264
- }
265
291
  }
292
+ tslib_es6.__decorate([
293
+ declarativeTypeValidator.validateTypes("string"),
294
+ tslib_es6.__metadata("design:type", Function),
295
+ tslib_es6.__metadata("design:paramtypes", [String]),
296
+ tslib_es6.__metadata("design:returntype", MessageBuilder)
297
+ ], MessageBuilder.prototype, "setBody", null);
298
+ tslib_es6.__decorate([
299
+ declarativeTypeValidator.validateTypes("string"),
300
+ tslib_es6.__metadata("design:type", Function),
301
+ tslib_es6.__metadata("design:paramtypes", [String]),
302
+ tslib_es6.__metadata("design:returntype", MessageBuilder)
303
+ ], MessageBuilder.prototype, "setSubject", null);
304
+ tslib_es6.__decorate([
305
+ declarativeTypeValidator.validateTypes(rules.json),
306
+ tslib_es6.__metadata("design:type", Function),
307
+ tslib_es6.__metadata("design:paramtypes", [Object]),
308
+ tslib_es6.__metadata("design:returntype", MessageBuilder)
309
+ ], MessageBuilder.prototype, "setAttributes", null);
310
+ tslib_es6.__decorate([
311
+ declarativeTypeValidator.validateTypes("string", [FormData, rules.sendMediaOptions]),
312
+ tslib_es6.__metadata("design:type", Function),
313
+ tslib_es6.__metadata("design:paramtypes", [String, Object]),
314
+ tslib_es6.__metadata("design:returntype", MessageBuilder)
315
+ ], MessageBuilder.prototype, "setEmailBody", null);
316
+ tslib_es6.__decorate([
317
+ declarativeTypeValidator.validateTypes("string", [FormData, rules.sendMediaOptions]),
318
+ tslib_es6.__metadata("design:type", Function),
319
+ tslib_es6.__metadata("design:paramtypes", [String, Object]),
320
+ tslib_es6.__metadata("design:returntype", MessageBuilder)
321
+ ], MessageBuilder.prototype, "setEmailHistory", null);
322
+ tslib_es6.__decorate([
323
+ declarativeTypeValidator.validateTypes("string", [
324
+ declarativeTypeValidator.array("content variables", contentTemplate.ContentTemplateVariable),
325
+ "undefined",
326
+ ]),
327
+ tslib_es6.__metadata("design:type", Function),
328
+ tslib_es6.__metadata("design:paramtypes", [String, Array]),
329
+ tslib_es6.__metadata("design:returntype", MessageBuilder)
330
+ ], MessageBuilder.prototype, "setContentTemplate", null);
331
+ tslib_es6.__decorate([
332
+ declarativeTypeValidator.validateTypes([FormData, rules.sendMediaOptions]),
333
+ tslib_es6.__metadata("design:type", Function),
334
+ tslib_es6.__metadata("design:paramtypes", [Object]),
335
+ tslib_es6.__metadata("design:returntype", MessageBuilder)
336
+ ], MessageBuilder.prototype, "addMedia", null);
266
337
 
267
338
  exports.MessageBuilder = MessageBuilder;
268
339
  //# 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;A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AC,IAAI,KAAI;AAChC,YAAA,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;AACjD,SAAC,CAAC,CAAC;QAEH,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,OAAO,KAAI;AACtC,YAAA,IAAI,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 { MessageBuilder };\n"],"names":["UnsentMessage","__decorate","validateTypes","json","sendMediaOptions","array","ContentTemplateVariable"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA;;;;;;;;;;;;;;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;AAEH,IAAA,OAAO,CAAC,IAAY,EAAA;AAClB,QAAA,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;AACzB,QAAA,OAAO,IAAI,CAAC;KACb;AAED;;;AAGG;AAEH,IAAA,UAAU,CAAC,OAAe,EAAA;QACxB,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,GAAG,OAAO,CAAC;AAC5C,QAAA,OAAO,IAAI,CAAC;KACb;AAED;;;AAGG;AAEH,IAAA,aAAa,CAAC,UAAqB,EAAA;AACjC,QAAA,IAAI,CAAC,OAAO,CAAC,UAAU,GAAG,UAAU,CAAC;AAC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,EAAA,cAAA,EAAA,IAAA,CAAA,CAAA;AAQDH,oBAAA,CAAA;IADCC,sCAAa,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAEE,sBAAgB,CAAC,CAAC;;;8CAInD,cAAc,CAAA;AAGhB,CAAA,EAAA,cAAA,CAAA,SAAA,EAAA,iBAAA,EAAA,IAAA,CAAA,CAAA;AAoBDH,oBAAA,CAAA;IAJCC,sCAAa,CAAC,QAAQ,EAAE;AACvB,QAAAG,8BAAK,CAAC,mBAAmB,EAAEC,uCAAuB,CAAC;QACnD,WAAW;KACZ,CAAC;;;8CAIC,cAAc,CAAA;AAIhB,CAAA,EAAA,cAAA,CAAA,SAAA,EAAA,oBAAA,EAAA,IAAA,CAAA,CAAA;AAODL,oBAAA,CAAA;AADC,IAAAC,sCAAa,CAAC,CAAC,QAAQ,EAAEE,sBAAgB,CAAC,CAAC;;;8CACI,cAAc,CAAA;AAc7D,CAAA,EAAA,cAAA,CAAA,SAAA,EAAA,UAAA,EAAA,IAAA,CAAA;;;;"}
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,22 @@ 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 deprecationDecorator = require('@twilio/deprecation-decorator');
155
+ var contentTemplate = require('./content-template.js');
145
156
 
146
157
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
147
158
 
148
159
  var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
149
160
 
150
161
  const log = logger.Logger.scope("Message");
162
+ const XHR =
163
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
164
+ global["XMLHttpRequest"] || {};
151
165
  /**
152
166
  * A message in a conversation.
153
167
  */
@@ -156,7 +170,7 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
156
170
  * @internal
157
171
  */
158
172
  constructor(index$1, data, conversation, links, configuration, services) {
159
- var _a, _b, _c, _d;
173
+ var _a, _b, _c, _d, _e;
160
174
  super();
161
175
  this.conversation = conversation;
162
176
  this.links = links;
@@ -167,6 +181,7 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
167
181
  index: index$1,
168
182
  author: data.author,
169
183
  subject: data.subject,
184
+ contentSid: data.contentSid,
170
185
  body: (_a = data.text) !== null && _a !== void 0 ? _a : null,
171
186
  timestamp: data.timestamp ? new Date(data.timestamp) : null,
172
187
  dateUpdated: data.dateUpdated ? new Date(data.dateUpdated) : null,
@@ -187,6 +202,7 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
187
202
  aggregatedDeliveryReceipt: data.delivery
188
203
  ? new aggregatedDeliveryReceipt.AggregatedDeliveryReceipt(data.delivery)
189
204
  : null,
205
+ hasChannelMetadata: (_e = data.channelMetadata) !== null && _e !== void 0 ? _e : false,
190
206
  };
191
207
  }
192
208
  /**
@@ -207,6 +223,12 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
207
223
  get subject() {
208
224
  return this.state.subject;
209
225
  }
226
+ /**
227
+ * Unique identifier of {@link ContentTemplate} for this message.
228
+ */
229
+ get contentSid() {
230
+ return this.state.contentSid;
231
+ }
210
232
  /**
211
233
  * Body of the message.
212
234
  */
@@ -220,14 +242,15 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
220
242
  return this.state.dateUpdated;
221
243
  }
222
244
  /**
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,
245
+ * Index of this message in the conversation's list of messages.
246
+ *
247
+ * By design, the message indices may have arbitrary gaps between them,
225
248
  * that does not necessarily mean they were deleted or otherwise modified - just that
226
249
  * messages may have some non-contiguous indices even if they are being sent immediately one after another.
227
250
  *
228
251
  * Trying to use indices for some calculations is going to be unreliable.
229
252
  *
230
- * To calculate the number of unread messages it is better to use the read horizon API.
253
+ * To calculate the number of unread messages, it is better to use the Read Horizon API.
231
254
  * See {@link Conversation.getUnreadMessagesCount} for details.
232
255
  */
233
256
  get index() {
@@ -282,6 +305,16 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
282
305
  get aggregatedDeliveryReceipt() {
283
306
  return this.state.aggregatedDeliveryReceipt;
284
307
  }
308
+ /**
309
+ * @deprecated
310
+ * Return a (possibly empty) array of media matching a specific set of categories.
311
+ * Allowed category is so far only 'media'.
312
+ * @param categories Array of categories to match.
313
+ * @returns Array of media descriptors matching given categories.
314
+ */
315
+ getMediaByCategory(categories) {
316
+ return this.getMediaByCategories(categories);
317
+ }
285
318
  /**
286
319
  * Return a (possibly empty) array of media matching a specific set of categories.
287
320
  * Allowed category is so far only 'media'.
@@ -414,16 +447,13 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
414
447
  */
415
448
  async getDetailedDeliveryReceipts() {
416
449
  let paginator = await this._getDetailedDeliveryReceiptsPaginator();
417
- let detailedDeliveryReceipts = [];
418
- while (true) {
450
+ let detailedDeliveryReceipts = paginator.items;
451
+ while (paginator.hasNextPage) {
452
+ paginator = await paginator.nextPage();
419
453
  detailedDeliveryReceipts = [
420
454
  ...detailedDeliveryReceipts,
421
455
  ...paginator.items,
422
456
  ];
423
- if (!paginator.hasNextPage) {
424
- break;
425
- }
426
- paginator = await paginator.nextPage();
427
457
  }
428
458
  return detailedDeliveryReceipts;
429
459
  }
@@ -456,6 +486,24 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
456
486
  });
457
487
  return this;
458
488
  }
489
+ /**
490
+ * @deprecated
491
+ * Get content URLs for all media attachments in the given set using a single operation.
492
+ * @param contentSet Set of media attachments to query content URLs.
493
+ */
494
+ async attachTemporaryUrlsFor(contentSet) {
495
+ // We ignore existing mcsMedia members of each of the media entries.
496
+ // Instead we just collect their sids and pull new descriptors from a mediaSet GET endpoint.
497
+ const sids = contentSet === null || contentSet === void 0 ? void 0 : contentSet.map((m) => m.sid);
498
+ if (this.services.mcsClient && sids) {
499
+ return (await this.services.mcsClient.mediaSetGet(sids)).map((item) => {
500
+ return new media.Media(item, this.services);
501
+ });
502
+ }
503
+ else {
504
+ throw new Error("Media Content Service is unavailable");
505
+ }
506
+ }
459
507
  /**
460
508
  * Get content URLs for all media attachments in the given set using a single operation.
461
509
  * @param contentSet Set of media attachments to query content URLs.
@@ -509,6 +557,90 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
509
557
  const response = await this.services.network.get(url);
510
558
  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
559
  }
560
+ /**
561
+ * Get the {@link ContentData} for this message. Resolves to `null` when
562
+ * {@link Message.contentSid} is null.
563
+ */
564
+ getContentData() {
565
+ return new mcsClient.CancellablePromise(async (resolve, reject, onCancel) => {
566
+ if (this.state.contentSid === null) {
567
+ resolve(null);
568
+ return;
569
+ }
570
+ const bodies = this.getMediaByCategories(["body"]);
571
+ if (bodies === null) {
572
+ resolve(null);
573
+ return;
574
+ }
575
+ const twilioPrefix = "application/x-vnd.com.twilio.rich.";
576
+ const filteredMedias = bodies.filter((media) => media.contentType.startsWith(twilioPrefix));
577
+ if (filteredMedias.length === 0) {
578
+ resolve(null);
579
+ return;
580
+ }
581
+ const contentMedia = filteredMedias[0];
582
+ const urlPromise = contentMedia.getContentTemporaryUrl();
583
+ onCancel(() => {
584
+ urlPromise.cancel();
585
+ });
586
+ let url;
587
+ try {
588
+ url = await urlPromise;
589
+ }
590
+ catch (e) {
591
+ reject(e);
592
+ return;
593
+ }
594
+ if (url === null) {
595
+ resolve(null);
596
+ return;
597
+ }
598
+ const jsonStringPromise = new Promise((resolve, reject) => {
599
+ let isCancelled = false;
600
+ const xhr = new XHR();
601
+ xhr.open("GET", url !== null && url !== void 0 ? url : "", true);
602
+ xhr.responseType = "text";
603
+ xhr.onreadystatechange = () => {
604
+ if (xhr.readyState !== 4 || isCancelled) {
605
+ return;
606
+ }
607
+ resolve(xhr.responseText);
608
+ };
609
+ xhr.onerror = () => {
610
+ reject(xhr.statusText);
611
+ };
612
+ onCancel(() => {
613
+ isCancelled = true;
614
+ xhr.abort();
615
+ reject(new Error("XHR has been aborted"));
616
+ });
617
+ xhr.send();
618
+ });
619
+ let json;
620
+ try {
621
+ const jsonString = await jsonStringPromise;
622
+ json = JSON.parse(jsonString);
623
+ }
624
+ catch (e) {
625
+ reject(e);
626
+ return;
627
+ }
628
+ const dataType = contentMedia.contentType
629
+ .replace(twilioPrefix, "")
630
+ .replace(".", "/");
631
+ resolve(contentTemplate.parseVariant(dataType, json.data));
632
+ });
633
+ }
634
+ /**
635
+ * Get the {@link ChannelMetadata} for this message. Resolves to `null` if
636
+ * the message doesn't have any channel metadata.
637
+ */
638
+ async getChannelMetadata() {
639
+ if (!this.state.hasChannelMetadata) {
640
+ return null;
641
+ }
642
+ return await this.services.channelMetadataClient.getChannelMetadata(this.conversation.sid, this.sid);
643
+ }
512
644
  }
513
645
  /**
514
646
  * Fired when the properties or the body of the message has been updated.
@@ -519,6 +651,12 @@ class Message extends replayEventEmitter.ReplayEventEmitter {
519
651
  * * {@link MessageUpdateReason}[] updateReasons - array of reasons for the update
520
652
  */
521
653
  Message.updated = "updated";
654
+ tslib_es6.__decorate([
655
+ deprecationDecorator.deprecated("getMediaByCategory", "getMediaByCategories"),
656
+ tslib_es6.__metadata("design:type", Function),
657
+ tslib_es6.__metadata("design:paramtypes", [Array]),
658
+ tslib_es6.__metadata("design:returntype", Array)
659
+ ], Message.prototype, "getMediaByCategory", null);
522
660
  tslib_es6.__decorate([
523
661
  declarativeTypeValidator.validateTypes([declarativeTypeValidator.nonEmptyString, "undefined"]),
524
662
  tslib_es6.__metadata("design:type", Function),
@@ -538,11 +676,17 @@ tslib_es6.__decorate([
538
676
  tslib_es6.__metadata("design:returntype", Promise)
539
677
  ], Message.prototype, "updateBody", null);
540
678
  tslib_es6.__decorate([
541
- declarativeTypeValidator.validateTypesAsync(attributes.attributesValidator),
679
+ declarativeTypeValidator.validateTypesAsync(rules.json),
542
680
  tslib_es6.__metadata("design:type", Function),
543
681
  tslib_es6.__metadata("design:paramtypes", [Object]),
544
682
  tslib_es6.__metadata("design:returntype", Promise)
545
683
  ], Message.prototype, "updateAttributes", null);
684
+ tslib_es6.__decorate([
685
+ deprecationDecorator.deprecated("attachTemporaryUrlsFor", "getTemporaryContentUrlsForMedia"),
686
+ tslib_es6.__metadata("design:type", Function),
687
+ tslib_es6.__metadata("design:paramtypes", [Array]),
688
+ tslib_es6.__metadata("design:returntype", Promise)
689
+ ], Message.prototype, "attachTemporaryUrlsFor", null);
546
690
  tslib_es6.__decorate([
547
691
  declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyArray("media", media.Media)),
548
692
  tslib_es6.__metadata("design:type", Function),