forked from dubinc/dub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edge-config.ts
54 lines (49 loc) · 1.31 KB
/
edge-config.ts
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
import { get } from "@vercel/edge-config";
import { getDomainWithoutWWW } from "./utils";
export const isBlacklistedDomain = async (domain: string) => {
let blacklistedDomains;
try {
blacklistedDomains = await get("domains");
} catch (e) {
blacklistedDomains = [];
}
return new RegExp(blacklistedDomains.join("|")).test(
getDomainWithoutWWW(domain) || domain,
);
};
export const isBlacklistedKey = async (key: string) => {
let blacklistedKeys;
try {
blacklistedKeys = await get("keys");
} catch (e) {
blacklistedKeys = [];
}
return new RegExp(blacklistedKeys.join("|"), "i").test(key);
};
export const isWhitelistedEmail = async (email: string) => {
let whitelistedEmails;
try {
whitelistedEmails = await get("whitelist");
} catch (e) {
whitelistedEmails = [];
}
return new Set(whitelistedEmails).has(email);
};
export const isBlacklistedEmail = async (email: string) => {
let blacklistedEmails;
try {
blacklistedEmails = await get("emails");
} catch (e) {
blacklistedEmails = [];
}
return new RegExp(blacklistedEmails.join("|"), "i").test(email);
};
export const isReservedKey = async (key: string) => {
let reservedKey;
try {
reservedKey = await get("reserved");
} catch (e) {
reservedKey = [];
}
return new Set(reservedKey).has(key);
};