Spaces:
Sleeping
Sleeping
File size: 2,146 Bytes
097eaf0 | 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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | import { TeamFlags } from "../controllers/v2/types";
import {
getScrapeZDR,
getIgnoreRobots,
getCustomRobotsAgent,
} from "./zdr-helpers";
type LocationOptions = { country?: string };
interface APIRequest {
zeroDataRetention?: boolean;
location?: LocationOptions;
scrapeOptions?: {
location?: LocationOptions;
};
crawlerOptions?: {
ignoreRobotsTxt?: boolean;
robotsUserAgent?: string;
};
}
const SUPPORT_EMAIL = "support@firecrawl.com";
export function checkPermissions(
request: APIRequest,
flags?: TeamFlags,
): { error?: string } {
// zdr perms — scrapeZDR must be 'allowed' or 'forced' for request-scoped ZDR
const scrapeMode = getScrapeZDR(flags);
if (
request.zeroDataRetention &&
scrapeMode !== "allowed" &&
scrapeMode !== "forced"
) {
return {
error: `Zero Data Retention (ZDR) is not enabled for your team. Contact ${SUPPORT_EMAIL} to enable this feature.`,
};
}
// robots perms — ignoreRobots must be 'allowed' or 'forced'
const robotsMode = getIgnoreRobots(flags);
if (
request.crawlerOptions?.ignoreRobotsTxt &&
robotsMode !== "allowed" &&
robotsMode !== "forced"
) {
return {
error: `The ignoreRobotsTxt parameter is an enterprise feature. Contact ${SUPPORT_EMAIL} to explore whether it can be enabled for your team.`,
};
}
// customRobotsAgent perms — separate flag for robotsUserAgent
const customAgentMode = getCustomRobotsAgent(flags);
if (
request.crawlerOptions?.robotsUserAgent &&
customAgentMode !== "allowed"
) {
return {
error: `The robotsUserAgent parameter is an enterprise feature. Contact ${SUPPORT_EMAIL} to explore whether it can be enabled for your team.`,
};
}
// ip whitelist perms
const needsWhitelist =
request.location?.country === "us-whitelist" ||
request.scrapeOptions?.location?.country === "us-whitelist";
if (needsWhitelist && !flags?.ipWhitelist) {
return {
error: `Static IP addresses are not enabled for your team. Contact ${SUPPORT_EMAIL} to get a dedicated set of IP addresses you can whitelist.`,
};
}
return {};
}
|