@twilio/mcs-client 0.5.3 → 0.6.0-rc.10
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/CHANGELOG.md +87 -0
- package/builds/browser.js +733 -370
- package/builds/browser.js.map +1 -1
- package/builds/lib.d.ts +55 -26
- package/builds/lib.js +708 -370
- package/builds/lib.js.map +1 -1
- package/builds/twilio-mcs-client.js +3371 -2210
- package/builds/twilio-mcs-client.min.js +3 -17
- package/dist/_virtual/rng-browser.js +34 -0
- package/dist/_virtual/rng-browser.js.map +1 -0
- package/dist/cancellable-promise.js +98 -0
- package/dist/cancellable-promise.js.map +1 -0
- package/dist/client.js +88 -23
- 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/node_modules/uuid/index.js +44 -0
- package/dist/node_modules/uuid/index.js.map +1 -0
- package/dist/node_modules/uuid/lib/bytesToUuid.js +60 -0
- package/dist/node_modules/uuid/lib/bytesToUuid.js.map +1 -0
- package/dist/node_modules/uuid/lib/rng-browser.js +65 -0
- package/dist/node_modules/uuid/lib/rng-browser.js.map +1 -0
- package/dist/node_modules/uuid/v1.js +146 -0
- package/dist/node_modules/uuid/v1.js.map +1 -0
- package/dist/node_modules/uuid/v4.js +66 -0
- package/dist/node_modules/uuid/v4.js.map +1 -0
- package/dist/packages/mcs-client/package.json.js +1 -1
- package/dist/services/network.js +54 -32
- package/dist/services/network.js.map +1 -1
- package/dist/services/transport.js +26 -11
- package/dist/services/transport.js.map +1 -1
- package/dist/services/transporterror.js.map +1 -1
- package/package.json +16 -14
package/builds/lib.d.ts
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
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 id;
|
|
29
|
+
private rejectPromise?;
|
|
30
|
+
private static readonly cancellationMap;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new CancellablePromise.
|
|
33
|
+
* @param executor A callback used to initialize the promise. This callback is passed three arguments:
|
|
34
|
+
* a resolve callback used to resolve the promise with a value or the result of another promise,
|
|
35
|
+
* a reject callback used to reject the promise with a provided reason or error,
|
|
36
|
+
* and an onCancel callback used to define behavior of cancellation.
|
|
37
|
+
*/
|
|
38
|
+
constructor(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: string | Error) => void, onCancel: (cancellationFunction: () => void) => void) => void);
|
|
39
|
+
/**
|
|
40
|
+
* Cancels the promise and invokes the cancellation callback if it was defined during instantiation. Cancellation will result in the promise being rejected.
|
|
41
|
+
*/
|
|
42
|
+
cancel(): this;
|
|
43
|
+
}
|
|
4
44
|
type Headers = {
|
|
5
45
|
[id: string]: string;
|
|
6
46
|
};
|
|
@@ -17,11 +57,11 @@ declare class Transport {
|
|
|
17
57
|
/**
|
|
18
58
|
* Make a GET request by given URL
|
|
19
59
|
*/
|
|
20
|
-
get(url: string, headers: Headers):
|
|
60
|
+
get(url: string, headers: Headers): CancellablePromise<Response>;
|
|
21
61
|
/**
|
|
22
62
|
* Make a POST request by given URL
|
|
23
63
|
*/
|
|
24
|
-
post(url: string, headers: Headers, body?: any):
|
|
64
|
+
post(url: string, headers: Headers, body?: any): CancellablePromise<Response>;
|
|
25
65
|
}
|
|
26
66
|
interface BackoffOverride {
|
|
27
67
|
max: number;
|
|
@@ -60,8 +100,8 @@ declare class Network {
|
|
|
60
100
|
private backoffConfig;
|
|
61
101
|
private retryWhenThrottled;
|
|
62
102
|
private executeWithRetry;
|
|
63
|
-
get(url: string):
|
|
64
|
-
post(url: string, category: MediaCategory | null, media: string | Buffer | Blob | FormData | Record<string, unknown>, contentType?: string, filename?: string):
|
|
103
|
+
get(url: string): CancellablePromise<any>;
|
|
104
|
+
post(url: string, category: MediaCategory | null, media: string | Buffer | Blob | FormData | Record<string, unknown>, contentType?: string, filename?: string): CancellablePromise<any>;
|
|
65
105
|
}
|
|
66
106
|
type MediaCategory = "media" | "body" | "history";
|
|
67
107
|
interface Links {
|
|
@@ -118,21 +158,8 @@ declare class Media {
|
|
|
118
158
|
*
|
|
119
159
|
* It is reasonable to build your own refresh logic upon these two functions: as soon as URL returned
|
|
120
160
|
* by getCachedContentUrl() returns 40x status you should call getContentUrl() to refresh it.
|
|
121
|
-
*
|
|
122
|
-
* @returns {Promise<string>}
|
|
123
161
|
*/
|
|
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>;
|
|
162
|
+
getContentUrl(): CancellablePromise<string | null>;
|
|
136
163
|
private _update;
|
|
137
164
|
}
|
|
138
165
|
interface Options$0 {
|
|
@@ -175,30 +202,32 @@ declare class Client {
|
|
|
175
202
|
/**
|
|
176
203
|
* Gets media from media service
|
|
177
204
|
* @param {String} sid - Media's SID
|
|
178
|
-
* @returns {Promise<Media>}
|
|
179
205
|
*/
|
|
180
|
-
get(sid: string):
|
|
206
|
+
get(sid: string): CancellablePromise<Media>;
|
|
181
207
|
/**
|
|
182
208
|
* Posts raw content to media service
|
|
183
209
|
* @param {String} contentType - content type of media
|
|
184
210
|
* @param {String|Buffer|Blob} media - content to post
|
|
185
211
|
* @param {MediaCategory|null} category - category for the media
|
|
186
|
-
* @returns {Promise<Media>}
|
|
187
212
|
*/
|
|
188
|
-
post(contentType: string, media: string | Buffer | Blob, category: MediaCategory | null, filename?: string):
|
|
213
|
+
post(contentType: string, media: string | Buffer | Blob, category: MediaCategory | null, filename?: string): CancellablePromise<Media>;
|
|
189
214
|
/**
|
|
190
215
|
* Posts FormData to media service. Can be used only with browser engine's FormData.
|
|
191
216
|
* In non-browser FormData case the method will do promise reject with
|
|
192
217
|
* new TypeError("Posting FormData supported only with browser engine's FormData")
|
|
193
218
|
* @param {FormData} formData - form data to post
|
|
194
219
|
* @param {MediaCategory|null} category - category for the media
|
|
195
|
-
* @returns {Promise<Media>}
|
|
196
220
|
*/
|
|
197
|
-
postFormData(formData: FormData, category?: MediaCategory | null):
|
|
221
|
+
postFormData(formData: FormData, category?: MediaCategory | null): CancellablePromise<Media>;
|
|
198
222
|
/**
|
|
199
223
|
* Retrieve information about multiple media SIDs at the same time.
|
|
200
224
|
* @param mediaSids Array of Media SIDs to get information from.
|
|
201
225
|
*/
|
|
202
|
-
mediaSetGet(mediaSids: string[]):
|
|
226
|
+
mediaSetGet(mediaSids: string[]): CancellablePromise<Media[]>;
|
|
227
|
+
/**
|
|
228
|
+
* Retrieve temporary URLs for a set of media SIDs.
|
|
229
|
+
* @param mediaSids array of the media SIDs to get URLs from.
|
|
230
|
+
*/
|
|
231
|
+
mediaSetGetContentUrls(mediaSids: string[]): CancellablePromise<Map<string, string>>;
|
|
203
232
|
}
|
|
204
|
-
export { Client, Client as McsClient, Client as default, Media, Media as McsMedia, MediaCategory, MediaCategory as McsMediaCategory };
|
|
233
|
+
export { CancellablePromise, Client, Client as McsClient, Client as default, Media, Media as McsMedia, MediaCategory, MediaCategory as McsMediaCategory };
|