@twilio/mcs-client 0.5.2 → 0.6.0-canary.18
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/builds/browser.js +517 -362
- package/builds/browser.js.map +1 -1
- package/builds/lib.d.ts +54 -26
- package/builds/lib.js +517 -362
- package/builds/lib.js.map +1 -1
- package/builds/twilio-mcs-client.js +10206 -9443
- package/builds/twilio-mcs-client.min.js +24 -38
- package/dist/cancellable-promise.js +88 -0
- package/dist/cancellable-promise.js.map +1 -0
- package/dist/client.js +89 -30
- package/dist/client.js.map +1 -1
- package/dist/configuration.js.map +1 -1
- package/dist/index.js +5 -9
- package/dist/index.js.map +1 -1
- package/dist/logger.js +2 -4
- package/dist/logger.js.map +1 -1
- package/dist/media.js +15 -22
- package/dist/media.js.map +1 -1
- package/dist/node_modules/tslib/tslib.es6.js +1 -1
- package/dist/node_modules/tslib/tslib.es6.js.map +1 -1
- package/dist/packages/mcs-client/package.json.js +1 -1
- package/dist/services/network.js +48 -31
- package/dist/services/network.js.map +1 -1
- package/dist/services/transport.js +11 -5
- package/dist/services/transport.js.map +1 -1
- package/dist/services/transporterror.js.map +1 -1
- package/package.json +17 -14
- package/CHANGELOG.md +0 -193
package/builds/lib.d.ts
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import * as log from "loglevel";
|
|
3
3
|
import * as loglevel from "loglevel";
|
|
4
|
+
/**
|
|
5
|
+
* Cancellable promise. Extends the functionality of the native Promise to include the cancel method.
|
|
6
|
+
*
|
|
7
|
+
* Example:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
*
|
|
11
|
+
* const cancellableFetchPromise = new CancellablePromise(async (resolve, reject, onCancel) => {
|
|
12
|
+
* const request = fetch("https://example.com/");
|
|
13
|
+
*
|
|
14
|
+
* onCancel(() => request.cancel());
|
|
15
|
+
*
|
|
16
|
+
* try {
|
|
17
|
+
* const response = await request;
|
|
18
|
+
* resolve(response);
|
|
19
|
+
* } catch (err) {
|
|
20
|
+
* reject(err);
|
|
21
|
+
* }
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* cancellableFetchPromise.cancel();
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare class CancellablePromise<T> extends Promise<T> {
|
|
28
|
+
private readonly onCancel?;
|
|
29
|
+
private rejectPromise?;
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new CancellablePromise.
|
|
32
|
+
* @param executor A callback used to initialize the promise. This callback is passed three arguments:
|
|
33
|
+
* a resolve callback used to resolve the promise with a value or the result of another promise,
|
|
34
|
+
* a reject callback used to reject the promise with a provided reason or error,
|
|
35
|
+
* and an onCancel callback used to define behavior of cancellation.
|
|
36
|
+
*/
|
|
37
|
+
constructor(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: string | Error) => void, onCancel: (cancellationFunction: () => void) => void) => void);
|
|
38
|
+
/**
|
|
39
|
+
* Cancels the promise and invokes the cancellation callback if it was defined during instantiation. Cancellation will result in the promise being rejected.
|
|
40
|
+
*/
|
|
41
|
+
cancel(): void;
|
|
42
|
+
}
|
|
4
43
|
type Headers = {
|
|
5
44
|
[id: string]: string;
|
|
6
45
|
};
|
|
@@ -17,11 +56,11 @@ declare class Transport {
|
|
|
17
56
|
/**
|
|
18
57
|
* Make a GET request by given URL
|
|
19
58
|
*/
|
|
20
|
-
get(url: string, headers: Headers):
|
|
59
|
+
get(url: string, headers: Headers): CancellablePromise<Response>;
|
|
21
60
|
/**
|
|
22
61
|
* Make a POST request by given URL
|
|
23
62
|
*/
|
|
24
|
-
post(url: string, headers: Headers, body?: any):
|
|
63
|
+
post(url: string, headers: Headers, body?: any): CancellablePromise<Response>;
|
|
25
64
|
}
|
|
26
65
|
interface BackoffOverride {
|
|
27
66
|
max: number;
|
|
@@ -60,8 +99,8 @@ declare class Network {
|
|
|
60
99
|
private backoffConfig;
|
|
61
100
|
private retryWhenThrottled;
|
|
62
101
|
private executeWithRetry;
|
|
63
|
-
get(url: string):
|
|
64
|
-
post(url: string, category: MediaCategory | null, media: string | Buffer | Blob | FormData, contentType?: string, filename?: string):
|
|
102
|
+
get(url: string): CancellablePromise<any>;
|
|
103
|
+
post(url: string, category: MediaCategory | null, media: string | Buffer | Blob | FormData | Record<string, unknown>, contentType?: string, filename?: string): CancellablePromise<any>;
|
|
65
104
|
}
|
|
66
105
|
type MediaCategory = "media" | "body" | "history";
|
|
67
106
|
interface Links {
|
|
@@ -118,21 +157,8 @@ declare class Media {
|
|
|
118
157
|
*
|
|
119
158
|
* It is reasonable to build your own refresh logic upon these two functions: as soon as URL returned
|
|
120
159
|
* by getCachedContentUrl() returns 40x status you should call getContentUrl() to refresh it.
|
|
121
|
-
*
|
|
122
|
-
* @returns {Promise<string>}
|
|
123
160
|
*/
|
|
124
|
-
getContentUrl():
|
|
125
|
-
/**
|
|
126
|
-
* Returns direct content URL to uploaded binary. This URL will expire after some time.
|
|
127
|
-
* This function does not support getting a new URL however. Once set it will remain the same.
|
|
128
|
-
* Use getContentUrl() to query a new one.
|
|
129
|
-
*
|
|
130
|
-
* It is reasonable to build your own refresh logic upon these two functions: as soon as URL returned
|
|
131
|
-
* by getCachedContentUrl() returns 40x status you should call getContentUrl() to refresh it.
|
|
132
|
-
*
|
|
133
|
-
* @returns {Promise<string>}
|
|
134
|
-
*/
|
|
135
|
-
getCachedContentUrl(): Promise<string | null>;
|
|
161
|
+
getContentUrl(): CancellablePromise<string | null>;
|
|
136
162
|
private _update;
|
|
137
163
|
}
|
|
138
164
|
interface Options$0 {
|
|
@@ -175,30 +201,32 @@ declare class Client {
|
|
|
175
201
|
/**
|
|
176
202
|
* Gets media from media service
|
|
177
203
|
* @param {String} sid - Media's SID
|
|
178
|
-
* @returns {Promise<Media>}
|
|
179
204
|
*/
|
|
180
|
-
get(sid: string):
|
|
205
|
+
get(sid: string): CancellablePromise<Media>;
|
|
181
206
|
/**
|
|
182
207
|
* Posts raw content to media service
|
|
183
208
|
* @param {String} contentType - content type of media
|
|
184
209
|
* @param {String|Buffer|Blob} media - content to post
|
|
185
210
|
* @param {MediaCategory|null} category - category for the media
|
|
186
|
-
* @returns {Promise<Media>}
|
|
187
211
|
*/
|
|
188
|
-
post(contentType: string, media: string | Buffer | Blob, category: MediaCategory | null, filename?: string):
|
|
212
|
+
post(contentType: string, media: string | Buffer | Blob, category: MediaCategory | null, filename?: string): CancellablePromise<Media>;
|
|
189
213
|
/**
|
|
190
214
|
* Posts FormData to media service. Can be used only with browser engine's FormData.
|
|
191
215
|
* In non-browser FormData case the method will do promise reject with
|
|
192
216
|
* new TypeError("Posting FormData supported only with browser engine's FormData")
|
|
193
217
|
* @param {FormData} formData - form data to post
|
|
194
218
|
* @param {MediaCategory|null} category - category for the media
|
|
195
|
-
* @returns {Promise<Media>}
|
|
196
219
|
*/
|
|
197
|
-
postFormData(formData: FormData, category?: MediaCategory | null):
|
|
220
|
+
postFormData(formData: FormData, category?: MediaCategory | null): CancellablePromise<Media>;
|
|
198
221
|
/**
|
|
199
222
|
* Retrieve information about multiple media SIDs at the same time.
|
|
200
223
|
* @param mediaSids Array of Media SIDs to get information from.
|
|
201
224
|
*/
|
|
202
|
-
mediaSetGet(mediaSids: string[]):
|
|
225
|
+
mediaSetGet(mediaSids: string[]): CancellablePromise<Media[]>;
|
|
226
|
+
/**
|
|
227
|
+
* Retrieve temporary URLs for a set of media SIDs.
|
|
228
|
+
* @param mediaSids array of the media SIDs to get URLs from.
|
|
229
|
+
*/
|
|
230
|
+
mediaSetGetContentUrls(mediaSids: string[]): CancellablePromise<Map<string, string>>;
|
|
203
231
|
}
|
|
204
|
-
export { Client, Client as McsClient, Client as default, Media, Media as McsMedia, MediaCategory, MediaCategory as McsMediaCategory };
|
|
232
|
+
export { CancellablePromise, Client, Client as McsClient, Client as default, Media, Media as McsMedia, MediaCategory, MediaCategory as McsMediaCategory };
|