@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,57 +0,0 @@
|
|
|
1
|
-
import { assertString, assertTruthy } from "../parameterAssertUtils";
|
|
2
|
-
import { Json } from "../Response";
|
|
3
|
-
import AbstractStore from "./AbstractStore";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Utility to ease handling localStorage.
|
|
7
|
-
*/
|
|
8
|
-
export default class LocalStorageStore implements AbstractStore {
|
|
9
|
-
_key: string;
|
|
10
|
-
_localStorage: Storage;
|
|
11
|
-
|
|
12
|
-
constructor(key: string, localStorage: Storage) {
|
|
13
|
-
assertTruthy(localStorage, "localStorage");
|
|
14
|
-
this._key = assertString(key, "key");
|
|
15
|
-
this._localStorage = localStorage;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Returns the stored value for this store, or a default if not available.
|
|
20
|
-
*
|
|
21
|
-
* @param {(Object|Array.|string|number)} [defaultValue] - Value returned if the object can't be retrieved.
|
|
22
|
-
* @return {?(Object|Array.|string|number)} Value stored, or defaultValue if not available.
|
|
23
|
-
*/
|
|
24
|
-
loadOrDefault(defaultValue: Json): Promise<Json> {
|
|
25
|
-
try {
|
|
26
|
-
const value = this._localStorage.getItem(this._key);
|
|
27
|
-
if (value) {
|
|
28
|
-
try {
|
|
29
|
-
return Promise.resolve(JSON.parse(value));
|
|
30
|
-
} catch (e) {
|
|
31
|
-
/* NOOP */
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return Promise.resolve(defaultValue);
|
|
35
|
-
} catch (e) {
|
|
36
|
-
// Cookies are blocked
|
|
37
|
-
console.warn("Error getting access to storage. Are cookies blocked?", e); // eslint-disable-line no-console
|
|
38
|
-
return Promise.resolve(defaultValue);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Change the value stored for this key.
|
|
44
|
-
*
|
|
45
|
-
* @param {(Object|Array.|string|number)} [value] - New value, will replace any previously stored.
|
|
46
|
-
*/
|
|
47
|
-
save(value: Json): Promise<void> {
|
|
48
|
-
try {
|
|
49
|
-
this._localStorage.setItem(this._key, JSON.stringify(value));
|
|
50
|
-
return Promise.resolve();
|
|
51
|
-
} catch (e) {
|
|
52
|
-
/* NOOP, cookies are blocked */
|
|
53
|
-
console.warn("Error getting access to storage. Are cookies blocked?", e); // eslint-disable-line no-console
|
|
54
|
-
return Promise.reject(e);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import ChromeStorageStore from "../ChromeStorageStore";
|
|
2
|
-
|
|
3
|
-
describe("ChromeStorageStore", () => {
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
-
let chromeStorage: any;
|
|
6
|
-
const storeName = "myStore1";
|
|
7
|
-
let credentialsStore: ChromeStorageStore;
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
chromeStorage = {
|
|
11
|
-
get: jest.fn(() => ({})),
|
|
12
|
-
set: jest.fn(),
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
credentialsStore = new ChromeStorageStore(storeName, chromeStorage);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe("loadOrDefault", () => {
|
|
19
|
-
it("should resolve with the stored object", async () => {
|
|
20
|
-
const savedValue = { mrT: "I pitty the fool" };
|
|
21
|
-
chromeStorage.get.mockImplementation((key: string, cb: any) => {
|
|
22
|
-
cb({ [storeName]: savedValue });
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const result = await credentialsStore.loadOrDefault({});
|
|
26
|
-
|
|
27
|
-
expect(result).toEqual(savedValue);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("should resolve with the default value if a stored object cannot be retrieved", async () => {
|
|
31
|
-
const defaultValue = { mrT: "I pitty the fool" };
|
|
32
|
-
chromeStorage.get.mockImplementation((key: string, cb: any) => {
|
|
33
|
-
cb(defaultValue);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
const result = await credentialsStore.loadOrDefault(defaultValue);
|
|
37
|
-
|
|
38
|
-
expect(result).toEqual(defaultValue);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe("save", () => {
|
|
43
|
-
it("should save the object to local storage", async () => {
|
|
44
|
-
const savedValue = { mrT: "I pitty the fool" };
|
|
45
|
-
chromeStorage.set.mockImplementation((obj: any, cb: any) => {
|
|
46
|
-
cb();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
await credentialsStore.save(savedValue);
|
|
50
|
-
|
|
51
|
-
// The first arg of the first call to the function
|
|
52
|
-
// The 2nd arg is the Promise.resolve anonymous fn
|
|
53
|
-
expect(chromeStorage.set.mock.calls[0][0]).toEqual({ [storeName]: savedValue });
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("should return undefined", async () => {
|
|
57
|
-
const savedValue = { mrT: "I pitty the fool" };
|
|
58
|
-
chromeStorage.set.mockImplementation((obj: any, cb: any) => {
|
|
59
|
-
cb();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const result = await credentialsStore.save(savedValue);
|
|
63
|
-
|
|
64
|
-
expect(result).toBeUndefined();
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
});
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import LocalStorageStore from "../LocalStorageStore";
|
|
2
|
-
import { itShouldThrowIfInvalid } from "../../test/helpers";
|
|
3
|
-
import DummyStore from "./__mocks__/storage";
|
|
4
|
-
|
|
5
|
-
jest.mock("./__mocks__/storage");
|
|
6
|
-
|
|
7
|
-
describe("LocalStorageStore", () => {
|
|
8
|
-
const storeName = "myStore";
|
|
9
|
-
let credentialsStore: LocalStorageStore;
|
|
10
|
-
let localStorage: jest.Mocked<DummyStore>;
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
localStorage = new DummyStore() as jest.Mocked<DummyStore>;
|
|
14
|
-
credentialsStore = new LocalStorageStore(storeName, localStorage);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
afterEach(() => {
|
|
18
|
-
jest.clearAllMocks();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
describe("constructor", () => {
|
|
22
|
-
//@ts-expect-error
|
|
23
|
-
itShouldThrowIfInvalid("key", () => new LocalStorageStore(undefined, localStorage));
|
|
24
|
-
//@ts-expect-error
|
|
25
|
-
itShouldThrowIfInvalid("localStorage", () => new LocalStorageStore(storeName, undefined));
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
describe("loadOrDefault", () => {
|
|
29
|
-
it("should resolve with the stored object if available", async () => {
|
|
30
|
-
const savedValue = { mrT: "I pitty the fool" };
|
|
31
|
-
localStorage.getItem.mockImplementation((key: string) => {
|
|
32
|
-
if (key === storeName) {
|
|
33
|
-
return JSON.stringify(savedValue);
|
|
34
|
-
} else {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
const result = await credentialsStore.loadOrDefault({});
|
|
40
|
-
|
|
41
|
-
expect(result).toEqual(savedValue);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("should resolve with the default value if the stored object cannot be retrieved", async () => {
|
|
45
|
-
const defaultValue = { mrT: "I pitty the fool" };
|
|
46
|
-
localStorage.getItem.mockImplementation((key: string) => {
|
|
47
|
-
if (key === storeName) {
|
|
48
|
-
return "This is not valid json";
|
|
49
|
-
} else {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
const result = await credentialsStore.loadOrDefault(defaultValue);
|
|
55
|
-
|
|
56
|
-
expect(result).toEqual(defaultValue);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it("should resolve with the default value if no object has been stored", async () => {
|
|
60
|
-
const defaultValue = { mrT: "I pitty the fool" };
|
|
61
|
-
localStorage.getItem.mockReturnValue(null);
|
|
62
|
-
const result = await credentialsStore.loadOrDefault(defaultValue);
|
|
63
|
-
expect(result).toEqual(defaultValue);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe("save", () => {
|
|
68
|
-
it("should save the object to local storage", () => {
|
|
69
|
-
const savedValue = { mrT: "I pitty the fool" };
|
|
70
|
-
const expectedValue = JSON.stringify(savedValue);
|
|
71
|
-
|
|
72
|
-
const promise = credentialsStore.save(savedValue);
|
|
73
|
-
|
|
74
|
-
return promise.then(() => {
|
|
75
|
-
expect(localStorage.setItem).toBeCalledWith(storeName, expectedValue);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export default class DummyStore implements Storage {
|
|
2
|
-
[name: string]: unknown;
|
|
3
|
-
length: number;
|
|
4
|
-
|
|
5
|
-
constructor() {
|
|
6
|
-
this.length = 0;
|
|
7
|
-
}
|
|
8
|
-
clear(): void {
|
|
9
|
-
throw new Error("Method not implemented.");
|
|
10
|
-
}
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
12
|
-
getItem(_key: string): string | null {
|
|
13
|
-
return "{}";
|
|
14
|
-
}
|
|
15
|
-
key(): string | null {
|
|
16
|
-
throw new Error("Method not implemented.");
|
|
17
|
-
}
|
|
18
|
-
removeItem(): void {
|
|
19
|
-
throw new Error("Method not implemented.");
|
|
20
|
-
}
|
|
21
|
-
setItem(): void {
|
|
22
|
-
// NOP
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
import assert from "assert";
|
|
2
|
-
import Organization, { OrganizationPreferences } from "../models/Organization";
|
|
3
|
-
import {
|
|
4
|
-
assertInstanceOf,
|
|
5
|
-
assertTruthy,
|
|
6
|
-
assertString,
|
|
7
|
-
assertArray,
|
|
8
|
-
assertNullOrString,
|
|
9
|
-
assertRecord,
|
|
10
|
-
} from "../parameterAssertUtils";
|
|
11
|
-
import ApiClient from "../ApiClient";
|
|
12
|
-
import Response from "../Response";
|
|
13
|
-
import { extractArray, extractString } from "../extractUtils";
|
|
14
|
-
import { ConsentGrantRequest } from "../types";
|
|
15
|
-
|
|
16
|
-
export default class OrganizationService {
|
|
17
|
-
_apiClient: ApiClient;
|
|
18
|
-
|
|
19
|
-
constructor({ apiClient }: { apiClient: ApiClient }) {
|
|
20
|
-
// apiClient is added since it will be used eventually or rather soon.
|
|
21
|
-
// this is to avoid the api to be broken again
|
|
22
|
-
this._apiClient = assertInstanceOf(apiClient, ApiClient);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Creates an organization.
|
|
27
|
-
*/
|
|
28
|
-
createOrganization({
|
|
29
|
-
organizationName,
|
|
30
|
-
subdomain,
|
|
31
|
-
owner,
|
|
32
|
-
}: {
|
|
33
|
-
organizationName: string;
|
|
34
|
-
subdomain: string;
|
|
35
|
-
owner:
|
|
36
|
-
| {
|
|
37
|
-
email: string;
|
|
38
|
-
displayName: string;
|
|
39
|
-
verificationCode: string;
|
|
40
|
-
consents?: ReadonlyArray<ConsentGrantRequest>;
|
|
41
|
-
}
|
|
42
|
-
| {
|
|
43
|
-
idToken: string;
|
|
44
|
-
displayName: string;
|
|
45
|
-
consents?: ReadonlyArray<ConsentGrantRequest>;
|
|
46
|
-
};
|
|
47
|
-
}): Promise<string> {
|
|
48
|
-
const { displayName, consents } = owner || {};
|
|
49
|
-
const email =
|
|
50
|
-
"email" in owner
|
|
51
|
-
? {
|
|
52
|
-
value: owner.email,
|
|
53
|
-
verificationCode: assertString(owner.verificationCode, "owner.verificationCode"),
|
|
54
|
-
}
|
|
55
|
-
: null;
|
|
56
|
-
const idToken = "idToken" in owner ? owner.idToken : null;
|
|
57
|
-
assertString(subdomain, "subdomain");
|
|
58
|
-
assertString(organizationName, "organizationName");
|
|
59
|
-
assertString(displayName, "owner.displayName");
|
|
60
|
-
assert.ok(email || idToken, "owner.email or owner.idToken is required");
|
|
61
|
-
|
|
62
|
-
if (consents) {
|
|
63
|
-
assertArray(consents, "consents");
|
|
64
|
-
for (const { consentRevisionId, action } of consents) {
|
|
65
|
-
assertString(consentRevisionId, "consentRevisionId");
|
|
66
|
-
assertNullOrString(action, "action");
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return this._apiClient
|
|
71
|
-
.request(`/organizations`, {
|
|
72
|
-
method: "POST",
|
|
73
|
-
data: {
|
|
74
|
-
organizationName,
|
|
75
|
-
type: "private",
|
|
76
|
-
subdomain,
|
|
77
|
-
owner: {
|
|
78
|
-
...(email && { email }),
|
|
79
|
-
...(idToken && { idToken }),
|
|
80
|
-
...(consents && { consents }),
|
|
81
|
-
displayName,
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
})
|
|
85
|
-
.then(({ data }) => {
|
|
86
|
-
return extractString(data, "organizationId");
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Retrieves the organization based on the subdomain.
|
|
92
|
-
*/
|
|
93
|
-
getOrganizationBySubdomain(subdomain: string): Promise<Organization | null> {
|
|
94
|
-
assertString(subdomain, "subdomain");
|
|
95
|
-
|
|
96
|
-
return this._apiClient
|
|
97
|
-
.request(
|
|
98
|
-
`/organization-subdomains/${encodeURIComponent(
|
|
99
|
-
subdomain
|
|
100
|
-
)}/?fields=permissions,account,onboardingSurvey`,
|
|
101
|
-
{
|
|
102
|
-
method: "GET",
|
|
103
|
-
}
|
|
104
|
-
)
|
|
105
|
-
|
|
106
|
-
.then(({ data }) => {
|
|
107
|
-
return Organization.fromJson(data);
|
|
108
|
-
})
|
|
109
|
-
.catch((res) => {
|
|
110
|
-
if (res instanceof Response) {
|
|
111
|
-
if (res.status === 404) {
|
|
112
|
-
return null;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
throw new Error(res.statusText);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
throw res;
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Retrieves the organization based on the organizationId.
|
|
124
|
-
*
|
|
125
|
-
* Note: This endpoint should only be used to retrieve an organization when the device is linked
|
|
126
|
-
* to a user in that organization. Use getOrganizationBySubdomain instead if you just want the information
|
|
127
|
-
* about an organization that is mapped to a given subdomain.
|
|
128
|
-
*/
|
|
129
|
-
getOrganizationByOrganizationId(organizationId: string): Promise<Organization | null> {
|
|
130
|
-
assertString(organizationId, "organizationId");
|
|
131
|
-
|
|
132
|
-
return this._apiClient
|
|
133
|
-
.request(`/organizations/${encodeURIComponent(organizationId)}?fields=permissions,account`, {
|
|
134
|
-
method: "GET",
|
|
135
|
-
})
|
|
136
|
-
.then(({ data }) => {
|
|
137
|
-
return Organization.fromJson(data);
|
|
138
|
-
})
|
|
139
|
-
.catch((res) => {
|
|
140
|
-
if (res instanceof Response) {
|
|
141
|
-
if (res.status === 404) {
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
throw new Error(res.statusText);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
throw res;
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Retrieves the organizations that contain a user
|
|
154
|
-
* matching provided the email+code or phoneNumber+code
|
|
155
|
-
* combination.
|
|
156
|
-
*/
|
|
157
|
-
getOrganizationsByContactPoint(
|
|
158
|
-
options:
|
|
159
|
-
| {
|
|
160
|
-
email: string;
|
|
161
|
-
code: string;
|
|
162
|
-
}
|
|
163
|
-
| {
|
|
164
|
-
phoneNumber: string;
|
|
165
|
-
code: string;
|
|
166
|
-
}
|
|
167
|
-
): Promise<ReadonlyArray<Organization>> {
|
|
168
|
-
const { code } = options;
|
|
169
|
-
const email = "email" in options ? options.email : null;
|
|
170
|
-
const phoneNumber = "phoneNumber" in options ? options.phoneNumber : null;
|
|
171
|
-
assert.ok((email || phoneNumber) && !(email && phoneNumber), "either email or phoneNumber is required");
|
|
172
|
-
assertString(code, "code");
|
|
173
|
-
|
|
174
|
-
const contactPoint = email ? { type: "email", value: email } : { type: "phoneNumber", value: phoneNumber };
|
|
175
|
-
return this._apiClient
|
|
176
|
-
.request("/organization-queries", {
|
|
177
|
-
method: "POST",
|
|
178
|
-
data: {
|
|
179
|
-
contactPoint,
|
|
180
|
-
code,
|
|
181
|
-
},
|
|
182
|
-
})
|
|
183
|
-
.then(({ data }) => {
|
|
184
|
-
return extractArray(data, "organizations", (organization) => Organization.fromJson(organization));
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Retrieves the organizations that contain a user
|
|
190
|
-
* matching provided the idToken
|
|
191
|
-
*/
|
|
192
|
-
getOrganizationsByIdToken({ idToken }: { idToken: string }): Promise<ReadonlyArray<Organization>> {
|
|
193
|
-
assertString(idToken, "idToken");
|
|
194
|
-
|
|
195
|
-
return this._apiClient
|
|
196
|
-
.request("/organization-queries", {
|
|
197
|
-
method: "POST",
|
|
198
|
-
data: {
|
|
199
|
-
idToken,
|
|
200
|
-
},
|
|
201
|
-
})
|
|
202
|
-
.then(({ data }) => {
|
|
203
|
-
return extractArray(data, "organizations", (organization) => {
|
|
204
|
-
return Organization.fromJson({
|
|
205
|
-
permissions: {},
|
|
206
|
-
limits: {},
|
|
207
|
-
...assertRecord(organization, "organization"),
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Retrieves the organizations containing a user
|
|
215
|
-
* with either the email or phoneNumber matching the logged in user.
|
|
216
|
-
*
|
|
217
|
-
* This is useful for showing the possible organization that the current
|
|
218
|
-
* user could log in to.
|
|
219
|
-
*/
|
|
220
|
-
getOrganizationsByLoggedInUser(): Promise<ReadonlyArray<Organization>> {
|
|
221
|
-
return this._apiClient
|
|
222
|
-
.request("/user/organizations", {
|
|
223
|
-
method: "GET",
|
|
224
|
-
})
|
|
225
|
-
.then(({ data }) => {
|
|
226
|
-
return extractArray(data, "organizations", (o) => {
|
|
227
|
-
return Organization.fromJson({
|
|
228
|
-
permissions: {},
|
|
229
|
-
limits: {},
|
|
230
|
-
...assertRecord(o, "organization"),
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Checks if a subdomain is available and verifies its format.
|
|
238
|
-
*/
|
|
239
|
-
getSubdomainAvailability(subdomain: string): Promise<{ status: string }> {
|
|
240
|
-
assertString(subdomain, "subdomain");
|
|
241
|
-
|
|
242
|
-
return this._apiClient
|
|
243
|
-
.request(`/organization-subdomains/${encodeURIComponent(subdomain)}/availability`, {
|
|
244
|
-
method: "GET",
|
|
245
|
-
})
|
|
246
|
-
.then(({ data }) => {
|
|
247
|
-
assertInstanceOf(data, Object, "data");
|
|
248
|
-
|
|
249
|
-
return {
|
|
250
|
-
status: extractString(data, "status"),
|
|
251
|
-
};
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* Updates preferences of the organization.
|
|
256
|
-
*/
|
|
257
|
-
updatePreferences({
|
|
258
|
-
organizationId,
|
|
259
|
-
preferences,
|
|
260
|
-
}: {
|
|
261
|
-
organizationId: string;
|
|
262
|
-
preferences: OrganizationPreferences;
|
|
263
|
-
}): Promise<undefined> {
|
|
264
|
-
assertTruthy(organizationId, "organizationId");
|
|
265
|
-
assertTruthy(preferences, "preferences");
|
|
266
|
-
return this._apiClient
|
|
267
|
-
.request(`/organizations/${encodeURIComponent(organizationId)}/preferences`, {
|
|
268
|
-
method: "PATCH",
|
|
269
|
-
data: preferences,
|
|
270
|
-
})
|
|
271
|
-
.then(() => undefined);
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Delete organization
|
|
275
|
-
*/
|
|
276
|
-
deleteOrganization({ organizationId }: { organizationId: string }): Promise<undefined> {
|
|
277
|
-
assertTruthy(organizationId, "organizationId");
|
|
278
|
-
return this._apiClient
|
|
279
|
-
.request(`/organizations/${encodeURIComponent(organizationId)}`, {
|
|
280
|
-
method: "DELETE",
|
|
281
|
-
})
|
|
282
|
-
.then(() => undefined);
|
|
283
|
-
}
|
|
284
|
-
}
|