@whereby.com/browser-sdk 2.0.0-beta2 → 2.0.0-beta3
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 +0 -14
- package/dist/embed/index.d.ts +4 -1
- package/dist/embed/{index.js → index.esm.js} +117 -109
- package/dist/react/index.d.ts +397 -6
- package/dist/react/index.esm.js +8245 -0
- package/dist/utils/index.d.ts +5 -2
- package/dist/utils/{fakeWebcamFrame.js → index.esm.js} +68 -47
- package/dist/v2-beta3.js +15 -0
- package/package.json +22 -12
- package/dist/LocalMedia.d.ts +0 -70
- package/dist/LocalMedia.js +0 -208
- package/dist/RoomConnection.d.ts +0 -190
- package/dist/RoomConnection.js +0 -646
- package/dist/RoomParticipant.d.ts +0 -50
- package/dist/RoomParticipant.js +0 -48
- package/dist/api/ApiClient.d.ts +0 -26
- package/dist/api/ApiClient.js +0 -61
- package/dist/api/Credentials.d.ts +0 -17
- package/dist/api/Credentials.js +0 -16
- package/dist/api/HttpClient.d.ts +0 -16
- package/dist/api/HttpClient.js +0 -52
- package/dist/api/MultipartHttpClient.d.ts +0 -10
- package/dist/api/MultipartHttpClient.js +0 -25
- package/dist/api/OrganizationApiClient.d.ts +0 -16
- package/dist/api/OrganizationApiClient.js +0 -28
- package/dist/api/Response.d.ts +0 -29
- package/dist/api/Response.js +0 -9
- package/dist/api/credentialsService/index.d.ts +0 -27
- package/dist/api/credentialsService/index.js +0 -89
- package/dist/api/deviceService/index.d.ts +0 -9
- package/dist/api/deviceService/index.js +0 -23
- package/dist/api/extractUtils.d.ts +0 -16
- package/dist/api/extractUtils.js +0 -51
- package/dist/api/index.d.ts +0 -7
- package/dist/api/index.js +0 -7
- package/dist/api/localStorageWrapper/index.d.ts +0 -2
- package/dist/api/localStorageWrapper/index.js +0 -15
- package/dist/api/models/Account.d.ts +0 -20
- package/dist/api/models/Account.js +0 -24
- package/dist/api/models/Meeting.d.ts +0 -12
- package/dist/api/models/Meeting.js +0 -29
- package/dist/api/models/Organization.d.ts +0 -102
- package/dist/api/models/Organization.js +0 -81
- package/dist/api/models/Room.d.ts +0 -4
- package/dist/api/models/Room.js +0 -38
- package/dist/api/models/account/EmbeddedFreeTierStatus.d.ts +0 -13
- package/dist/api/models/account/EmbeddedFreeTierStatus.js +0 -17
- package/dist/api/modules/AbstractStore.d.ts +0 -5
- package/dist/api/modules/AbstractStore.js +0 -1
- package/dist/api/modules/ChromeStorageStore.d.ts +0 -10
- package/dist/api/modules/ChromeStorageStore.js +0 -21
- package/dist/api/modules/LocalStorageStore.d.ts +0 -9
- package/dist/api/modules/LocalStorageStore.js +0 -35
- package/dist/api/modules/tests/__mocks__/storage.d.ts +0 -10
- package/dist/api/modules/tests/__mocks__/storage.js +0 -19
- package/dist/api/organizationService/index.d.ts +0 -46
- package/dist/api/organizationService/index.js +0 -158
- package/dist/api/organizationServiceCache/index.d.ts +0 -13
- package/dist/api/organizationServiceCache/index.js +0 -16
- package/dist/api/parameterAssertUtils.d.ts +0 -13
- package/dist/api/parameterAssertUtils.js +0 -64
- package/dist/api/roomService/index.d.ts +0 -54
- package/dist/api/roomService/index.js +0 -160
- package/dist/api/test/helpers.d.ts +0 -7
- package/dist/api/test/helpers.js +0 -32
- package/dist/api/types.d.ts +0 -5
- package/dist/api/types.js +0 -1
- package/dist/react/VideoView.d.ts +0 -15
- package/dist/react/VideoView.js +0 -37
- package/dist/react/index.js +0 -4
- package/dist/react/useLocalMedia.d.ts +0 -29
- package/dist/react/useLocalMedia.js +0 -109
- package/dist/react/useRoomConnection.d.ts +0 -57
- package/dist/react/useRoomConnection.js +0 -340
- package/dist/utils/debounce.d.ts +0 -9
- package/dist/utils/debounce.js +0 -18
- package/dist/utils/fakeAudioStream.d.ts +0 -1
- package/dist/utils/fakeAudioStream.js +0 -18
- package/dist/utils/fakeWebcamFrame.d.ts +0 -1
- package/dist/utils/index.js +0 -2
- package/dist/v2-beta2.js +0 -2000
- package/dist/version.d.ts +0 -1
- package/dist/version.js +0 -1
package/dist/RoomParticipant.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
export default class RoomParticipant {
|
|
2
|
-
constructor({ displayName, id, stream, isAudioEnabled, isVideoEnabled }) {
|
|
3
|
-
this.isLocalParticipant = false;
|
|
4
|
-
this.displayName = displayName;
|
|
5
|
-
this.id = id;
|
|
6
|
-
this.stream = stream;
|
|
7
|
-
this.isAudioEnabled = isAudioEnabled;
|
|
8
|
-
this.isVideoEnabled = isVideoEnabled;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
export class RemoteParticipant extends RoomParticipant {
|
|
12
|
-
constructor({ displayName, id, newJoiner, streams, isAudioEnabled, isVideoEnabled, }) {
|
|
13
|
-
super({ displayName, id, isAudioEnabled, isVideoEnabled });
|
|
14
|
-
this.newJoiner = newJoiner;
|
|
15
|
-
this.streams = streams.map((streamId) => ({ id: streamId, state: newJoiner ? "new_accept" : "to_accept" }));
|
|
16
|
-
}
|
|
17
|
-
addStream(streamId, state) {
|
|
18
|
-
this.streams.push({ id: streamId, state });
|
|
19
|
-
}
|
|
20
|
-
removeStream(streamId) {
|
|
21
|
-
const index = this.streams.findIndex((s) => s.id === streamId);
|
|
22
|
-
if (index !== -1) {
|
|
23
|
-
this.streams.splice(index, 1);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
updateStreamState(streamId, state) {
|
|
27
|
-
const stream = this.streams.find((s) => s.id === streamId);
|
|
28
|
-
if (stream) {
|
|
29
|
-
stream.state = state;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
export class LocalParticipant extends RoomParticipant {
|
|
34
|
-
constructor({ displayName, id, stream, isAudioEnabled, isVideoEnabled }) {
|
|
35
|
-
super({ displayName, id, stream, isAudioEnabled, isVideoEnabled });
|
|
36
|
-
this.isLocalParticipant = true;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
export class Screenshare {
|
|
40
|
-
constructor({ participantId, id, hasAudioTrack, stream, isLocal }) {
|
|
41
|
-
this.isLocal = false;
|
|
42
|
-
this.participantId = participantId;
|
|
43
|
-
this.id = id;
|
|
44
|
-
this.hasAudioTrack = hasAudioTrack;
|
|
45
|
-
this.stream = stream;
|
|
46
|
-
this.isLocal = isLocal;
|
|
47
|
-
}
|
|
48
|
-
}
|
package/dist/api/ApiClient.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import HttpClient, { HttpClientRequestConfig } from "./HttpClient";
|
|
2
|
-
import MultipartHttpClient from "./MultipartHttpClient";
|
|
3
|
-
import Credentials from "./Credentials";
|
|
4
|
-
import Response from "./Response";
|
|
5
|
-
interface AuthenticatedHttpClientOptions {
|
|
6
|
-
httpClient: HttpClient;
|
|
7
|
-
fetchDeviceCredentials: () => Promise<Credentials | null>;
|
|
8
|
-
}
|
|
9
|
-
declare class AuthenticatedHttpClient {
|
|
10
|
-
private _httpClient;
|
|
11
|
-
private _fetchDeviceCredentials;
|
|
12
|
-
constructor({ httpClient, fetchDeviceCredentials }: AuthenticatedHttpClientOptions);
|
|
13
|
-
request(url: string, options: HttpClientRequestConfig): Promise<Response>;
|
|
14
|
-
}
|
|
15
|
-
interface ApiClientOptions {
|
|
16
|
-
baseUrl?: string;
|
|
17
|
-
fetchDeviceCredentials?: AuthenticatedHttpClientOptions["fetchDeviceCredentials"];
|
|
18
|
-
}
|
|
19
|
-
export default class ApiClient {
|
|
20
|
-
authenticatedHttpClient: AuthenticatedHttpClient;
|
|
21
|
-
authenticatedFormDataHttpClient: MultipartHttpClient;
|
|
22
|
-
constructor({ baseUrl, fetchDeviceCredentials, }?: ApiClientOptions);
|
|
23
|
-
request(url: string, options: HttpClientRequestConfig): Promise<Response>;
|
|
24
|
-
requestMultipart(url: string, options: HttpClientRequestConfig): Promise<Response>;
|
|
25
|
-
}
|
|
26
|
-
export {};
|
package/dist/api/ApiClient.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import nodeBtoa from "btoa";
|
|
2
|
-
import assert from "@whereby/jslib-media/src/utils/assert";
|
|
3
|
-
import HttpClient from "./HttpClient";
|
|
4
|
-
import MultipartHttpClient from "./MultipartHttpClient";
|
|
5
|
-
import { assertString } from "./parameterAssertUtils";
|
|
6
|
-
let btoa;
|
|
7
|
-
if (typeof window === "object") {
|
|
8
|
-
btoa = window.btoa || nodeBtoa;
|
|
9
|
-
}
|
|
10
|
-
else if (typeof global === "object") {
|
|
11
|
-
btoa = global.btoa || nodeBtoa;
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
btoa = nodeBtoa;
|
|
15
|
-
}
|
|
16
|
-
function _getAuthHeader(credentials) {
|
|
17
|
-
if (credentials && credentials.credentials) {
|
|
18
|
-
const btoaStr = `${credentials.credentials.uuid}:${credentials.hmac}`;
|
|
19
|
-
return { Authorization: `Basic ${btoa(btoaStr)}` };
|
|
20
|
-
}
|
|
21
|
-
return {};
|
|
22
|
-
}
|
|
23
|
-
const noCredentials = () => Promise.resolve(null);
|
|
24
|
-
class AuthenticatedHttpClient {
|
|
25
|
-
constructor({ httpClient, fetchDeviceCredentials }) {
|
|
26
|
-
this._httpClient = httpClient;
|
|
27
|
-
this._fetchDeviceCredentials = fetchDeviceCredentials;
|
|
28
|
-
}
|
|
29
|
-
request(url, options) {
|
|
30
|
-
return this._fetchDeviceCredentials().then((credentials) => {
|
|
31
|
-
const headers = Object.assign({}, options.headers, _getAuthHeader(credentials), {
|
|
32
|
-
"X-Appearin-Device-Platform": "web",
|
|
33
|
-
});
|
|
34
|
-
const httpClientOptions = Object.assign({}, options, { headers });
|
|
35
|
-
return this._httpClient.request(url, httpClientOptions);
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
export default class ApiClient {
|
|
40
|
-
constructor({ baseUrl = "https://api.appearin.net", fetchDeviceCredentials = noCredentials, } = {}) {
|
|
41
|
-
this.authenticatedHttpClient = new AuthenticatedHttpClient({
|
|
42
|
-
httpClient: new HttpClient({
|
|
43
|
-
baseUrl,
|
|
44
|
-
}),
|
|
45
|
-
fetchDeviceCredentials,
|
|
46
|
-
});
|
|
47
|
-
this.authenticatedFormDataHttpClient = new MultipartHttpClient({ httpClient: this.authenticatedHttpClient });
|
|
48
|
-
}
|
|
49
|
-
request(url, options) {
|
|
50
|
-
assertString(url, "url");
|
|
51
|
-
assert.ok(url[0] === "/", 'url<String> only accepts relative URLs beginning with "/".');
|
|
52
|
-
assert.ok(options, "options are required");
|
|
53
|
-
return this.authenticatedHttpClient.request(url, options);
|
|
54
|
-
}
|
|
55
|
-
requestMultipart(url, options) {
|
|
56
|
-
assertString(url, "url");
|
|
57
|
-
assert.ok(url[0] === "/", 'url<String> only accepts relative URLs beginning with "/".');
|
|
58
|
-
assert.ok(options, "options are required");
|
|
59
|
-
return this.authenticatedFormDataHttpClient.request(url, options);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Json } from "./Response";
|
|
2
|
-
interface CredentialsOptions {
|
|
3
|
-
uuid: string;
|
|
4
|
-
hmac: string;
|
|
5
|
-
userId?: string;
|
|
6
|
-
}
|
|
7
|
-
export default class Credentials {
|
|
8
|
-
credentials: {
|
|
9
|
-
uuid: CredentialsOptions["uuid"];
|
|
10
|
-
};
|
|
11
|
-
hmac: CredentialsOptions["hmac"];
|
|
12
|
-
userId: CredentialsOptions["userId"];
|
|
13
|
-
constructor(uuid: CredentialsOptions["uuid"], hmac: CredentialsOptions["hmac"], userId?: CredentialsOptions["userId"]);
|
|
14
|
-
toJson(): Json;
|
|
15
|
-
static fromJson(json: Json): Credentials;
|
|
16
|
-
}
|
|
17
|
-
export {};
|
package/dist/api/Credentials.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { extractJson, extractNullOrString, extractString } from "./extractUtils";
|
|
2
|
-
export default class Credentials {
|
|
3
|
-
constructor(uuid, hmac, userId = undefined) {
|
|
4
|
-
this.credentials = {
|
|
5
|
-
uuid,
|
|
6
|
-
};
|
|
7
|
-
this.hmac = hmac;
|
|
8
|
-
this.userId = userId;
|
|
9
|
-
}
|
|
10
|
-
toJson() {
|
|
11
|
-
return Object.assign({ credentials: this.credentials, hmac: this.hmac }, (this.userId && { userId: this.userId }));
|
|
12
|
-
}
|
|
13
|
-
static fromJson(json) {
|
|
14
|
-
return new Credentials(extractString(extractJson(json, "credentials"), "uuid"), extractString(json, "hmac"), extractNullOrString(json, "userId") || undefined);
|
|
15
|
-
}
|
|
16
|
-
}
|
package/dist/api/HttpClient.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from "axios";
|
|
2
|
-
import Response from "./Response";
|
|
3
|
-
export type HttpClientRequestConfig = AxiosRequestConfig | {
|
|
4
|
-
[key: string]: unknown;
|
|
5
|
-
};
|
|
6
|
-
export interface IHttpClient {
|
|
7
|
-
request(url: string, options: HttpClientRequestConfig): Promise<Response>;
|
|
8
|
-
}
|
|
9
|
-
export default class HttpClient implements IHttpClient {
|
|
10
|
-
_baseUrl: string;
|
|
11
|
-
constructor({ baseUrl }: {
|
|
12
|
-
baseUrl: string;
|
|
13
|
-
});
|
|
14
|
-
private _requestAxios;
|
|
15
|
-
request(url: string, options: HttpClientRequestConfig): Promise<Response>;
|
|
16
|
-
}
|
package/dist/api/HttpClient.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import assert from "@whereby/jslib-media/src/utils/assert";
|
|
2
|
-
import axios from "axios";
|
|
3
|
-
import Response from "./Response";
|
|
4
|
-
import { assertString } from "./parameterAssertUtils";
|
|
5
|
-
function _getAbsoluteUrl({ baseUrl, url }) {
|
|
6
|
-
return baseUrl ? baseUrl + url : url;
|
|
7
|
-
}
|
|
8
|
-
export default class HttpClient {
|
|
9
|
-
constructor({ baseUrl }) {
|
|
10
|
-
assertString(baseUrl, "baseUrl");
|
|
11
|
-
this._baseUrl = baseUrl;
|
|
12
|
-
}
|
|
13
|
-
_requestAxios(url, options) {
|
|
14
|
-
const axiosOptions = Object.assign({}, options, {
|
|
15
|
-
url,
|
|
16
|
-
baseURL: this._baseUrl,
|
|
17
|
-
});
|
|
18
|
-
return axios.request(axiosOptions);
|
|
19
|
-
}
|
|
20
|
-
request(url, options) {
|
|
21
|
-
assertString(url, "url");
|
|
22
|
-
assert.ok(url[0] === "/", 'url<String> only accepts relative URLs beginning with "/".');
|
|
23
|
-
assert.ok(options, "options are required");
|
|
24
|
-
return this._requestAxios(url, options)
|
|
25
|
-
.then((response) => {
|
|
26
|
-
const { data, headers, status, statusText, config } = response;
|
|
27
|
-
const requestUrl = config && config.url ? _getAbsoluteUrl({ baseUrl: config.baseURL, url: config.url }) : null;
|
|
28
|
-
return new Response({
|
|
29
|
-
data,
|
|
30
|
-
headers,
|
|
31
|
-
status,
|
|
32
|
-
statusText,
|
|
33
|
-
url: requestUrl,
|
|
34
|
-
});
|
|
35
|
-
})
|
|
36
|
-
.catch((error) => {
|
|
37
|
-
const responseObject = error.response;
|
|
38
|
-
if (!responseObject) {
|
|
39
|
-
throw new Error("Could not make the request.");
|
|
40
|
-
}
|
|
41
|
-
const { data, headers, status, statusText, config } = responseObject;
|
|
42
|
-
const requestUrl = config && config.url ? _getAbsoluteUrl({ baseUrl: config.baseURL, url: config.url }) : null;
|
|
43
|
-
return Promise.reject(new Response({
|
|
44
|
-
data,
|
|
45
|
-
headers,
|
|
46
|
-
status,
|
|
47
|
-
statusText,
|
|
48
|
-
url: requestUrl,
|
|
49
|
-
}));
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { HttpClientRequestConfig, IHttpClient } from "./HttpClient";
|
|
2
|
-
import Response from "./Response";
|
|
3
|
-
export default class MultipartHttpClient implements IHttpClient {
|
|
4
|
-
_httpClient: IHttpClient;
|
|
5
|
-
constructor({ httpClient }: {
|
|
6
|
-
httpClient: IHttpClient;
|
|
7
|
-
});
|
|
8
|
-
static dataToFormData(data: Record<string, string>): FormData;
|
|
9
|
-
request(url: string, options?: HttpClientRequestConfig): Promise<Response>;
|
|
10
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import assert from "@whereby/jslib-media/src/utils/assert";
|
|
2
|
-
export default class MultipartHttpClient {
|
|
3
|
-
constructor({ httpClient }) {
|
|
4
|
-
assert.ok(httpClient, "httpClient is required");
|
|
5
|
-
this._httpClient = httpClient;
|
|
6
|
-
}
|
|
7
|
-
static dataToFormData(data) {
|
|
8
|
-
assert.ok(data, "data is required");
|
|
9
|
-
const fd = new FormData();
|
|
10
|
-
Object.keys(data).forEach((key) => {
|
|
11
|
-
const value = data[key];
|
|
12
|
-
fd.append(key, value);
|
|
13
|
-
});
|
|
14
|
-
return fd;
|
|
15
|
-
}
|
|
16
|
-
request(url, options = {}) {
|
|
17
|
-
const headers = Object.assign(options.headers || {}, {
|
|
18
|
-
"Content-Type": undefined,
|
|
19
|
-
});
|
|
20
|
-
return this._httpClient.request(url, Object.assign(options, {
|
|
21
|
-
headers,
|
|
22
|
-
transformRequest: MultipartHttpClient.dataToFormData,
|
|
23
|
-
}));
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import ApiClient from "./ApiClient";
|
|
2
|
-
import { HttpClientRequestConfig } from "./HttpClient";
|
|
3
|
-
import Response from "./Response";
|
|
4
|
-
import Organization from "./models/Organization";
|
|
5
|
-
export type FetchOrganizationFunction = () => Promise<Organization | undefined>;
|
|
6
|
-
export default class OrganizationApiClient {
|
|
7
|
-
private _apiClient;
|
|
8
|
-
private _fetchOrganization;
|
|
9
|
-
constructor({ apiClient, fetchOrganization, }: {
|
|
10
|
-
apiClient: ApiClient;
|
|
11
|
-
fetchOrganization?: FetchOrganizationFunction;
|
|
12
|
-
});
|
|
13
|
-
_callRequestMethod(method: "request" | "requestMultipart", url: string, options: HttpClientRequestConfig): Promise<Response>;
|
|
14
|
-
request(url: string, options: HttpClientRequestConfig): Promise<Response>;
|
|
15
|
-
requestMultipart(url: string, options: HttpClientRequestConfig): Promise<Response>;
|
|
16
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import assert from "@whereby/jslib-media/src/utils/assert";
|
|
2
|
-
import { assertString } from "./parameterAssertUtils";
|
|
3
|
-
const noOrganization = () => Promise.resolve(undefined);
|
|
4
|
-
export default class OrganizationApiClient {
|
|
5
|
-
constructor({ apiClient, fetchOrganization = noOrganization, }) {
|
|
6
|
-
this._apiClient = apiClient;
|
|
7
|
-
this._fetchOrganization = fetchOrganization;
|
|
8
|
-
this._apiClient = apiClient;
|
|
9
|
-
}
|
|
10
|
-
_callRequestMethod(method, url, options) {
|
|
11
|
-
assertString(url, "url");
|
|
12
|
-
assert.ok(url[0] === "/", 'url<String> only accepts relative URLs beginning with "/".');
|
|
13
|
-
assert.ok(options, "options are required");
|
|
14
|
-
return this._fetchOrganization().then((organization) => {
|
|
15
|
-
if (!organization) {
|
|
16
|
-
return this._apiClient[method](url, options);
|
|
17
|
-
}
|
|
18
|
-
const { organizationId } = organization;
|
|
19
|
-
return this._apiClient[method](`/organizations/${encodeURIComponent(organizationId)}${url}`, options);
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
request(url, options) {
|
|
23
|
-
return this._callRequestMethod("request", url, options);
|
|
24
|
-
}
|
|
25
|
-
requestMultipart(url, options) {
|
|
26
|
-
return this._callRequestMethod("requestMultipart", url, options);
|
|
27
|
-
}
|
|
28
|
-
}
|
package/dist/api/Response.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export type Json = string | number | boolean | null | Array<Json> | {
|
|
2
|
-
[key: string]: Json;
|
|
3
|
-
};
|
|
4
|
-
export type ErrorResponseObject = {
|
|
5
|
-
data?: Json;
|
|
6
|
-
headers?: Record<string, unknown>;
|
|
7
|
-
status?: number;
|
|
8
|
-
statusText?: string;
|
|
9
|
-
config?: {
|
|
10
|
-
url?: string;
|
|
11
|
-
baseURL?: string;
|
|
12
|
-
} | null;
|
|
13
|
-
};
|
|
14
|
-
interface ResponseOptions {
|
|
15
|
-
data?: Json;
|
|
16
|
-
headers?: Record<string, unknown>;
|
|
17
|
-
status?: number;
|
|
18
|
-
statusText?: string;
|
|
19
|
-
url?: string | null;
|
|
20
|
-
}
|
|
21
|
-
export default class Response {
|
|
22
|
-
data: Json;
|
|
23
|
-
headers: Record<string, unknown>;
|
|
24
|
-
status: number;
|
|
25
|
-
statusText: string;
|
|
26
|
-
url: string | null;
|
|
27
|
-
constructor(initialValues?: ResponseOptions);
|
|
28
|
-
}
|
|
29
|
-
export {};
|
package/dist/api/Response.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export default class Response {
|
|
2
|
-
constructor(initialValues = {}) {
|
|
3
|
-
this.data = initialValues.data === undefined ? {} : initialValues.data;
|
|
4
|
-
this.headers = initialValues.headers || {};
|
|
5
|
-
this.status = initialValues.status || 200;
|
|
6
|
-
this.statusText = initialValues.statusText || "OK";
|
|
7
|
-
this.url = initialValues.url || null;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import EventEmitter from "events";
|
|
3
|
-
import DeviceService from "../deviceService/index";
|
|
4
|
-
import AbstractStore from "../modules/AbstractStore";
|
|
5
|
-
import { Credentials } from "..";
|
|
6
|
-
export declare const events: {
|
|
7
|
-
CREDENTIALS_SAVED: string;
|
|
8
|
-
};
|
|
9
|
-
export default class CredentialsService extends EventEmitter {
|
|
10
|
-
_deviceService: DeviceService;
|
|
11
|
-
_credentialsStore: AbstractStore;
|
|
12
|
-
credentialsPromise?: Promise<Credentials | null>;
|
|
13
|
-
constructor({ deviceService, credentialsStore, }: {
|
|
14
|
-
deviceService: DeviceService;
|
|
15
|
-
credentialsStore: AbstractStore;
|
|
16
|
-
});
|
|
17
|
-
static create({ baseUrl, storeName, storeType, }: {
|
|
18
|
-
baseUrl: string;
|
|
19
|
-
storeName?: string;
|
|
20
|
-
storeType?: "localStorage" | "chromeStorage";
|
|
21
|
-
}): CredentialsService;
|
|
22
|
-
_fetchNewCredentialsFromApi(): Promise<Credentials | null>;
|
|
23
|
-
getCurrentCredentials(): Promise<Credentials | null>;
|
|
24
|
-
getCredentials(): Promise<Credentials | null>;
|
|
25
|
-
saveCredentials(credentials: Credentials): Promise<Credentials>;
|
|
26
|
-
setUserId(userId: string | null): Promise<void>;
|
|
27
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import EventEmitter from "events";
|
|
2
|
-
import DeviceService from "../deviceService/index";
|
|
3
|
-
import ChromeStorageStore from "../modules/ChromeStorageStore";
|
|
4
|
-
import LocalStorageStore from "../modules/LocalStorageStore";
|
|
5
|
-
import ApiClient from "../ApiClient";
|
|
6
|
-
import localStorage from "../localStorageWrapper";
|
|
7
|
-
import { Credentials } from "..";
|
|
8
|
-
export const events = {
|
|
9
|
-
CREDENTIALS_SAVED: "credentials_saved",
|
|
10
|
-
};
|
|
11
|
-
export default class CredentialsService extends EventEmitter {
|
|
12
|
-
constructor({ deviceService, credentialsStore, }) {
|
|
13
|
-
super();
|
|
14
|
-
this._deviceService = deviceService;
|
|
15
|
-
this._credentialsStore = credentialsStore;
|
|
16
|
-
}
|
|
17
|
-
static create({ baseUrl, storeName = "CredentialsStorage", storeType = "localStorage", }) {
|
|
18
|
-
const deviceService = new DeviceService({
|
|
19
|
-
apiClient: new ApiClient({ baseUrl }),
|
|
20
|
-
});
|
|
21
|
-
let credentialsStore = null;
|
|
22
|
-
if (storeType === "localStorage") {
|
|
23
|
-
credentialsStore = new LocalStorageStore(storeName, localStorage);
|
|
24
|
-
}
|
|
25
|
-
else if (storeType === "chromeStorage") {
|
|
26
|
-
credentialsStore = new ChromeStorageStore(storeName, window["chrome"].storage.local);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
throw new Error(`Unknown store type: ${storeType}`);
|
|
30
|
-
}
|
|
31
|
-
return new CredentialsService({
|
|
32
|
-
deviceService,
|
|
33
|
-
credentialsStore,
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
_fetchNewCredentialsFromApi() {
|
|
37
|
-
const credentialsStore = this._credentialsStore;
|
|
38
|
-
return new Promise((resolve) => {
|
|
39
|
-
const fetchCredentials = () => {
|
|
40
|
-
this._deviceService
|
|
41
|
-
.getCredentials()
|
|
42
|
-
.then((credentials) => {
|
|
43
|
-
return credentialsStore
|
|
44
|
-
.save(credentials ? credentials.toJson() : null)
|
|
45
|
-
.then(() => resolve(credentials));
|
|
46
|
-
})
|
|
47
|
-
.catch(() => {
|
|
48
|
-
setTimeout(fetchCredentials, 2000);
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
fetchCredentials();
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
getCurrentCredentials() {
|
|
55
|
-
return this._credentialsStore.loadOrDefault(null).then((json) => (json ? Credentials.fromJson(json) : null));
|
|
56
|
-
}
|
|
57
|
-
getCredentials() {
|
|
58
|
-
if (!this.credentialsPromise) {
|
|
59
|
-
this.credentialsPromise = this.getCurrentCredentials().then((storedCredentials) => {
|
|
60
|
-
if (storedCredentials) {
|
|
61
|
-
return storedCredentials;
|
|
62
|
-
}
|
|
63
|
-
return this._fetchNewCredentialsFromApi();
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
return this.credentialsPromise;
|
|
67
|
-
}
|
|
68
|
-
saveCredentials(credentials) {
|
|
69
|
-
this.credentialsPromise = undefined;
|
|
70
|
-
return this._credentialsStore.save(credentials.toJson()).then(() => {
|
|
71
|
-
this.emit(events.CREDENTIALS_SAVED, credentials);
|
|
72
|
-
return credentials;
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
setUserId(userId) {
|
|
76
|
-
return this.getCurrentCredentials()
|
|
77
|
-
.then((storedCredentials) => {
|
|
78
|
-
if (!storedCredentials) {
|
|
79
|
-
console.error("Illegal state: no credentials to set user id for.");
|
|
80
|
-
}
|
|
81
|
-
const userIdChangedFromLocalStorage = storedCredentials === null || storedCredentials.userId !== userId;
|
|
82
|
-
if (!userIdChangedFromLocalStorage) {
|
|
83
|
-
return undefined;
|
|
84
|
-
}
|
|
85
|
-
return this._credentialsStore.save(Object.assign({}, storedCredentials === null || storedCredentials === void 0 ? void 0 : storedCredentials.toJson(), { userId }));
|
|
86
|
-
})
|
|
87
|
-
.then(() => undefined);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import Credentials from "../Credentials";
|
|
2
|
-
export default class DeviceService {
|
|
3
|
-
constructor({ apiClient }) {
|
|
4
|
-
this._apiClient = apiClient;
|
|
5
|
-
}
|
|
6
|
-
getCredentials() {
|
|
7
|
-
return this._apiClient
|
|
8
|
-
.request("/devices", {
|
|
9
|
-
method: "post",
|
|
10
|
-
})
|
|
11
|
-
.then(({ data }) => {
|
|
12
|
-
return Credentials.fromJson(data);
|
|
13
|
-
})
|
|
14
|
-
.catch((error) => {
|
|
15
|
-
if (error.response) {
|
|
16
|
-
if (error.response.status === 404) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
throw error;
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Json } from "./Response";
|
|
2
|
-
export type Extractor<T> = (data: Json, propertyName: string) => T;
|
|
3
|
-
export type Transformer<T> = (data: Json) => T;
|
|
4
|
-
export declare function nullOrTransform<T>(transform: Transformer<T>): Transformer<T | null>;
|
|
5
|
-
export declare function nullOrExtract<T>(extract: Extractor<T>): Extractor<T | null>;
|
|
6
|
-
export declare function extractBoolean(data: Json, propertyName: string): boolean;
|
|
7
|
-
export declare function extractString(data: Json, propertyName: string): string;
|
|
8
|
-
export declare const extractNullOrString: Extractor<string | null>;
|
|
9
|
-
export declare function extractNumber(data: Json, propertyName: string): number;
|
|
10
|
-
export declare const extractNullOrNumber: Extractor<number | null>;
|
|
11
|
-
export declare function extractDate(data: Json, propertyName: string): Date;
|
|
12
|
-
export declare const extractNullOrDate: (data: Json, propertyName: string) => Date | null;
|
|
13
|
-
export declare function extractArrayOfJson(data: Json, propertyName: string): Array<Json>;
|
|
14
|
-
export declare function extractArray<T>(data: Json, propertyName: string, transformer: Transformer<T>): Array<T>;
|
|
15
|
-
export declare function extractJson(data: Json, propertyName: string): Json;
|
|
16
|
-
export declare function extractJsonWithTransform<T>(data: Json, propertyName: string, transformer: Transformer<T>): T;
|
package/dist/api/extractUtils.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { assertArray, assertBoolean, assertNumber, assertRecord, assertString } from "./parameterAssertUtils";
|
|
2
|
-
export function nullOrTransform(transform) {
|
|
3
|
-
return (data) => {
|
|
4
|
-
return data === null || data === undefined ? null : transform(data);
|
|
5
|
-
};
|
|
6
|
-
}
|
|
7
|
-
export function nullOrExtract(extract) {
|
|
8
|
-
return (data, propertyName) => {
|
|
9
|
-
const record = assertRecord(data, "data");
|
|
10
|
-
const value = record[propertyName];
|
|
11
|
-
return value === null || value === undefined ? null : extract(data, propertyName);
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
export function extractBoolean(data, propertyName) {
|
|
15
|
-
const record = assertRecord(data, "data");
|
|
16
|
-
return assertBoolean(record[propertyName], propertyName);
|
|
17
|
-
}
|
|
18
|
-
export function extractString(data, propertyName) {
|
|
19
|
-
const record = assertRecord(data, "data");
|
|
20
|
-
return assertString(record[propertyName], propertyName);
|
|
21
|
-
}
|
|
22
|
-
export const extractNullOrString = nullOrExtract(extractString);
|
|
23
|
-
export function extractNumber(data, propertyName) {
|
|
24
|
-
const record = assertRecord(data, "data");
|
|
25
|
-
return assertNumber(record[propertyName], propertyName);
|
|
26
|
-
}
|
|
27
|
-
export const extractNullOrNumber = nullOrExtract(extractNumber);
|
|
28
|
-
export function extractDate(data, propertyName) {
|
|
29
|
-
const dateString = extractString(data, propertyName);
|
|
30
|
-
const d = new Date(dateString);
|
|
31
|
-
if (isNaN(d.getTime())) {
|
|
32
|
-
throw new Error(`Invalid date for ${dateString}`);
|
|
33
|
-
}
|
|
34
|
-
return d;
|
|
35
|
-
}
|
|
36
|
-
export const extractNullOrDate = nullOrExtract(extractDate);
|
|
37
|
-
export function extractArrayOfJson(data, propertyName) {
|
|
38
|
-
const record = assertRecord(data, "data");
|
|
39
|
-
return assertArray(record[propertyName], propertyName);
|
|
40
|
-
}
|
|
41
|
-
export function extractArray(data, propertyName, transformer) {
|
|
42
|
-
return extractArrayOfJson(data, propertyName).map((value) => transformer(value));
|
|
43
|
-
}
|
|
44
|
-
export function extractJson(data, propertyName) {
|
|
45
|
-
const record = assertRecord(data, "data");
|
|
46
|
-
const value = record[propertyName];
|
|
47
|
-
return value === undefined ? null : value;
|
|
48
|
-
}
|
|
49
|
-
export function extractJsonWithTransform(data, propertyName, transformer) {
|
|
50
|
-
return transformer(extractJson(data, propertyName));
|
|
51
|
-
}
|
package/dist/api/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { default as ApiClient } from "./ApiClient";
|
|
2
|
-
export { default as CredentialsService } from "./credentialsService";
|
|
3
|
-
export { default as Credentials } from "./Credentials";
|
|
4
|
-
export { default as OrganizationApiClient } from "./OrganizationApiClient";
|
|
5
|
-
export { default as OrganizationService } from "./organizationService";
|
|
6
|
-
export { default as OrganizationServiceCache } from "./organizationServiceCache";
|
|
7
|
-
export { default as RoomService } from "./roomService";
|
package/dist/api/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { default as ApiClient } from "./ApiClient";
|
|
2
|
-
export { default as CredentialsService } from "./credentialsService";
|
|
3
|
-
export { default as Credentials } from "./Credentials";
|
|
4
|
-
export { default as OrganizationApiClient } from "./OrganizationApiClient";
|
|
5
|
-
export { default as OrganizationService } from "./organizationService";
|
|
6
|
-
export { default as OrganizationServiceCache } from "./organizationServiceCache";
|
|
7
|
-
export { default as RoomService } from "./roomService";
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
let localStorage;
|
|
2
|
-
try {
|
|
3
|
-
localStorage = self.localStorage;
|
|
4
|
-
}
|
|
5
|
-
catch (e) {
|
|
6
|
-
localStorage = {
|
|
7
|
-
getItem: () => undefined,
|
|
8
|
-
key: () => undefined,
|
|
9
|
-
setItem: () => undefined,
|
|
10
|
-
removeItem: () => undefined,
|
|
11
|
-
hasOwnProperty: () => undefined,
|
|
12
|
-
length: 0,
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
export default localStorage;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import EmbeddedFreeTierStatus from "./account/EmbeddedFreeTierStatus";
|
|
2
|
-
interface AccountProps {
|
|
3
|
-
basePlanId: string | null;
|
|
4
|
-
isDeactivated: boolean;
|
|
5
|
-
isOnTrial: boolean;
|
|
6
|
-
onTrialUntil: Date | null;
|
|
7
|
-
trialStatus: string | null;
|
|
8
|
-
embeddedFreeTierStatus: EmbeddedFreeTierStatus | null;
|
|
9
|
-
}
|
|
10
|
-
export default class Account {
|
|
11
|
-
basePlanId: string | null;
|
|
12
|
-
embeddedFreeTierStatus: EmbeddedFreeTierStatus | null;
|
|
13
|
-
isDeactivated: boolean;
|
|
14
|
-
isOnTrial: boolean;
|
|
15
|
-
onTrialUntil: Date | null;
|
|
16
|
-
trialStatus: string | null;
|
|
17
|
-
constructor({ basePlanId, embeddedFreeTierStatus, isDeactivated, isOnTrial, onTrialUntil, trialStatus, }: AccountProps);
|
|
18
|
-
static fromJson(data: Record<string, unknown>): Account;
|
|
19
|
-
}
|
|
20
|
-
export {};
|