-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathfiredata.ts
More file actions
55 lines (45 loc) · 1.73 KB
/
Copy pathfiredata.ts
File metadata and controls
55 lines (45 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { Client } from "../apiv2";
import { firedataOrigin } from "../api";
import { FirebaseError } from "../error";
const client = new Client({ urlPrefix: firedataOrigin(), auth: true, apiVersion: "v1" });
export const APPHOSTING_TOS_ID = "APP_HOSTING_TOS";
export const APP_CHECK_TOS_ID = "APP_CHECK";
export const DATA_CONNECT_TOS_ID = "FIREBASE_DATA_CONNECT";
export type TosId = typeof APPHOSTING_TOS_ID | typeof APP_CHECK_TOS_ID | typeof DATA_CONNECT_TOS_ID;
export type AcceptanceStatus = null | "ACCEPTED" | "TERMS_UPDATED";
export interface TosAcceptanceStatus {
status: AcceptanceStatus;
}
export interface ServiceTosStatus {
tosId: TosId;
serviceStatus: TosAcceptanceStatus;
}
export interface GetTosStatusResponse {
perServiceStatus: ServiceTosStatus[];
}
/**
* Fetches the Terms of Service status for the logged in user.
*/
export async function getTosStatus(): Promise<GetTosStatusResponse> {
const res = await client.request<void, GetTosStatusResponse>({
method: "GET",
path: "accessmanagement/tos:getStatus",
ignoreQuotaProject: true,
});
return res.body;
}
/** Returns the AcceptanceStatus for a given product. */
export function getAcceptanceStatus(
response: GetTosStatusResponse,
tosId: TosId,
): AcceptanceStatus {
const perServiceStatus = response.perServiceStatus.find((tosStatus) => tosStatus.tosId === tosId);
if (perServiceStatus === undefined) {
throw new FirebaseError(`Missing terms of service status for product: ${tosId}`);
}
return perServiceStatus.serviceStatus.status;
}
/** Returns true if a product's ToS has been accepted. */
export function isProductTosAccepted(response: GetTosStatusResponse, tosId: TosId): boolean {
return getAcceptanceStatus(response, tosId) === "ACCEPTED";
}