@twilio/conversations 2.0.0 → 2.0.1-canary.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.
- package/README.md +4 -12
- package/dist/browser.js +11 -20
- package/dist/browser.js.map +1 -1
- package/dist/docs/index.html +4 -10
- package/dist/docs/modules.html +4 -10
- package/dist/lib/aggregated-delivery-receipt.js +227 -0
- package/dist/lib/aggregated-delivery-receipt.js.map +1 -0
- package/dist/lib/client.js +872 -0
- package/dist/lib/client.js.map +1 -0
- package/dist/lib/command-executor.js +203 -0
- package/dist/lib/command-executor.js.map +1 -0
- package/dist/lib/configuration.js +196 -0
- package/dist/lib/configuration.js.map +1 -0
- package/dist/lib/conversation.js +973 -0
- package/dist/lib/conversation.js.map +1 -0
- package/dist/lib/data/conversations.js +443 -0
- package/dist/lib/data/conversations.js.map +1 -0
- package/dist/lib/data/messages.js +341 -0
- package/dist/lib/data/messages.js.map +1 -0
- package/dist/lib/data/participants.js +313 -0
- package/dist/lib/data/participants.js.map +1 -0
- package/dist/lib/data/users.js +228 -0
- package/dist/lib/data/users.js.map +1 -0
- package/dist/lib/detailed-delivery-receipt.js +154 -0
- package/dist/lib/detailed-delivery-receipt.js.map +1 -0
- package/dist/lib/index.js +167 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/interfaces/notification-types.js +143 -0
- package/dist/lib/interfaces/notification-types.js.map +1 -0
- package/dist/lib/logger.js +190 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/media.js +213 -0
- package/dist/lib/media.js.map +1 -0
- package/dist/lib/message-builder.js +209 -0
- package/dist/lib/message-builder.js.map +1 -0
- package/dist/lib/message.js +450 -0
- package/dist/lib/message.js.map +1 -0
- package/dist/lib/node_modules/tslib/tslib.es6.js +161 -0
- package/dist/lib/node_modules/tslib/tslib.es6.js.map +1 -0
- package/dist/lib/packages/conversations/package.json.js +136 -0
- package/dist/lib/packages/conversations/package.json.js.map +1 -0
- package/dist/lib/participant.js +346 -0
- package/dist/lib/participant.js.map +1 -0
- package/dist/lib/push-notification.js +152 -0
- package/dist/lib/push-notification.js.map +1 -0
- package/dist/lib/rest-paginator.js +175 -0
- package/dist/lib/rest-paginator.js.map +1 -0
- package/dist/lib/services/network.js +205 -0
- package/dist/lib/services/network.js.map +1 -0
- package/dist/lib/services/typing-indicator.js +235 -0
- package/dist/lib/services/typing-indicator.js.map +1 -0
- package/dist/lib/unsent-message.js +159 -0
- package/dist/lib/unsent-message.js.map +1 -0
- package/dist/lib/user.js +392 -0
- package/dist/lib/user.js.map +1 -0
- package/dist/lib/util/deferred.js +154 -0
- package/dist/lib/util/deferred.js.map +1 -0
- package/dist/lib/util/index.js +206 -0
- package/dist/lib/util/index.js.map +1 -0
- package/dist/lib.js +11 -20
- package/dist/lib.js.map +1 -1
- package/dist/twilio-conversations.js +1937 -1097
- package/dist/twilio-conversations.min.js +3 -3
- package/package.json +15 -14
- package/CHANGELOG.md +0 -219
- package/dist/post-install.js +0 -29
- package/dist/react-native.js +0 -4039
- package/dist/react-native.js.map +0 -1
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"logger.js","sources":["../../src/logger.ts"],"sourcesContent":["import * as loglevelLog from 'loglevel';\n\nfunction prepareLine(prefix, args) {\n return [`${new Date().toISOString()} Conversations ${prefix}:`].concat(Array.from(args));\n}\n\nconst log: loglevelLog.Logger = loglevelLog.getLogger('twilio-conversations'); // twilio-conversations is used by Flex SDK. Please DO NOT change\n\nclass Logger {\n private prefix: string = '';\n\n private constructor(prefix: string) {\n this.prefix = prefix !== null && prefix !== undefined && prefix.length > 0\n ? prefix + ' '\n : '';\n }\n\n static scope(prefix: string): Logger {\n return new Logger(prefix);\n }\n\n setLevel(level: any) {\n log.setLevel(level);\n }\n\n static setLevel(level: any) {\n log.setLevel(level);\n }\n\n trace(...args) { log.trace.apply(null, prepareLine(this.prefix + 'T', args)); }\n\n debug(...args) { log.debug.apply(null, prepareLine(this.prefix + 'D', args)); }\n\n info(...args) { log.info.apply(null, prepareLine(this.prefix + 'I', args)); }\n\n warn(...args) { log.warn.apply(null, prepareLine(this.prefix + 'W', args)); }\n\n error(...args) { log.error.apply(null, prepareLine(this.prefix + 'E', args)); }\n\n static trace(...args) { log.trace.apply(null, prepareLine('T', args)); }\n\n static debug(...args) { log.debug.apply(null, prepareLine('D', args)); }\n\n static info(...args) { log.info.apply(null, prepareLine('I', args)); }\n\n static warn(...args) { log.warn.apply(null, prepareLine('W', args)); }\n\n static error(...args) { log.error.apply(null, prepareLine('E', args)); }\n\n}\n\nexport { Logger };\n"],"names":["loglevelLog"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAS,WAAW,CAAC,MAAM,EAAE,IAAI;IAC/B,OAAO,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,kBAAkB,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AAC3F,CAAC;AAED,MAAM,GAAG,GAAuBA,sBAAW,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAC;AAE9E,MAAM,MAAM;IAGV,YAAoB,MAAc;QAF1B,WAAM,GAAW,EAAE,CAAC;QAG1B,IAAI,CAAC,MAAM,GAAG,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;cACtE,MAAM,GAAG,GAAG;cACZ,EAAE,CAAC;KACR;IAED,OAAO,KAAK,CAAC,MAAc;QACzB,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC;KAC3B;IAED,QAAQ,CAAC,KAAU;QACjB,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAA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AI,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE;IAEtE,OAAO,IAAI,CAAC,GAAG,IAAI,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE;IAEtE,OAAO,KAAK,CAAC,GAAG,IAAI,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE;;;;;"}
|
@@ -0,0 +1,213 @@
|
|
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
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
132
|
+
|
133
|
+
var mcsClient = require('@twilio/mcs-client');
|
134
|
+
|
135
|
+
/**
|
136
|
+
* Represents a media information for a message in a conversation.
|
137
|
+
*/
|
138
|
+
class Media {
|
139
|
+
/**
|
140
|
+
* @internal
|
141
|
+
*/
|
142
|
+
constructor(data, services) {
|
143
|
+
this.mcsMedia = null;
|
144
|
+
this.services = services;
|
145
|
+
if (data instanceof mcsClient.McsMedia) {
|
146
|
+
this.mcsMedia = data;
|
147
|
+
}
|
148
|
+
this.state = {
|
149
|
+
sid: data.sid,
|
150
|
+
category: data.category,
|
151
|
+
filename: data.filename,
|
152
|
+
contentType: data.contentType,
|
153
|
+
size: data.size
|
154
|
+
};
|
155
|
+
}
|
156
|
+
/**
|
157
|
+
* Server-assigned unique identifier for the media.
|
158
|
+
*/
|
159
|
+
get sid() { return this.state.sid; }
|
160
|
+
/**
|
161
|
+
* File name. Null if absent.
|
162
|
+
*/
|
163
|
+
get filename() { return this.state.filename; }
|
164
|
+
/**
|
165
|
+
* Content type of the media.
|
166
|
+
*/
|
167
|
+
get contentType() { return this.state.contentType; }
|
168
|
+
/**
|
169
|
+
* Size of the media in bytes.
|
170
|
+
*/
|
171
|
+
get size() { return this.state.size; }
|
172
|
+
/**
|
173
|
+
* Media category, can be one of the {@link MediaCategory} values.
|
174
|
+
*/
|
175
|
+
get category() { return this.state.category; }
|
176
|
+
/**
|
177
|
+
* Returns the direct content URL for the media.
|
178
|
+
*
|
179
|
+
* This URL is impermanent, it will expire in several minutes and cannot be cached.
|
180
|
+
* If the URL becomes expired, you need to request a new one.
|
181
|
+
* Each call to this function produces a new temporary URL.
|
182
|
+
*/
|
183
|
+
async getContentTemporaryUrl() {
|
184
|
+
await this._fetchMcsMedia();
|
185
|
+
return this.mcsMedia.getContentUrl();
|
186
|
+
}
|
187
|
+
/**
|
188
|
+
* Returns cached direct content URL for the media.
|
189
|
+
*
|
190
|
+
* This URL will expire in several minutes. This function does not refresh the URL and can be used to query it several times
|
191
|
+
* without causing network traffic.
|
192
|
+
* If the URL becomes expired, you need to request a new one using getContentTemporaryUrl().
|
193
|
+
*
|
194
|
+
* @returns {Promise<String>}
|
195
|
+
*/
|
196
|
+
async getCachedTemporaryUrl() {
|
197
|
+
await this._fetchMcsMedia();
|
198
|
+
return this.mcsMedia.getCachedContentUrl();
|
199
|
+
}
|
200
|
+
async _fetchMcsMedia() {
|
201
|
+
if (!this.mcsMedia) {
|
202
|
+
if (this.services.mcsClient) {
|
203
|
+
this.mcsMedia = await this.services.mcsClient.get(this.state.sid);
|
204
|
+
}
|
205
|
+
else {
|
206
|
+
throw new Error('Media Content Service is unavailable');
|
207
|
+
}
|
208
|
+
}
|
209
|
+
}
|
210
|
+
}
|
211
|
+
|
212
|
+
exports.Media = Media;
|
213
|
+
//# sourceMappingURL=media.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"media.js","sources":["../../src/media.ts"],"sourcesContent":["import {\n McsClient,\n McsMedia,\n MediaCategory as McsMediaCategory\n} from '@twilio/mcs-client';\n\n/**\n * Category of media. Possible values are as follows:\n * * `'media'`\n * * `'body'`\n * * `'history'`\n */\ntype MediaCategory = McsMediaCategory;\n\ninterface MediaState {\n sid: string;\n category: MediaCategory;\n filename?: string;\n contentType: string;\n size: number;\n}\n\ninterface MediaServices {\n mcsClient: McsClient;\n}\n\n/**\n * Represents a media information for a message in a conversation.\n */\nclass Media {\n\n private state: MediaState;\n private services: MediaServices;\n private mcsMedia: McsMedia = null;\n\n /**\n * @internal\n */\n constructor(data: MediaState | McsMedia, services: MediaServices) {\n\n this.services = services;\n\n if (data instanceof McsMedia) {\n this.mcsMedia = data as McsMedia;\n }\n\n this.state = {\n sid: data.sid,\n category: data.category,\n filename: data.filename,\n contentType: data.contentType,\n size: data.size\n };\n }\n\n /**\n * Server-assigned unique identifier for the media.\n */\n public get sid(): string { return this.state.sid; }\n\n /**\n * File name. Null if absent.\n */\n public get filename(): string {return this.state.filename; }\n\n /**\n * Content type of the media.\n */\n public get contentType(): string { return this.state.contentType; }\n\n /**\n * Size of the media in bytes.\n */\n public get size(): number {return this.state.size; }\n\n /**\n * Media category, can be one of the {@link MediaCategory} values.\n */\n public get category(): MediaCategory { return this.state.category; }\n\n /**\n * Returns the direct content URL for the media.\n *\n * This URL is impermanent, it will expire in several minutes and cannot be cached.\n * If the URL becomes expired, you need to request a new one.\n * Each call to this function produces a new temporary URL.\n */\n public async getContentTemporaryUrl(): Promise<string> {\n await this._fetchMcsMedia();\n return this.mcsMedia.getContentUrl();\n }\n\n /**\n * Returns cached direct content URL for the media.\n *\n * This URL will expire in several minutes. This function does not refresh the URL and can be used to query it several times\n * without causing network traffic.\n * If the URL becomes expired, you need to request a new one using getContentTemporaryUrl().\n *\n * @returns {Promise<String>}\n */\n public async getCachedTemporaryUrl(): Promise<string> {\n await this._fetchMcsMedia();\n return this.mcsMedia.getCachedContentUrl();\n }\n\n private async _fetchMcsMedia() {\n if (!this.mcsMedia) {\n if (this.services.mcsClient) {\n this.mcsMedia = await this.services.mcsClient.get(this.state.sid);\n } else {\n throw new Error('Media Content Service is unavailable');\n }\n }\n }\n}\n\nexport {\n Media,\n MediaState,\n MediaServices,\n MediaCategory,\n};\n"],"names":["McsMedia"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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S,EAAE;gBAC3B,IAAI,CAAC,QAAQ,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;aACnE;iBAAM;gBACL,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;aACzD;SACF;KACF;;;;;"}
|
@@ -0,0 +1,209 @@
|
|
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
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
132
|
+
|
133
|
+
var unsentMessage = require('./unsent-message.js');
|
134
|
+
|
135
|
+
/**
|
136
|
+
* Message builder. Allows the message to be built and sent via method chaining.
|
137
|
+
*
|
138
|
+
* Example:
|
139
|
+
*
|
140
|
+
* ```ts
|
141
|
+
* await testConversation.prepareMessage()
|
142
|
+
* .setBody('Hello!')
|
143
|
+
* .setAttributes({foo: 'bar'})
|
144
|
+
* .addMedia(media1)
|
145
|
+
* .addMedia(media2)
|
146
|
+
* .build()
|
147
|
+
* .send();
|
148
|
+
* ```
|
149
|
+
*/
|
150
|
+
class MessageBuilder {
|
151
|
+
/**
|
152
|
+
* @internal
|
153
|
+
*/
|
154
|
+
constructor(limits, messagesEntity) {
|
155
|
+
this.limits = limits;
|
156
|
+
this.message = new unsentMessage.UnsentMessage(messagesEntity);
|
157
|
+
}
|
158
|
+
/**
|
159
|
+
* Sets the message body.
|
160
|
+
* @param text Contents of the body.
|
161
|
+
*/
|
162
|
+
setBody(text) {
|
163
|
+
this.message.text = text;
|
164
|
+
return this;
|
165
|
+
}
|
166
|
+
/**
|
167
|
+
* Sets the message subject.
|
168
|
+
* @param subject Contents of the subject.
|
169
|
+
*/
|
170
|
+
setSubject(subject) {
|
171
|
+
this.message.emailOptions.subject = subject;
|
172
|
+
return this;
|
173
|
+
}
|
174
|
+
/**
|
175
|
+
* Sets the message attributes.
|
176
|
+
* @param attributes Message attributes.
|
177
|
+
*/
|
178
|
+
setAttributes(attributes) {
|
179
|
+
this.message.attributes = attributes;
|
180
|
+
return this;
|
181
|
+
}
|
182
|
+
/**
|
183
|
+
* Adds media to the message.
|
184
|
+
* @param payload Media to add.
|
185
|
+
*/
|
186
|
+
addMedia(payload) {
|
187
|
+
this.message.mediaContent.push(['media', payload]);
|
188
|
+
return this;
|
189
|
+
}
|
190
|
+
/**
|
191
|
+
* Builds the message, making it ready to be sent.
|
192
|
+
*/
|
193
|
+
build() {
|
194
|
+
if (this.message.mediaContent.length > this.limits.mediaAttachmentsCountLimit) {
|
195
|
+
throw new Error(`Too many media attachments in the message (${this.message.mediaContent.length} > ${this.limits.mediaAttachmentsCountLimit})`);
|
196
|
+
}
|
197
|
+
// @todo we don't know the sizes of the attachments in FormData
|
198
|
+
return this.message;
|
199
|
+
}
|
200
|
+
getPayloadContentType(payload) {
|
201
|
+
if (typeof FormData !== 'undefined' && (payload instanceof FormData)) {
|
202
|
+
return payload.get('Content-Type');
|
203
|
+
}
|
204
|
+
return payload.contentType;
|
205
|
+
}
|
206
|
+
}
|
207
|
+
|
208
|
+
exports.MessageBuilder = MessageBuilder;
|
209
|
+
//# sourceMappingURL=message-builder.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"message-builder.js","sources":["../../src/message-builder.ts"],"sourcesContent":["import { Limits } from './interfaces/limits';\nimport { SendMediaOptions } from './conversation';\nimport { UnsentMessage } from './unsent-message';\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\n /**\n * @internal\n */\n constructor(private readonly limits: Limits, messagesEntity: any) {\n this.message = new UnsentMessage(messagesEntity);\n }\n\n /**\n * Sets the message body.\n * @param text Contents of the body.\n */\n setBody(text: string): MessageBuilder {\n this.message.text = text;\n return this;\n }\n\n /**\n * Sets the message subject.\n * @param subject Contents of the subject.\n */\n setSubject(subject: string): MessageBuilder {\n this.message.emailOptions.subject = subject;\n return this;\n }\n\n /**\n * Sets the message attributes.\n * @param attributes Message attributes.\n */\n setAttributes(attributes: any): MessageBuilder {\n this.message.attributes = attributes;\n return this;\n }\n\n /**\n * Adds media to the message.\n * @param payload Media to add.\n */\n addMedia(payload: FormData | SendMediaOptions): MessageBuilder {\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 if (this.message.mediaContent.length > this.limits.mediaAttachmentsCountLimit) {\n throw new Error(`Too many media attachments in the message (${this.message.mediaContent.length} > ${this.limits.mediaAttachmentsCountLimit})`);\n }\n\n // @todo we don't know the sizes of the attachments in FormData\n\n return this.message;\n }\n\n private getPayloadContentType(payload: FormData | SendMediaOptions): string {\n if (typeof FormData !== 'undefined' && (payload instanceof FormData)) {\n return payload.get('Content-Type') as string;\n }\n return (payload as SendMediaOptions).contentType;\n }\n}\n\nexport { MessageBuilder };\n"],"names":["UnsentMessage"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA;;;;;;;;;;;;;;;AAeA,MAAM,cAAc;;;;IAMlB,YAA6B,MAAc,EAAE,cAAmB;QAAnC,WAAM,GAAN,MAAM,CAAQ;QACzC,IAAI,CAAC,OAAO,GAAG,IAAIA,2BAAa,CAAC,cAAc,CAAC,CAAC;KAClD;;;;;IAMD,OAAO,CAAC,IAAY;QAClB,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;QACzB,OAAO,IAAI,CAAC;KACb;;;;;IAMD,UAAU,CAAC,OAAe;QACxB,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,GAAG,OAAO,CAAC;QAC5C,OAAO,IAAI,CAAC;KACb;;;;;IAMD,aAAa,CAAC,UAAe;QAC3B,IAAI,CAAC,OAAO,CAAC,UAAU,GAAG,UAAU,CAAC;QACrC,OAAO,IAAI,CAAC;KACb;;;;;IAMD,QAAQ,CAAC,OAAoC;QAC3C,IAAI,C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