@whereby.com/browser-sdk 2.0.0-alpha → 2.0.0-alpha1
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/dist/lib.cjs.js +5467 -0
- package/dist/lib.esm.js +5451 -0
- package/dist/types.d.ts +104 -0
- package/dist/v2-alpha1.js +105 -0
- package/package.json +2 -1
- package/.eslintrc +0 -23
- package/.github/actions/build/action.yml +0 -17
- package/.github/workflows/deploy.yml +0 -102
- package/.github/workflows/test.yml +0 -24
- package/.prettierignore +0 -7
- package/.prettierrc +0 -4
- package/.storybook/main.cjs +0 -16
- package/.storybook/preview.js +0 -9
- package/jest.config.js +0 -6
- package/rollup.config.js +0 -70
- package/src/lib/RoomConnection.ts +0 -516
- package/src/lib/RoomParticipant.ts +0 -77
- package/src/lib/__tests__/embed.unit.ts +0 -77
- package/src/lib/api/ApiClient.ts +0 -111
- package/src/lib/api/Credentials.ts +0 -45
- package/src/lib/api/HttpClient.ts +0 -95
- package/src/lib/api/MultipartHttpClient.ts +0 -53
- package/src/lib/api/OrganizationApiClient.ts +0 -64
- package/src/lib/api/Response.ts +0 -34
- package/src/lib/api/credentialsService/index.ts +0 -159
- package/src/lib/api/credentialsService/test/index.spec.ts +0 -181
- package/src/lib/api/deviceService/index.ts +0 -42
- package/src/lib/api/deviceService/tests/index.spec.ts +0 -74
- package/src/lib/api/extractUtils.ts +0 -160
- package/src/lib/api/index.ts +0 -8
- package/src/lib/api/localStorageWrapper/index.ts +0 -15
- package/src/lib/api/models/Account.ts +0 -48
- package/src/lib/api/models/Meeting.ts +0 -42
- package/src/lib/api/models/Organization.ts +0 -186
- package/src/lib/api/models/Room.ts +0 -44
- package/src/lib/api/models/account/EmbeddedFreeTierStatus.ts +0 -34
- package/src/lib/api/models/tests/Account.spec.ts +0 -128
- package/src/lib/api/models/tests/Organization.spec.ts +0 -161
- package/src/lib/api/models/tests/Room.spec.ts +0 -74
- package/src/lib/api/modules/AbstractStore.ts +0 -18
- package/src/lib/api/modules/ChromeStorageStore.ts +0 -44
- package/src/lib/api/modules/LocalStorageStore.ts +0 -57
- package/src/lib/api/modules/tests/ChromeStorageStore.spec.ts +0 -67
- package/src/lib/api/modules/tests/LocalStorageStore.spec.ts +0 -79
- package/src/lib/api/modules/tests/__mocks__/storage.ts +0 -24
- package/src/lib/api/organizationService/index.ts +0 -284
- package/src/lib/api/organizationService/tests/index.spec.ts +0 -781
- package/src/lib/api/organizationServiceCache/index.ts +0 -28
- package/src/lib/api/organizationServiceCache/tests/index.spec.ts +0 -101
- package/src/lib/api/parameterAssertUtils.ts +0 -166
- package/src/lib/api/roomService/index.ts +0 -310
- package/src/lib/api/roomService/tests/index.spec.ts +0 -668
- package/src/lib/api/test/ApiClient.spec.ts +0 -139
- package/src/lib/api/test/HttpClient.spec.ts +0 -120
- package/src/lib/api/test/MultipartHttpClient.spec.ts +0 -145
- package/src/lib/api/test/OrganizationApiClient.spec.ts +0 -132
- package/src/lib/api/test/extractUtils.spec.ts +0 -357
- package/src/lib/api/test/helpers.ts +0 -41
- package/src/lib/api/test/parameterAssertUtils.spec.ts +0 -265
- package/src/lib/api/types.ts +0 -6
- package/src/lib/embed.ts +0 -172
- package/src/lib/index.ts +0 -3
- package/src/lib/react/VideoElement.tsx +0 -16
- package/src/lib/react/index.ts +0 -3
- package/src/lib/react/useLocalMedia.ts +0 -25
- package/src/lib/react/useRoomConnection.ts +0 -92
- package/src/lib/reducer.ts +0 -142
- package/src/stories/custom-ui.stories.tsx +0 -133
- package/src/stories/prebuilt-ui.stories.tsx +0 -131
- package/src/stories/styles.css +0 -74
- package/src/types.d.ts +0 -175
- package/tsconfig.json +0 -30
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
import ApiClient from "../../ApiClient";
|
|
3
|
-
import Credentials from "../../Credentials";
|
|
4
|
-
import CredentialsService, { events } from "../index";
|
|
5
|
-
import LocalStorageStore from "../../modules/LocalStorageStore";
|
|
6
|
-
import DeviceService from "../../deviceService/index";
|
|
7
|
-
|
|
8
|
-
jest.mock("../../modules/LocalStorageStore")
|
|
9
|
-
jest.mock("../../deviceService")
|
|
10
|
-
|
|
11
|
-
describe("CredentialsService", () => {
|
|
12
|
-
let apiClient;
|
|
13
|
-
let deviceService;
|
|
14
|
-
let credentialsStore;
|
|
15
|
-
let credentialsService;
|
|
16
|
-
let storedCredentials;
|
|
17
|
-
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
apiClient = new ApiClient() as jest.Mocked<ApiClient>;
|
|
20
|
-
credentialsStore = new LocalStorageStore;
|
|
21
|
-
deviceService = new DeviceService({ apiClient });
|
|
22
|
-
credentialsService = new CredentialsService({
|
|
23
|
-
deviceService,
|
|
24
|
-
credentialsStore,
|
|
25
|
-
});
|
|
26
|
-
storedCredentials = new Credentials("test-stored-uuid", "test-stored-hmac");
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe("getCurrentCredentials", () => {
|
|
30
|
-
it("should load credentials from the store", async () => {
|
|
31
|
-
credentialsStore.loadOrDefault.mockResolvedValue(storedCredentials.toJson());
|
|
32
|
-
|
|
33
|
-
const result = await credentialsService.getCurrentCredentials();
|
|
34
|
-
|
|
35
|
-
expect(result).toEqual(storedCredentials);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("should load credentials from the store", () => {
|
|
39
|
-
credentialsStore.loadOrDefault.mockResolvedValue(storedCredentials.toJson());
|
|
40
|
-
|
|
41
|
-
credentialsService.getCurrentCredentials();
|
|
42
|
-
|
|
43
|
-
return expect(credentialsStore.loadOrDefault).toBeCalled();
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
describe("getCredentials", () => {
|
|
48
|
-
describe("when no credentials are available in localStorage", () => {
|
|
49
|
-
let apiCredentials;
|
|
50
|
-
beforeEach(() => {
|
|
51
|
-
apiCredentials = new Credentials("test-fetched-uuid", "test-fetched-hmac");
|
|
52
|
-
credentialsStore.loadOrDefault.mockResolvedValue(null);
|
|
53
|
-
credentialsStore.save.mockResolvedValue();
|
|
54
|
-
deviceService.getCredentials.mockResolvedValue(apiCredentials);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("should save the fetched credentials to credentialsStore", () => {
|
|
58
|
-
const promise = credentialsService.getCredentials();
|
|
59
|
-
|
|
60
|
-
return promise.then(() => {
|
|
61
|
-
expect(credentialsStore.save).toBeCalledWith(apiCredentials.toJson());
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it("should fetch new credentials from the API", async () => {
|
|
66
|
-
await credentialsService.getCredentials();
|
|
67
|
-
|
|
68
|
-
expect(deviceService.getCredentials).toBeCalledTimes(1);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("should resolve with the credentials from the api", async () => {
|
|
72
|
-
const result = await credentialsService.getCredentials();
|
|
73
|
-
|
|
74
|
-
return expect(result).toEqual(apiCredentials);
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
describe("when credentials are available in localStorage", () => {
|
|
79
|
-
beforeEach(() => {
|
|
80
|
-
credentialsStore.loadOrDefault.mockResolvedValue(storedCredentials);
|
|
81
|
-
deviceService.getCredentials.mockResolvedValue(null);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("should not fetch new credentials from the api", () => {
|
|
85
|
-
const promise = credentialsService.getCredentials();
|
|
86
|
-
|
|
87
|
-
return promise.then(() => {
|
|
88
|
-
expect(deviceService.getCredentials).not.toBeCalled();
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it("should return credentials from localstorage", async () => {
|
|
93
|
-
const result = await credentialsService.getCredentials();
|
|
94
|
-
|
|
95
|
-
expect(result).toEqual(storedCredentials);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
describe("saveCredentials", () => {
|
|
101
|
-
it("should save the credentials to localStorage", () => {
|
|
102
|
-
credentialsStore.save.mockResolvedValue();
|
|
103
|
-
|
|
104
|
-
const promise = credentialsService.saveCredentials(storedCredentials);
|
|
105
|
-
|
|
106
|
-
return promise.then(() => {
|
|
107
|
-
expect(credentialsStore.save).toBeCalledWith(storedCredentials.toJson());
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("should fire the CREDENTIALS_SAVED event", () => {
|
|
112
|
-
credentialsStore.save.mockResolvedValue();
|
|
113
|
-
const callback = jest.fn();
|
|
114
|
-
credentialsService.on(events.CREDENTIALS_SAVED, callback);
|
|
115
|
-
|
|
116
|
-
const promise = credentialsService.saveCredentials(storedCredentials);
|
|
117
|
-
|
|
118
|
-
return promise.then(() => {
|
|
119
|
-
expect(callback).toBeCalled();
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
describe("setUserId", () => {
|
|
125
|
-
const mockUserId = "1234ef-987654-a1b2cd3e";
|
|
126
|
-
|
|
127
|
-
describe("when no credentials are stored", () => {
|
|
128
|
-
beforeEach(() => {
|
|
129
|
-
jest.spyOn(console, "error").mockClear().mockImplementation();
|
|
130
|
-
credentialsStore.loadOrDefault.mockResolvedValue(null);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
afterEach(() => {
|
|
134
|
-
console.error.mockRestore(); // eslint-disable-line no-console
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it("should call log an error", () => {
|
|
138
|
-
const promise = credentialsService.setUserId(mockUserId);
|
|
139
|
-
|
|
140
|
-
return promise.then(() => {
|
|
141
|
-
expect(console.error).toBeCalled(); // eslint-disable-line no-console
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it("should return undefined", async () => {
|
|
146
|
-
const result = await credentialsService.setUserId(mockUserId);
|
|
147
|
-
|
|
148
|
-
expect(result).toBeUndefined();
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
describe("when have been credentials have been stored", () => {
|
|
153
|
-
[null, "some-new-userId"].forEach((newUserId) => {
|
|
154
|
-
let credentialsWithUserId;
|
|
155
|
-
beforeEach(() => {
|
|
156
|
-
credentialsWithUserId = new Credentials("some-uuid", "some-hmac", "some-userId");
|
|
157
|
-
credentialsStore.loadOrDefault.mockResolvedValue(credentialsWithUserId);
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it("should return undefined", async () => {
|
|
161
|
-
const result = await credentialsService.setUserId(newUserId);
|
|
162
|
-
|
|
163
|
-
expect(result).toBeUndefined();
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it(
|
|
167
|
-
"should set the userId property in the credentials and store them when it has changed",
|
|
168
|
-
() => {
|
|
169
|
-
const expectedCredentials = Object.assign({}, credentialsWithUserId, { userId: newUserId });
|
|
170
|
-
|
|
171
|
-
const promise = credentialsService.setUserId(newUserId);
|
|
172
|
-
|
|
173
|
-
return promise.then(() => {
|
|
174
|
-
expect(credentialsStore.save).toBeCalledWith(expectedCredentials);
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
);
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import ApiClient from "../ApiClient";
|
|
2
|
-
import { assertInstanceOf } from "../parameterAssertUtils";
|
|
3
|
-
import Credentials from "../Credentials";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Related to device calls needed to obtain credentials
|
|
7
|
-
*/
|
|
8
|
-
export default class DeviceService {
|
|
9
|
-
_apiClient: ApiClient;
|
|
10
|
-
|
|
11
|
-
constructor({ apiClient }: { apiClient: ApiClient }) {
|
|
12
|
-
this._apiClient = assertInstanceOf(apiClient, ApiClient);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Get's the device credentials needed for most of the other API services
|
|
17
|
-
*
|
|
18
|
-
* @return {Promise} A promise which is fulfilled or failed based on the
|
|
19
|
-
* response.
|
|
20
|
-
*/
|
|
21
|
-
getCredentials(): Promise<Credentials | null> {
|
|
22
|
-
return this._apiClient
|
|
23
|
-
.request("/devices", {
|
|
24
|
-
method: "post",
|
|
25
|
-
})
|
|
26
|
-
.then(({ data }) => {
|
|
27
|
-
return Credentials.fromJson(data);
|
|
28
|
-
})
|
|
29
|
-
.catch((error) => {
|
|
30
|
-
if (error.response) {
|
|
31
|
-
// The request was made, but the server responded with a status code
|
|
32
|
-
// that falls out of the range of 2xx
|
|
33
|
-
if (error.response.status === 404) {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Something happened in setting up the request that triggered an Error
|
|
39
|
-
throw error;
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import DeviceService from "../index";
|
|
2
|
-
import ApiClient from "../../ApiClient";
|
|
3
|
-
import Credentials from "../../Credentials";
|
|
4
|
-
import { itShouldThrowIfInvalid } from "../../test/helpers";
|
|
5
|
-
import Response from "../../Response";
|
|
6
|
-
|
|
7
|
-
jest.mock("../../ApiClient");
|
|
8
|
-
|
|
9
|
-
const credentials = {
|
|
10
|
-
credentials: {
|
|
11
|
-
uuid: "12345",
|
|
12
|
-
},
|
|
13
|
-
hmac: "67890",
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
describe("deviceService", () => {
|
|
17
|
-
let apiClient: jest.Mocked<ApiClient>;
|
|
18
|
-
let deviceService: DeviceService;
|
|
19
|
-
|
|
20
|
-
beforeEach(() => {
|
|
21
|
-
apiClient = new ApiClient() as jest.Mocked<ApiClient>;
|
|
22
|
-
deviceService = new DeviceService({ apiClient });
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
describe("constructor", () => {
|
|
26
|
-
itShouldThrowIfInvalid(
|
|
27
|
-
"apiClient",
|
|
28
|
-
() =>
|
|
29
|
-
new DeviceService({
|
|
30
|
-
//@ts-expect-error
|
|
31
|
-
apiClient: undefined,
|
|
32
|
-
})
|
|
33
|
-
);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
describe("getCredentials", () => {
|
|
37
|
-
const url = "/devices";
|
|
38
|
-
const method = "post";
|
|
39
|
-
|
|
40
|
-
beforeEach(() => {
|
|
41
|
-
apiClient.request.mockResolvedValue(new Response({ data: credentials }));
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("should call request with correct params", async () => {
|
|
45
|
-
await deviceService.getCredentials();
|
|
46
|
-
|
|
47
|
-
expect(apiClient.request).toBeCalledWith(url, {
|
|
48
|
-
method,
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it("should be fulfilled with the credentials success", async () => {
|
|
53
|
-
const result = await deviceService.getCredentials();
|
|
54
|
-
|
|
55
|
-
expect(result).toEqual(new Credentials(credentials.credentials.uuid, credentials.hmac));
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("should fail if the request failed", async () => {
|
|
59
|
-
const error = new Error("some error");
|
|
60
|
-
apiClient.request.mockRejectedValue(error);
|
|
61
|
-
|
|
62
|
-
await expect(deviceService.getCredentials()).rejects.toThrow(error);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it("should return null if the server is down", async () => {
|
|
66
|
-
const response = { response: { status: 404 } };
|
|
67
|
-
apiClient.request.mockRejectedValue(response);
|
|
68
|
-
|
|
69
|
-
const result = await deviceService.getCredentials();
|
|
70
|
-
|
|
71
|
-
expect(result).toEqual(null);
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
});
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { assertArray, assertBoolean, assertNumber, assertRecord, assertString } from "./parameterAssertUtils";
|
|
2
|
-
import { Json } from "./Response";
|
|
3
|
-
|
|
4
|
-
export type Extractor<T> = (data: Json, propertyName: string) => T;
|
|
5
|
-
export type Transformer<T> = (data: Json) => T;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Utility function to transform the given transformer function into a
|
|
9
|
-
* function that handles `undefined` and `null` values.
|
|
10
|
-
*
|
|
11
|
-
* @param transformer - Function to transform
|
|
12
|
-
* @returns the transformed function.
|
|
13
|
-
*/
|
|
14
|
-
export function nullOrTransform<T>(transform: Transformer<T>): Transformer<T | null> {
|
|
15
|
-
return (data: Json): T | null => {
|
|
16
|
-
return data === null || data === undefined ? null : transform(data);
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Utility function to transform the given extract function to allow
|
|
22
|
-
* `undefined` and `null` values.
|
|
23
|
-
* @param extract - Function to transform
|
|
24
|
-
* @returns the transformed function.
|
|
25
|
-
*/
|
|
26
|
-
export function nullOrExtract<T>(extract: Extractor<T>): Extractor<T | null> {
|
|
27
|
-
return (data: Json, propertyName: string): T | null => {
|
|
28
|
-
const record = assertRecord(data, "data");
|
|
29
|
-
|
|
30
|
-
const value = record[propertyName];
|
|
31
|
-
return value === null || value === undefined ? null : extract(data, propertyName);
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Extract a boolean from the given Json object.
|
|
37
|
-
* If the value is not a boolean, an error is thrown.
|
|
38
|
-
*
|
|
39
|
-
* @param data - the object to extract the value from
|
|
40
|
-
* @param propertyName - the name of the parameter to extract
|
|
41
|
-
* @returns the extracted value
|
|
42
|
-
*/
|
|
43
|
-
export function extractBoolean(data: Json, propertyName: string): boolean {
|
|
44
|
-
const record = assertRecord(data, "data");
|
|
45
|
-
return assertBoolean(record[propertyName], propertyName);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Extract a string from the given Json object.
|
|
50
|
-
* If the value is not a string, an error is thrown.
|
|
51
|
-
*
|
|
52
|
-
* @param data - the object to extract the value from
|
|
53
|
-
* @param propertyName - the name of the parameter to extract
|
|
54
|
-
* @returns the extracted value
|
|
55
|
-
*/
|
|
56
|
-
export function extractString(data: Json, propertyName: string): string {
|
|
57
|
-
const record = assertRecord(data, "data");
|
|
58
|
-
return assertString(record[propertyName], propertyName);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export const extractNullOrString = nullOrExtract(extractString);
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Extract a number from the given Json object.
|
|
65
|
-
* If the value is not a number, an error is thrown.
|
|
66
|
-
*
|
|
67
|
-
* @param data - the object to extract the value from
|
|
68
|
-
* @param propertyName - the name of the parameter to extract
|
|
69
|
-
* @returns the extracted value
|
|
70
|
-
*/
|
|
71
|
-
export function extractNumber(data: Json, propertyName: string): number {
|
|
72
|
-
const record = assertRecord(data, "data");
|
|
73
|
-
return assertNumber(record[propertyName], propertyName);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export const extractNullOrNumber = nullOrExtract(extractNumber);
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Extract a Date from the given Json object.
|
|
80
|
-
* If the value is not a valid Date, an error is thrown.
|
|
81
|
-
*
|
|
82
|
-
* @param data - the object to extract the value from
|
|
83
|
-
* @param propertyName - the name of the parameter to extract
|
|
84
|
-
* @returns the extracted value
|
|
85
|
-
*/
|
|
86
|
-
export function extractDate(data: Json, propertyName: string): Date {
|
|
87
|
-
const dateString = extractString(data, propertyName);
|
|
88
|
-
const d = new Date(dateString);
|
|
89
|
-
if (isNaN(d.getTime())) {
|
|
90
|
-
throw new Error(`Invalid date for ${dateString}`);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return d;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export const extractNullOrDate: (data: Json, propertyName: string) => Date | null = nullOrExtract(extractDate);
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Extract an Array from the given Json object.
|
|
100
|
-
* If the value is not a valid Array, an error is thrown.
|
|
101
|
-
*
|
|
102
|
-
* @param data - the object to extract the value from
|
|
103
|
-
* @param propertyName - the name of the parameter to extract
|
|
104
|
-
* @returns the extracted value
|
|
105
|
-
**/
|
|
106
|
-
export function extractArrayOfJson(data: Json, propertyName: string): Array<Json> {
|
|
107
|
-
const record = assertRecord(data, "data");
|
|
108
|
-
return assertArray(record[propertyName], propertyName) as Array<Json>;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Extract an Array from the given Json object and run the provided
|
|
113
|
-
* transformer on all of the provided values.
|
|
114
|
-
* If the value is not a valid Array, an error is thrown.
|
|
115
|
-
*
|
|
116
|
-
* @param data - the object to extract the value from
|
|
117
|
-
* @param propertyName - the name of the parameter to extract
|
|
118
|
-
* @param transformer - A function to transform all the Json elements extracted from the parameter
|
|
119
|
-
* @returns the extracted value
|
|
120
|
-
**/
|
|
121
|
-
export function extractArray<T>(data: Json, propertyName: string, transformer: Transformer<T>): Array<T> {
|
|
122
|
-
return extractArrayOfJson(data, propertyName).map((value) => transformer(value));
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Extract a Json object from the given Json object.
|
|
127
|
-
* If the value is not a valid Json object, an error is thrown.
|
|
128
|
-
*
|
|
129
|
-
* Note, if the extracted value is undefined, null will be returned
|
|
130
|
-
* since the extractor functions don't distinguish an undefined value
|
|
131
|
-
* and a null value.
|
|
132
|
-
*
|
|
133
|
-
* @param data - the object to extract the value from
|
|
134
|
-
* @param propertyName - the name of the parameter to extract
|
|
135
|
-
* @returns the extracted value
|
|
136
|
-
*/
|
|
137
|
-
export function extractJson(data: Json, propertyName: string): Json {
|
|
138
|
-
const record = assertRecord(data, "data") as Record<string, Json>;
|
|
139
|
-
|
|
140
|
-
const value = record[propertyName];
|
|
141
|
-
return value === undefined ? null : value;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Extract a Json object from the given Json object and transform
|
|
146
|
-
* that value using the given transformer function.
|
|
147
|
-
* If the provided json object is not a valid Json object, an error is thrown.
|
|
148
|
-
*
|
|
149
|
-
* Note, if the extracted value is undefined, null will be returned
|
|
150
|
-
* since the extractor functions don't distinguish an undefined value
|
|
151
|
-
* and a null value.
|
|
152
|
-
*
|
|
153
|
-
* @param data - the object to extract the value from
|
|
154
|
-
* @param propertyName - the name of the parameter to extract
|
|
155
|
-
* @param transformer - A function to transform the extracted value
|
|
156
|
-
* @returns the extracted and transformed value
|
|
157
|
-
**/
|
|
158
|
-
export function extractJsonWithTransform<T>(data: Json, propertyName: string, transformer: Transformer<T>): T {
|
|
159
|
-
return transformer(extractJson(data, propertyName));
|
|
160
|
-
}
|
package/src/lib/api/index.ts
DELETED
|
@@ -1,8 +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"
|
|
8
|
-
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
let localStorage;
|
|
2
|
-
try {
|
|
3
|
-
localStorage = self.localStorage;
|
|
4
|
-
} catch (e) {
|
|
5
|
-
localStorage = {
|
|
6
|
-
getItem: (): undefined => undefined,
|
|
7
|
-
key: (): undefined => undefined,
|
|
8
|
-
setItem: (): undefined => undefined,
|
|
9
|
-
removeItem: (): undefined => undefined,
|
|
10
|
-
hasOwnProperty: (): undefined => undefined,
|
|
11
|
-
length: 0,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default localStorage as Storage;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { assertBoolean } from "../parameterAssertUtils";
|
|
2
|
-
import EmbeddedFreeTierStatus from "./account/EmbeddedFreeTierStatus";
|
|
3
|
-
|
|
4
|
-
interface AccountProps {
|
|
5
|
-
basePlanId: string | null;
|
|
6
|
-
isDeactivated: boolean;
|
|
7
|
-
isOnTrial: boolean;
|
|
8
|
-
onTrialUntil: Date | null;
|
|
9
|
-
trialStatus: string | null;
|
|
10
|
-
embeddedFreeTierStatus: EmbeddedFreeTierStatus | null;
|
|
11
|
-
}
|
|
12
|
-
export default class Account {
|
|
13
|
-
basePlanId: string | null;
|
|
14
|
-
embeddedFreeTierStatus: EmbeddedFreeTierStatus | null;
|
|
15
|
-
isDeactivated: boolean;
|
|
16
|
-
isOnTrial: boolean;
|
|
17
|
-
onTrialUntil: Date | null;
|
|
18
|
-
trialStatus: string | null;
|
|
19
|
-
|
|
20
|
-
constructor({
|
|
21
|
-
basePlanId,
|
|
22
|
-
embeddedFreeTierStatus,
|
|
23
|
-
isDeactivated,
|
|
24
|
-
isOnTrial,
|
|
25
|
-
onTrialUntil,
|
|
26
|
-
trialStatus,
|
|
27
|
-
}: AccountProps) {
|
|
28
|
-
this.basePlanId = basePlanId;
|
|
29
|
-
this.isDeactivated = isDeactivated;
|
|
30
|
-
this.isOnTrial = isOnTrial;
|
|
31
|
-
this.onTrialUntil = onTrialUntil || null;
|
|
32
|
-
this.trialStatus = trialStatus || null;
|
|
33
|
-
this.embeddedFreeTierStatus = embeddedFreeTierStatus || null;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
static fromJson(data: Record<string, unknown>): Account {
|
|
37
|
-
return new Account({
|
|
38
|
-
basePlanId: typeof data.basePlanId === "string" ? data.basePlanId : null,
|
|
39
|
-
isDeactivated: assertBoolean(data.isDeactivated, "isDeactivated"),
|
|
40
|
-
isOnTrial: assertBoolean(data.isOnTrial, "isOnTrial"),
|
|
41
|
-
onTrialUntil: typeof data.onTrialUntil === "string" ? new Date(data.onTrialUntil) : null,
|
|
42
|
-
trialStatus: typeof data.trialStatus === "string" ? data.trialStatus : null,
|
|
43
|
-
embeddedFreeTierStatus: data.embeddedFreeTierStatus
|
|
44
|
-
? EmbeddedFreeTierStatus.fromJson(data.embeddedFreeTierStatus as Record<string, unknown>)
|
|
45
|
-
: null,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { extractDate, extractNullOrString, extractString } from "../extractUtils";
|
|
2
|
-
import { assertString, assertInstanceOf } from "../parameterAssertUtils";
|
|
3
|
-
import { Json } from "../Response";
|
|
4
|
-
|
|
5
|
-
export default class Meeting {
|
|
6
|
-
meetingId: string;
|
|
7
|
-
roomName: string;
|
|
8
|
-
roomUrl: string;
|
|
9
|
-
startDate: Date;
|
|
10
|
-
endDate: Date;
|
|
11
|
-
hostRoomUrl: string | null;
|
|
12
|
-
viewerRoomUrl: string | null;
|
|
13
|
-
|
|
14
|
-
constructor({ meetingId, roomName, roomUrl, startDate, endDate, hostRoomUrl, viewerRoomUrl }: Meeting) {
|
|
15
|
-
assertString(meetingId, "meetingId");
|
|
16
|
-
assertString(roomName, "roomName");
|
|
17
|
-
assertString(roomUrl, "roomUrl");
|
|
18
|
-
|
|
19
|
-
assertInstanceOf(startDate, Date, "startDate");
|
|
20
|
-
assertInstanceOf(endDate, Date, "endDate");
|
|
21
|
-
|
|
22
|
-
this.meetingId = meetingId;
|
|
23
|
-
this.roomName = roomName;
|
|
24
|
-
this.roomUrl = roomUrl;
|
|
25
|
-
this.startDate = startDate;
|
|
26
|
-
this.endDate = endDate;
|
|
27
|
-
this.hostRoomUrl = hostRoomUrl;
|
|
28
|
-
this.viewerRoomUrl = viewerRoomUrl;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
static fromJson(data: Json): Meeting {
|
|
32
|
-
return new Meeting({
|
|
33
|
-
meetingId: extractString(data, "meetingId"),
|
|
34
|
-
roomName: extractString(data, "roomName"),
|
|
35
|
-
roomUrl: extractString(data, "roomUrl"),
|
|
36
|
-
startDate: extractDate(data, "startDate"),
|
|
37
|
-
endDate: extractDate(data, "endDate"),
|
|
38
|
-
hostRoomUrl: extractNullOrString(data, "hostRoomUrl"),
|
|
39
|
-
viewerRoomUrl: extractNullOrString(data, "viewerRoomUrl"),
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}
|