@whereby.com/browser-sdk 2.0.0-alpha23 → 2.0.0-alpha25
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 +14 -0
- package/dist/LocalMedia.d.ts +53 -0
- package/dist/LocalMedia.js +154 -0
- package/dist/RoomConnection.d.ts +174 -0
- package/dist/RoomConnection.js +608 -0
- package/dist/RoomParticipant.d.ts +50 -0
- package/dist/RoomParticipant.js +48 -0
- package/dist/api/ApiClient.d.ts +26 -0
- package/dist/api/ApiClient.js +63 -0
- package/dist/api/Credentials.d.ts +17 -0
- package/dist/api/Credentials.js +16 -0
- package/dist/api/HttpClient.d.ts +16 -0
- package/dist/api/HttpClient.js +53 -0
- package/dist/api/MultipartHttpClient.d.ts +10 -0
- package/dist/api/MultipartHttpClient.js +25 -0
- package/dist/api/OrganizationApiClient.d.ts +16 -0
- package/dist/api/OrganizationApiClient.js +30 -0
- package/dist/api/Response.d.ts +29 -0
- package/dist/api/Response.js +9 -0
- package/dist/api/credentialsService/index.d.ts +27 -0
- package/dist/api/credentialsService/index.js +90 -0
- package/dist/api/deviceService/index.d.ts +9 -0
- package/dist/api/deviceService/index.js +25 -0
- package/dist/api/extractUtils.d.ts +16 -0
- package/dist/api/extractUtils.js +51 -0
- package/dist/api/index.d.ts +7 -0
- package/dist/api/index.js +7 -0
- package/dist/api/localStorageWrapper/index.d.ts +2 -0
- package/dist/api/localStorageWrapper/index.js +15 -0
- package/dist/api/models/Account.d.ts +20 -0
- package/dist/api/models/Account.js +24 -0
- package/dist/api/models/Meeting.d.ts +12 -0
- package/dist/api/models/Meeting.js +29 -0
- package/dist/api/models/Organization.d.ts +102 -0
- package/dist/api/models/Organization.js +81 -0
- package/dist/api/models/Room.d.ts +4 -0
- package/dist/api/models/Room.js +38 -0
- package/dist/api/models/account/EmbeddedFreeTierStatus.d.ts +13 -0
- package/dist/api/models/account/EmbeddedFreeTierStatus.js +17 -0
- package/dist/api/modules/AbstractStore.d.ts +5 -0
- package/dist/api/modules/AbstractStore.js +1 -0
- package/dist/api/modules/ChromeStorageStore.d.ts +10 -0
- package/dist/api/modules/ChromeStorageStore.js +21 -0
- package/dist/api/modules/LocalStorageStore.d.ts +9 -0
- package/dist/api/modules/LocalStorageStore.js +35 -0
- package/dist/api/modules/tests/__mocks__/storage.d.ts +10 -0
- package/dist/api/modules/tests/__mocks__/storage.js +19 -0
- package/dist/api/organizationService/index.d.ts +46 -0
- package/dist/api/organizationService/index.js +159 -0
- package/dist/api/organizationServiceCache/index.d.ts +13 -0
- package/dist/api/organizationServiceCache/index.js +20 -0
- package/dist/api/parameterAssertUtils.d.ts +13 -0
- package/dist/api/parameterAssertUtils.js +64 -0
- package/dist/api/roomService/index.d.ts +54 -0
- package/dist/api/roomService/index.js +160 -0
- package/dist/api/test/helpers.d.ts +5 -0
- package/dist/api/test/helpers.js +32 -0
- package/dist/api/types.d.ts +5 -0
- package/dist/api/types.js +1 -0
- package/dist/embed/index.d.ts +31 -0
- package/dist/embed/index.js +123 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/react/VideoView.d.ts +14 -0
- package/dist/react/VideoView.js +37 -0
- package/dist/react/index.d.ts +3 -0
- package/dist/react/index.js +3 -0
- package/dist/react/useLocalMedia.d.ts +28 -0
- package/dist/react/useLocalMedia.js +109 -0
- package/dist/react/useRoomConnection.d.ts +47 -0
- package/dist/react/useRoomConnection.js +283 -0
- package/dist/utils/debounce.d.ts +9 -0
- package/dist/utils/debounce.js +20 -0
- package/dist/utils/fakeAudioStream.d.ts +1 -0
- package/dist/utils/fakeAudioStream.js +18 -0
- package/dist/utils/fakeWebcamFrame.d.ts +1 -0
- package/dist/utils/fakeWebcamFrame.js +49 -0
- package/dist/v2-alpha25.js +1993 -0
- package/package.json +23 -11
- package/dist/lib.cjs +0 -6200
- package/dist/lib.esm.js +0 -6182
- package/dist/types.d.ts +0 -382
- package/dist/v2-alpha23.js +0 -43
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { assertBoolean } from "../parameterAssertUtils";
|
|
2
|
+
import EmbeddedFreeTierStatus from "./account/EmbeddedFreeTierStatus";
|
|
3
|
+
export default class Account {
|
|
4
|
+
constructor({ basePlanId, embeddedFreeTierStatus, isDeactivated, isOnTrial, onTrialUntil, trialStatus, }) {
|
|
5
|
+
this.basePlanId = basePlanId;
|
|
6
|
+
this.isDeactivated = isDeactivated;
|
|
7
|
+
this.isOnTrial = isOnTrial;
|
|
8
|
+
this.onTrialUntil = onTrialUntil || null;
|
|
9
|
+
this.trialStatus = trialStatus || null;
|
|
10
|
+
this.embeddedFreeTierStatus = embeddedFreeTierStatus || null;
|
|
11
|
+
}
|
|
12
|
+
static fromJson(data) {
|
|
13
|
+
return new Account({
|
|
14
|
+
basePlanId: typeof data.basePlanId === "string" ? data.basePlanId : null,
|
|
15
|
+
isDeactivated: assertBoolean(data.isDeactivated, "isDeactivated"),
|
|
16
|
+
isOnTrial: assertBoolean(data.isOnTrial, "isOnTrial"),
|
|
17
|
+
onTrialUntil: typeof data.onTrialUntil === "string" ? new Date(data.onTrialUntil) : null,
|
|
18
|
+
trialStatus: typeof data.trialStatus === "string" ? data.trialStatus : null,
|
|
19
|
+
embeddedFreeTierStatus: data.embeddedFreeTierStatus
|
|
20
|
+
? EmbeddedFreeTierStatus.fromJson(data.embeddedFreeTierStatus)
|
|
21
|
+
: null,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Json } from "../Response";
|
|
2
|
+
export default class Meeting {
|
|
3
|
+
meetingId: string;
|
|
4
|
+
roomName: string;
|
|
5
|
+
roomUrl: string;
|
|
6
|
+
startDate: Date;
|
|
7
|
+
endDate: Date;
|
|
8
|
+
hostRoomUrl: string | null;
|
|
9
|
+
viewerRoomUrl: string | null;
|
|
10
|
+
constructor({ meetingId, roomName, roomUrl, startDate, endDate, hostRoomUrl, viewerRoomUrl }: Meeting);
|
|
11
|
+
static fromJson(data: Json): Meeting;
|
|
12
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { extractDate, extractNullOrString, extractString } from "../extractUtils";
|
|
2
|
+
import { assertString, assertInstanceOf } from "../parameterAssertUtils";
|
|
3
|
+
export default class Meeting {
|
|
4
|
+
constructor({ meetingId, roomName, roomUrl, startDate, endDate, hostRoomUrl, viewerRoomUrl }) {
|
|
5
|
+
assertString(meetingId, "meetingId");
|
|
6
|
+
assertString(roomName, "roomName");
|
|
7
|
+
assertString(roomUrl, "roomUrl");
|
|
8
|
+
assertInstanceOf(startDate, Date, "startDate");
|
|
9
|
+
assertInstanceOf(endDate, Date, "endDate");
|
|
10
|
+
this.meetingId = meetingId;
|
|
11
|
+
this.roomName = roomName;
|
|
12
|
+
this.roomUrl = roomUrl;
|
|
13
|
+
this.startDate = startDate;
|
|
14
|
+
this.endDate = endDate;
|
|
15
|
+
this.hostRoomUrl = hostRoomUrl;
|
|
16
|
+
this.viewerRoomUrl = viewerRoomUrl;
|
|
17
|
+
}
|
|
18
|
+
static fromJson(data) {
|
|
19
|
+
return new Meeting({
|
|
20
|
+
meetingId: extractString(data, "meetingId"),
|
|
21
|
+
roomName: extractString(data, "roomName"),
|
|
22
|
+
roomUrl: extractString(data, "roomUrl"),
|
|
23
|
+
startDate: extractDate(data, "startDate"),
|
|
24
|
+
endDate: extractDate(data, "endDate"),
|
|
25
|
+
hostRoomUrl: extractNullOrString(data, "hostRoomUrl"),
|
|
26
|
+
viewerRoomUrl: extractNullOrString(data, "viewerRoomUrl"),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { Json } from "../Response";
|
|
2
|
+
import Account from "./Account";
|
|
3
|
+
interface OrganizationPermissionAction {
|
|
4
|
+
isAllowed: boolean;
|
|
5
|
+
isSupported: boolean;
|
|
6
|
+
}
|
|
7
|
+
interface FullOrganizationPermissions {
|
|
8
|
+
images: {
|
|
9
|
+
logoImageUrl: {
|
|
10
|
+
set: OrganizationPermissionAction;
|
|
11
|
+
reset: OrganizationPermissionAction;
|
|
12
|
+
};
|
|
13
|
+
roomBackgroundImageUrl: {
|
|
14
|
+
set: OrganizationPermissionAction;
|
|
15
|
+
reset: OrganizationPermissionAction;
|
|
16
|
+
};
|
|
17
|
+
roomKnockPageBackgroundImageUrl: {
|
|
18
|
+
set: OrganizationPermissionAction;
|
|
19
|
+
reset: OrganizationPermissionAction;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
invitations: {
|
|
23
|
+
add: OrganizationPermissionAction;
|
|
24
|
+
delete: OrganizationPermissionAction;
|
|
25
|
+
list: OrganizationPermissionAction;
|
|
26
|
+
};
|
|
27
|
+
roles: {
|
|
28
|
+
set: OrganizationPermissionAction;
|
|
29
|
+
remove: OrganizationPermissionAction;
|
|
30
|
+
removeSelf: OrganizationPermissionAction;
|
|
31
|
+
list: OrganizationPermissionAction;
|
|
32
|
+
};
|
|
33
|
+
users: {
|
|
34
|
+
signUpWithoutInvitation: OrganizationPermissionAction;
|
|
35
|
+
};
|
|
36
|
+
rooms: {
|
|
37
|
+
customize: OrganizationPermissionAction;
|
|
38
|
+
customizeSelf: OrganizationPermissionAction;
|
|
39
|
+
list: OrganizationPermissionAction;
|
|
40
|
+
lock: OrganizationPermissionAction;
|
|
41
|
+
unclaim: OrganizationPermissionAction;
|
|
42
|
+
unclaimSelf: OrganizationPermissionAction;
|
|
43
|
+
};
|
|
44
|
+
subscriptions: {
|
|
45
|
+
add: OrganizationPermissionAction;
|
|
46
|
+
list: OrganizationPermissionAction;
|
|
47
|
+
payLatestInvoice: OrganizationPermissionAction;
|
|
48
|
+
updatePlan: OrganizationPermissionAction;
|
|
49
|
+
};
|
|
50
|
+
browserExtension: {
|
|
51
|
+
install: OrganizationPermissionAction;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
type OrganizationPermissions = Partial<FullOrganizationPermissions>;
|
|
55
|
+
interface OrganizationLimits {
|
|
56
|
+
maxNumberOfInvitationsAndUsers: number | null;
|
|
57
|
+
maxNumberOfClaimedRooms: number | null;
|
|
58
|
+
maxRoomLimitPerOrganization: number | null;
|
|
59
|
+
trialMinutesLimit: number | null;
|
|
60
|
+
includedUnits: number | null;
|
|
61
|
+
}
|
|
62
|
+
interface OrganizationOnboardingSurvey {
|
|
63
|
+
name: string;
|
|
64
|
+
value: unknown;
|
|
65
|
+
}
|
|
66
|
+
export type OrganizationPreferences = Record<string, boolean | string | null | number>;
|
|
67
|
+
export declare function hasValue(value: unknown): boolean;
|
|
68
|
+
export default class Organization {
|
|
69
|
+
static GLOBAL_ORGANIZATION_ID: string;
|
|
70
|
+
organizationId: string;
|
|
71
|
+
organizationName: string;
|
|
72
|
+
subdomain: string;
|
|
73
|
+
permissions: OrganizationPermissions;
|
|
74
|
+
limits: OrganizationLimits;
|
|
75
|
+
account: Account | null;
|
|
76
|
+
logoImageUrl: string | null;
|
|
77
|
+
roomBackgroundImageUrl: string | null;
|
|
78
|
+
roomBackgroundThumbnailUrl: string | null;
|
|
79
|
+
roomKnockPageBackgroundImageUrl: string | null;
|
|
80
|
+
roomKnockPageBackgroundThumbnailUrl: string | null;
|
|
81
|
+
preferences: OrganizationPreferences | null;
|
|
82
|
+
onboardingSurvey: OrganizationOnboardingSurvey | null;
|
|
83
|
+
type: string | null;
|
|
84
|
+
constructor(properties: {
|
|
85
|
+
account: Account | null;
|
|
86
|
+
organizationId: string;
|
|
87
|
+
organizationName: string;
|
|
88
|
+
subdomain: string;
|
|
89
|
+
permissions: OrganizationPermissions;
|
|
90
|
+
limits: OrganizationLimits;
|
|
91
|
+
logoImageUrl: string | null;
|
|
92
|
+
roomBackgroundImageUrl: string | null;
|
|
93
|
+
roomBackgroundThumbnailUrl: string | null;
|
|
94
|
+
roomKnockPageBackgroundImageUrl: string | null;
|
|
95
|
+
roomKnockPageBackgroundThumbnailUrl: string | null;
|
|
96
|
+
preferences: OrganizationPreferences | null;
|
|
97
|
+
onboardingSurvey: OrganizationOnboardingSurvey | null;
|
|
98
|
+
type: string | null;
|
|
99
|
+
});
|
|
100
|
+
static fromJson(data: Json): Organization;
|
|
101
|
+
}
|
|
102
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { assertInstanceOf, assertString } from "../parameterAssertUtils";
|
|
2
|
+
import Account from "./Account";
|
|
3
|
+
export function hasValue(value) {
|
|
4
|
+
return value !== null && value !== undefined;
|
|
5
|
+
}
|
|
6
|
+
function createOrganizationLimits(limits = {}) {
|
|
7
|
+
return {
|
|
8
|
+
maxNumberOfInvitationsAndUsers: hasValue(limits === null || limits === void 0 ? void 0 : limits.maxNumberOfInvitationsAndUsers)
|
|
9
|
+
? Number(limits === null || limits === void 0 ? void 0 : limits.maxNumberOfInvitationsAndUsers)
|
|
10
|
+
: null,
|
|
11
|
+
maxNumberOfClaimedRooms: hasValue(limits === null || limits === void 0 ? void 0 : limits.maxNumberOfClaimedRooms)
|
|
12
|
+
? Number(limits === null || limits === void 0 ? void 0 : limits.maxNumberOfClaimedRooms)
|
|
13
|
+
: null,
|
|
14
|
+
maxRoomLimitPerOrganization: hasValue(limits === null || limits === void 0 ? void 0 : limits.maxRoomLimitPerOrganization)
|
|
15
|
+
? Number(limits === null || limits === void 0 ? void 0 : limits.maxRoomLimitPerOrganization)
|
|
16
|
+
: null,
|
|
17
|
+
trialMinutesLimit: hasValue(limits === null || limits === void 0 ? void 0 : limits.trialMinutesLimit) ? Number(limits === null || limits === void 0 ? void 0 : limits.trialMinutesLimit) : null,
|
|
18
|
+
includedUnits: hasValue(limits === null || limits === void 0 ? void 0 : limits.includedUnits) ? Number(limits === null || limits === void 0 ? void 0 : limits.includedUnits) : null,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export default class Organization {
|
|
22
|
+
constructor(properties) {
|
|
23
|
+
this.logoImageUrl = null;
|
|
24
|
+
this.roomBackgroundImageUrl = null;
|
|
25
|
+
this.roomBackgroundThumbnailUrl = null;
|
|
26
|
+
this.roomKnockPageBackgroundImageUrl = null;
|
|
27
|
+
this.roomKnockPageBackgroundThumbnailUrl = null;
|
|
28
|
+
this.preferences = null;
|
|
29
|
+
this.onboardingSurvey = null;
|
|
30
|
+
this.type = null;
|
|
31
|
+
assertInstanceOf(properties, Object, "properties");
|
|
32
|
+
assertString(properties.organizationId, "organizationId");
|
|
33
|
+
assertString(properties.organizationName, "organizationName");
|
|
34
|
+
assertString(properties.subdomain, "subdomain");
|
|
35
|
+
assertInstanceOf(properties.permissions, Object, "permissions");
|
|
36
|
+
assertInstanceOf(properties.limits, Object, "limits");
|
|
37
|
+
this.organizationId = properties.organizationId;
|
|
38
|
+
this.organizationName = properties.organizationName;
|
|
39
|
+
this.subdomain = properties.subdomain;
|
|
40
|
+
this.permissions = properties.permissions;
|
|
41
|
+
this.limits = properties.limits;
|
|
42
|
+
this.account = properties.account ? new Account(properties.account) : null;
|
|
43
|
+
this.logoImageUrl = properties.logoImageUrl;
|
|
44
|
+
this.roomBackgroundImageUrl = properties.roomBackgroundImageUrl;
|
|
45
|
+
this.roomBackgroundThumbnailUrl = properties.roomBackgroundThumbnailUrl;
|
|
46
|
+
this.roomKnockPageBackgroundImageUrl = properties.roomKnockPageBackgroundImageUrl;
|
|
47
|
+
this.roomKnockPageBackgroundThumbnailUrl = properties.roomKnockPageBackgroundThumbnailUrl;
|
|
48
|
+
this.preferences = properties.preferences;
|
|
49
|
+
this.onboardingSurvey = properties.onboardingSurvey;
|
|
50
|
+
this.type = properties.type;
|
|
51
|
+
}
|
|
52
|
+
static fromJson(data) {
|
|
53
|
+
const parsedData = assertInstanceOf(data, Object, "data");
|
|
54
|
+
const preferences = ((parsedData === null || parsedData === void 0 ? void 0 : parsedData.preferences) || {});
|
|
55
|
+
const onboardingSurvey = ((parsedData === null || parsedData === void 0 ? void 0 : parsedData.onboardingSurvey) || null);
|
|
56
|
+
const permissions = assertInstanceOf(parsedData.permissions, Object, "permissions");
|
|
57
|
+
return new Organization({
|
|
58
|
+
organizationId: assertString(parsedData.organizationId, "organizationId"),
|
|
59
|
+
organizationName: assertString(parsedData.organizationName, "organizationName"),
|
|
60
|
+
subdomain: assertString(parsedData.subdomain, "subdomain"),
|
|
61
|
+
permissions,
|
|
62
|
+
limits: createOrganizationLimits(assertInstanceOf(parsedData.limits, Object, "limits")),
|
|
63
|
+
account: parsedData.account ? Account.fromJson(parsedData.account) : null,
|
|
64
|
+
logoImageUrl: typeof parsedData.logoImageUrl === "string" ? parsedData.logoImageUrl : null,
|
|
65
|
+
roomBackgroundImageUrl: typeof parsedData.roomBackgroundImageUrl === "string" ? parsedData.roomBackgroundImageUrl : null,
|
|
66
|
+
roomBackgroundThumbnailUrl: typeof parsedData.roomBackgroundThumbnailUrl === "string"
|
|
67
|
+
? parsedData.roomBackgroundThumbnailUrl
|
|
68
|
+
: null,
|
|
69
|
+
roomKnockPageBackgroundImageUrl: typeof parsedData.roomKnockPageBackgroundImageUrl === "string"
|
|
70
|
+
? parsedData.roomKnockPageBackgroundImageUrl
|
|
71
|
+
: null,
|
|
72
|
+
roomKnockPageBackgroundThumbnailUrl: typeof parsedData.roomKnockPageBackgroundThumbnailUrl === "string"
|
|
73
|
+
? parsedData.roomKnockPageBackgroundThumbnailUrl
|
|
74
|
+
: null,
|
|
75
|
+
preferences,
|
|
76
|
+
onboardingSurvey,
|
|
77
|
+
type: typeof parsedData.type === "string" ? parsedData.type : null,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
Organization.GLOBAL_ORGANIZATION_ID = "1";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import assert from "assert";
|
|
2
|
+
export default class Room {
|
|
3
|
+
constructor(properties = {}) {
|
|
4
|
+
assert.ok(properties instanceof Object, "properties<object> must be empty or an object");
|
|
5
|
+
this.isClaimed = false;
|
|
6
|
+
this.isBanned = false;
|
|
7
|
+
this.isLocked = false;
|
|
8
|
+
this.knockPage = {
|
|
9
|
+
backgroundImageUrl: null,
|
|
10
|
+
backgroundThumbnailUrl: null,
|
|
11
|
+
};
|
|
12
|
+
this.logoUrl = null;
|
|
13
|
+
this.backgroundImageUrl = null;
|
|
14
|
+
this.backgroundThumbnailUrl = null;
|
|
15
|
+
this.type = null;
|
|
16
|
+
this.legacyRoomType = null;
|
|
17
|
+
this.mode = null;
|
|
18
|
+
this.product = null;
|
|
19
|
+
this.roomName = null;
|
|
20
|
+
this.theme = null;
|
|
21
|
+
this.preferences = {};
|
|
22
|
+
this.protectedPreferences = {};
|
|
23
|
+
this.publicProfile = null;
|
|
24
|
+
const validProperties = {};
|
|
25
|
+
Object.getOwnPropertyNames(properties).forEach((prop) => {
|
|
26
|
+
if (Object.getOwnPropertyNames(this).indexOf(prop) !== -1) {
|
|
27
|
+
validProperties[prop] = properties[prop];
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
if (properties.ownerId !== undefined) {
|
|
31
|
+
this.ownerId = properties.ownerId;
|
|
32
|
+
}
|
|
33
|
+
if (properties.meeting !== undefined) {
|
|
34
|
+
this.meeting = properties.meeting;
|
|
35
|
+
}
|
|
36
|
+
Object.assign(this, validProperties);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default class EmbeddedFreeTierStatus {
|
|
2
|
+
isExhausted: boolean;
|
|
3
|
+
renewsAt: Date;
|
|
4
|
+
totalMinutesLimit: number;
|
|
5
|
+
totalMinutesUsed: number;
|
|
6
|
+
constructor({ isExhausted, renewsAt, totalMinutesLimit, totalMinutesUsed, }: {
|
|
7
|
+
isExhausted: boolean;
|
|
8
|
+
renewsAt: Date;
|
|
9
|
+
totalMinutesLimit: number;
|
|
10
|
+
totalMinutesUsed: number;
|
|
11
|
+
});
|
|
12
|
+
static fromJson(data: Record<string, unknown>): EmbeddedFreeTierStatus;
|
|
13
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { assertBoolean, assertNumber, assertString } from "../../parameterAssertUtils";
|
|
2
|
+
export default class EmbeddedFreeTierStatus {
|
|
3
|
+
constructor({ isExhausted, renewsAt, totalMinutesLimit, totalMinutesUsed, }) {
|
|
4
|
+
this.isExhausted = isExhausted;
|
|
5
|
+
this.renewsAt = renewsAt;
|
|
6
|
+
this.totalMinutesLimit = totalMinutesLimit;
|
|
7
|
+
this.totalMinutesUsed = totalMinutesUsed;
|
|
8
|
+
}
|
|
9
|
+
static fromJson(data) {
|
|
10
|
+
return new EmbeddedFreeTierStatus({
|
|
11
|
+
isExhausted: assertBoolean(data.isExhausted, "isExhausted"),
|
|
12
|
+
renewsAt: new Date(assertString(data.renewsAt, "renewsAt")),
|
|
13
|
+
totalMinutesLimit: assertNumber(data.totalMinutesLimit, "totalMinutesLimit"),
|
|
14
|
+
totalMinutesUsed: assertNumber(data.totalMinutesUsed, "totalMinutesUsed"),
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="chrome" />
|
|
2
|
+
import { Json } from "../Response";
|
|
3
|
+
import AbstractStore from "./AbstractStore";
|
|
4
|
+
export default class ChromeStorageStore implements AbstractStore {
|
|
5
|
+
_key: string;
|
|
6
|
+
_chromeStorage: chrome.storage.StorageArea;
|
|
7
|
+
constructor(key: string, chromeStorage: chrome.storage.StorageArea);
|
|
8
|
+
loadOrDefault(defaultValue: Json): Promise<Json>;
|
|
9
|
+
save(value: Json): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export default class ChromeStorageStore {
|
|
2
|
+
constructor(key, chromeStorage) {
|
|
3
|
+
this._key = key;
|
|
4
|
+
this._chromeStorage = chromeStorage;
|
|
5
|
+
}
|
|
6
|
+
loadOrDefault(defaultValue) {
|
|
7
|
+
return new Promise((resolve) => {
|
|
8
|
+
this._chromeStorage.get(this._key, (result) => {
|
|
9
|
+
const unknownResult = result;
|
|
10
|
+
resolve(unknownResult[this._key] || defaultValue);
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
save(value) {
|
|
15
|
+
return new Promise((resolve) => {
|
|
16
|
+
this._chromeStorage.set({ [this._key]: value }, () => {
|
|
17
|
+
resolve();
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Json } from "../Response";
|
|
2
|
+
import AbstractStore from "./AbstractStore";
|
|
3
|
+
export default class LocalStorageStore implements AbstractStore {
|
|
4
|
+
_key: string;
|
|
5
|
+
_localStorage: Storage;
|
|
6
|
+
constructor(key: string, localStorage: Storage);
|
|
7
|
+
loadOrDefault(defaultValue: Json): Promise<Json>;
|
|
8
|
+
save(value: Json): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { assertString, assertTruthy } from "../parameterAssertUtils";
|
|
2
|
+
export default class LocalStorageStore {
|
|
3
|
+
constructor(key, localStorage) {
|
|
4
|
+
assertTruthy(localStorage, "localStorage");
|
|
5
|
+
this._key = assertString(key, "key");
|
|
6
|
+
this._localStorage = localStorage;
|
|
7
|
+
}
|
|
8
|
+
loadOrDefault(defaultValue) {
|
|
9
|
+
try {
|
|
10
|
+
const value = this._localStorage.getItem(this._key);
|
|
11
|
+
if (value) {
|
|
12
|
+
try {
|
|
13
|
+
return Promise.resolve(JSON.parse(value));
|
|
14
|
+
}
|
|
15
|
+
catch (e) {
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return Promise.resolve(defaultValue);
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
console.warn("Error getting access to storage. Are cookies blocked?", e);
|
|
22
|
+
return Promise.resolve(defaultValue);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
save(value) {
|
|
26
|
+
try {
|
|
27
|
+
this._localStorage.setItem(this._key, JSON.stringify(value));
|
|
28
|
+
return Promise.resolve();
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
console.warn("Error getting access to storage. Are cookies blocked?", e);
|
|
32
|
+
return Promise.reject(e);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export default class DummyStore {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.length = 0;
|
|
4
|
+
}
|
|
5
|
+
clear() {
|
|
6
|
+
throw new Error("Method not implemented.");
|
|
7
|
+
}
|
|
8
|
+
getItem(_key) {
|
|
9
|
+
return "{}";
|
|
10
|
+
}
|
|
11
|
+
key() {
|
|
12
|
+
throw new Error("Method not implemented.");
|
|
13
|
+
}
|
|
14
|
+
removeItem() {
|
|
15
|
+
throw new Error("Method not implemented.");
|
|
16
|
+
}
|
|
17
|
+
setItem() {
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import Organization, { OrganizationPreferences } from "../models/Organization";
|
|
2
|
+
import ApiClient from "../ApiClient";
|
|
3
|
+
import { ConsentGrantRequest } from "../types";
|
|
4
|
+
export default class OrganizationService {
|
|
5
|
+
_apiClient: ApiClient;
|
|
6
|
+
constructor({ apiClient }: {
|
|
7
|
+
apiClient: ApiClient;
|
|
8
|
+
});
|
|
9
|
+
createOrganization({ organizationName, subdomain, owner, }: {
|
|
10
|
+
organizationName: string;
|
|
11
|
+
subdomain: string;
|
|
12
|
+
owner: {
|
|
13
|
+
email: string;
|
|
14
|
+
displayName: string;
|
|
15
|
+
verificationCode: string;
|
|
16
|
+
consents?: ReadonlyArray<ConsentGrantRequest>;
|
|
17
|
+
} | {
|
|
18
|
+
idToken: string;
|
|
19
|
+
displayName: string;
|
|
20
|
+
consents?: ReadonlyArray<ConsentGrantRequest>;
|
|
21
|
+
};
|
|
22
|
+
}): Promise<string>;
|
|
23
|
+
getOrganizationBySubdomain(subdomain: string): Promise<Organization | null>;
|
|
24
|
+
getOrganizationByOrganizationId(organizationId: string): Promise<Organization | null>;
|
|
25
|
+
getOrganizationsByContactPoint(options: {
|
|
26
|
+
email: string;
|
|
27
|
+
code: string;
|
|
28
|
+
} | {
|
|
29
|
+
phoneNumber: string;
|
|
30
|
+
code: string;
|
|
31
|
+
}): Promise<ReadonlyArray<Organization>>;
|
|
32
|
+
getOrganizationsByIdToken({ idToken }: {
|
|
33
|
+
idToken: string;
|
|
34
|
+
}): Promise<ReadonlyArray<Organization>>;
|
|
35
|
+
getOrganizationsByLoggedInUser(): Promise<ReadonlyArray<Organization>>;
|
|
36
|
+
getSubdomainAvailability(subdomain: string): Promise<{
|
|
37
|
+
status: string;
|
|
38
|
+
}>;
|
|
39
|
+
updatePreferences({ organizationId, preferences, }: {
|
|
40
|
+
organizationId: string;
|
|
41
|
+
preferences: OrganizationPreferences;
|
|
42
|
+
}): Promise<undefined>;
|
|
43
|
+
deleteOrganization({ organizationId }: {
|
|
44
|
+
organizationId: string;
|
|
45
|
+
}): Promise<undefined>;
|
|
46
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import assert from "assert";
|
|
2
|
+
import Organization from "../models/Organization";
|
|
3
|
+
import { assertInstanceOf, assertTruthy, assertString, assertArray, assertNullOrString, assertRecord, } from "../parameterAssertUtils";
|
|
4
|
+
import ApiClient from "../ApiClient";
|
|
5
|
+
import Response from "../Response";
|
|
6
|
+
import { extractArray, extractString } from "../extractUtils";
|
|
7
|
+
export default class OrganizationService {
|
|
8
|
+
constructor({ apiClient }) {
|
|
9
|
+
this._apiClient = assertInstanceOf(apiClient, ApiClient);
|
|
10
|
+
}
|
|
11
|
+
createOrganization({ organizationName, subdomain, owner, }) {
|
|
12
|
+
const { displayName, consents } = owner || {};
|
|
13
|
+
const email = "email" in owner
|
|
14
|
+
? {
|
|
15
|
+
value: owner.email,
|
|
16
|
+
verificationCode: assertString(owner.verificationCode, "owner.verificationCode"),
|
|
17
|
+
}
|
|
18
|
+
: null;
|
|
19
|
+
const idToken = "idToken" in owner ? owner.idToken : null;
|
|
20
|
+
assertString(subdomain, "subdomain");
|
|
21
|
+
assertString(organizationName, "organizationName");
|
|
22
|
+
assertString(displayName, "owner.displayName");
|
|
23
|
+
assert.ok(email || idToken, "owner.email or owner.idToken is required");
|
|
24
|
+
if (consents) {
|
|
25
|
+
assertArray(consents, "consents");
|
|
26
|
+
for (const { consentRevisionId, action } of consents) {
|
|
27
|
+
assertString(consentRevisionId, "consentRevisionId");
|
|
28
|
+
assertNullOrString(action, "action");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return this._apiClient
|
|
32
|
+
.request(`/organizations`, {
|
|
33
|
+
method: "POST",
|
|
34
|
+
data: {
|
|
35
|
+
organizationName,
|
|
36
|
+
type: "private",
|
|
37
|
+
subdomain,
|
|
38
|
+
owner: Object.assign(Object.assign(Object.assign(Object.assign({}, (email && { email })), (idToken && { idToken })), (consents && { consents })), { displayName }),
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
.then(({ data }) => {
|
|
42
|
+
return extractString(data, "organizationId");
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
getOrganizationBySubdomain(subdomain) {
|
|
46
|
+
assertString(subdomain, "subdomain");
|
|
47
|
+
return this._apiClient
|
|
48
|
+
.request(`/organization-subdomains/${encodeURIComponent(subdomain)}/?fields=permissions,account,onboardingSurvey`, {
|
|
49
|
+
method: "GET",
|
|
50
|
+
})
|
|
51
|
+
.then(({ data }) => {
|
|
52
|
+
return Organization.fromJson(data);
|
|
53
|
+
})
|
|
54
|
+
.catch((res) => {
|
|
55
|
+
if (res instanceof Response) {
|
|
56
|
+
if (res.status === 404) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
throw new Error(res.statusText);
|
|
60
|
+
}
|
|
61
|
+
throw res;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
getOrganizationByOrganizationId(organizationId) {
|
|
65
|
+
assertString(organizationId, "organizationId");
|
|
66
|
+
return this._apiClient
|
|
67
|
+
.request(`/organizations/${encodeURIComponent(organizationId)}?fields=permissions,account`, {
|
|
68
|
+
method: "GET",
|
|
69
|
+
})
|
|
70
|
+
.then(({ data }) => {
|
|
71
|
+
return Organization.fromJson(data);
|
|
72
|
+
})
|
|
73
|
+
.catch((res) => {
|
|
74
|
+
if (res instanceof Response) {
|
|
75
|
+
if (res.status === 404) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
throw new Error(res.statusText);
|
|
79
|
+
}
|
|
80
|
+
throw res;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
getOrganizationsByContactPoint(options) {
|
|
84
|
+
const { code } = options;
|
|
85
|
+
const email = "email" in options ? options.email : null;
|
|
86
|
+
const phoneNumber = "phoneNumber" in options ? options.phoneNumber : null;
|
|
87
|
+
assert.ok((email || phoneNumber) && !(email && phoneNumber), "either email or phoneNumber is required");
|
|
88
|
+
assertString(code, "code");
|
|
89
|
+
const contactPoint = email ? { type: "email", value: email } : { type: "phoneNumber", value: phoneNumber };
|
|
90
|
+
return this._apiClient
|
|
91
|
+
.request("/organization-queries", {
|
|
92
|
+
method: "POST",
|
|
93
|
+
data: {
|
|
94
|
+
contactPoint,
|
|
95
|
+
code,
|
|
96
|
+
},
|
|
97
|
+
})
|
|
98
|
+
.then(({ data }) => {
|
|
99
|
+
return extractArray(data, "organizations", (organization) => Organization.fromJson(organization));
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
getOrganizationsByIdToken({ idToken }) {
|
|
103
|
+
assertString(idToken, "idToken");
|
|
104
|
+
return this._apiClient
|
|
105
|
+
.request("/organization-queries", {
|
|
106
|
+
method: "POST",
|
|
107
|
+
data: {
|
|
108
|
+
idToken,
|
|
109
|
+
},
|
|
110
|
+
})
|
|
111
|
+
.then(({ data }) => {
|
|
112
|
+
return extractArray(data, "organizations", (organization) => {
|
|
113
|
+
return Organization.fromJson(Object.assign({ permissions: {}, limits: {} }, assertRecord(organization, "organization")));
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
getOrganizationsByLoggedInUser() {
|
|
118
|
+
return this._apiClient
|
|
119
|
+
.request("/user/organizations", {
|
|
120
|
+
method: "GET",
|
|
121
|
+
})
|
|
122
|
+
.then(({ data }) => {
|
|
123
|
+
return extractArray(data, "organizations", (o) => {
|
|
124
|
+
return Organization.fromJson(Object.assign({ permissions: {}, limits: {} }, assertRecord(o, "organization")));
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
getSubdomainAvailability(subdomain) {
|
|
129
|
+
assertString(subdomain, "subdomain");
|
|
130
|
+
return this._apiClient
|
|
131
|
+
.request(`/organization-subdomains/${encodeURIComponent(subdomain)}/availability`, {
|
|
132
|
+
method: "GET",
|
|
133
|
+
})
|
|
134
|
+
.then(({ data }) => {
|
|
135
|
+
assertInstanceOf(data, Object, "data");
|
|
136
|
+
return {
|
|
137
|
+
status: extractString(data, "status"),
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
updatePreferences({ organizationId, preferences, }) {
|
|
142
|
+
assertTruthy(organizationId, "organizationId");
|
|
143
|
+
assertTruthy(preferences, "preferences");
|
|
144
|
+
return this._apiClient
|
|
145
|
+
.request(`/organizations/${encodeURIComponent(organizationId)}/preferences`, {
|
|
146
|
+
method: "PATCH",
|
|
147
|
+
data: preferences,
|
|
148
|
+
})
|
|
149
|
+
.then(() => undefined);
|
|
150
|
+
}
|
|
151
|
+
deleteOrganization({ organizationId }) {
|
|
152
|
+
assertTruthy(organizationId, "organizationId");
|
|
153
|
+
return this._apiClient
|
|
154
|
+
.request(`/organizations/${encodeURIComponent(organizationId)}`, {
|
|
155
|
+
method: "DELETE",
|
|
156
|
+
})
|
|
157
|
+
.then(() => undefined);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import OrganizationService from "../organizationService/index";
|
|
2
|
+
import Organization from "../models/Organization";
|
|
3
|
+
export default class OrganizationServiceCache {
|
|
4
|
+
private _organizationService;
|
|
5
|
+
private _subdomain;
|
|
6
|
+
private _organizationPromise;
|
|
7
|
+
constructor({ organizationService, subdomain }: {
|
|
8
|
+
organizationService: OrganizationService;
|
|
9
|
+
subdomain: string;
|
|
10
|
+
});
|
|
11
|
+
initOrganization(): Promise<void>;
|
|
12
|
+
fetchOrganization(): Promise<Organization | null>;
|
|
13
|
+
}
|