Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions apps/api/src/__tests__/snips/v1/billing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ describeIf(TEST_PRODUCTION)("Billing tests", () => {
name: "billing/bills ZDR scrape correctly",
credits: 100,
flags: {
allowZDR: true,
scrapeZDR: "allowed",
},
});

Expand Down Expand Up @@ -462,7 +462,7 @@ describeIf(TEST_PRODUCTION)("Billing tests", () => {
name: "billing/bills ZDR batch scrape correctly",
credits: 100,
flags: {
allowZDR: true,
scrapeZDR: "allowed",
},
});

Expand Down Expand Up @@ -531,7 +531,7 @@ describeIf(TEST_PRODUCTION)("Billing tests", () => {
name: "billing/bills ZDR crawl correctly",
credits: 200,
flags: {
allowZDR: true,
scrapeZDR: "allowed",
},
});

Expand Down Expand Up @@ -595,7 +595,7 @@ describeIf(TEST_PRODUCTION)("Billing tests", () => {
name: "billing/bills ZDR scrape correctly",
credits: 100,
flags: {
allowZDR: true,
scrapeZDR: "allowed",
zdrCost: 0,
},
});
Expand Down
21 changes: 3 additions & 18 deletions apps/api/src/__tests__/snips/v1/zdr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ describeIf(TEST_PRODUCTION)("Zero Data Retention", () => {
name: `zdr/${scope}/scrape`,
credits: 10000,
flags: {
allowZDR: true,
...(scope === "Team-scoped"
? {
forceZDR: true,
}
: {}),
scrapeZDR: scope === "Team-scoped" ? "forced" : "allowed",
},
});

Expand Down Expand Up @@ -66,12 +61,7 @@ describeIf(TEST_PRODUCTION)("Zero Data Retention", () => {
name: `zdr/${scope}/crawl`,
credits: 10000,
flags: {
allowZDR: true,
...(scope === "Team-scoped"
? {
forceZDR: true,
}
: {}),
scrapeZDR: scope === "Team-scoped" ? "forced" : "allowed",
},
});

Expand Down Expand Up @@ -122,12 +112,7 @@ describeIf(TEST_PRODUCTION)("Zero Data Retention", () => {
name: `zdr/${scope}/batch-scrape`,
credits: 10000,
flags: {
allowZDR: true,
...(scope === "Team-scoped"
? {
forceZDR: true,
}
: {}),
scrapeZDR: scope === "Team-scoped" ? "forced" : "allowed",
},
});

Expand Down
8 changes: 4 additions & 4 deletions apps/api/src/__tests__/snips/v2/billing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ describeIf(TEST_PRODUCTION)("Billing tests", () => {
name: "billing/bills ZDR scrape correctly",
credits: 100,
flags: {
allowZDR: true,
scrapeZDR: "allowed",
},
});

Expand Down Expand Up @@ -439,7 +439,7 @@ describeIf(TEST_PRODUCTION)("Billing tests", () => {
name: "billing/bills ZDR batch scrape correctly",
credits: 100,
flags: {
allowZDR: true,
scrapeZDR: "allowed",
},
});

Expand Down Expand Up @@ -510,7 +510,7 @@ describeIf(TEST_PRODUCTION)("Billing tests", () => {
name: "billing/bills ZDR crawl correctly",
credits: 200,
flags: {
allowZDR: true,
scrapeZDR: "allowed",
},
});

Expand Down Expand Up @@ -576,7 +576,7 @@ describeIf(TEST_PRODUCTION)("Billing tests", () => {
name: "billing/bills ZDR scrape correctly",
credits: 100,
flags: {
allowZDR: true,
scrapeZDR: "allowed",
zdrCost: 0,
},
});
Expand Down
21 changes: 3 additions & 18 deletions apps/api/src/__tests__/snips/v2/zdr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ describeIf(TEST_PRODUCTION)("Zero Data Retention", () => {
name: `zdr/${scope}/scrape`,
credits: 10000,
flags: {
allowZDR: true,
...(scope === "Team-scoped"
? {
forceZDR: true,
}
: {}),
scrapeZDR: scope === "Team-scoped" ? "forced" : "allowed",
},
});

Expand Down Expand Up @@ -66,12 +61,7 @@ describeIf(TEST_PRODUCTION)("Zero Data Retention", () => {
name: `zdr/${scope}/crawl`,
credits: 10000,
flags: {
allowZDR: true,
...(scope === "Team-scoped"
? {
forceZDR: true,
}
: {}),
scrapeZDR: scope === "Team-scoped" ? "forced" : "allowed",
},
});

Expand Down Expand Up @@ -120,12 +110,7 @@ describeIf(TEST_PRODUCTION)("Zero Data Retention", () => {
name: `zdr/${scope}/batch-scrape`,
credits: 10000,
flags: {
allowZDR: true,
...(scope === "Team-scoped"
? {
forceZDR: true,
}
: {}),
scrapeZDR: scope === "Team-scoped" ? "forced" : "allowed",
},
});

Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/controllers/v0/crawl-cancel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as Sentry from "@sentry/node";
import { configDotenv } from "dotenv";
import { redisEvictConnection } from "../../../src/services/redis";
import { crawlGroup } from "../../services/worker/nuq";
import { getScrapeZDR } from "../../lib/zdr-helpers";
configDotenv();

export async function crawlCancelController(req: Request, res: Response) {
Expand All @@ -18,7 +19,7 @@ export async function crawlCancelController(req: Request, res: Response) {

const { team_id } = auth;

if (auth.chunk?.flags?.forceZDR) {
if (getScrapeZDR(auth.chunk?.flags) === "forced") {
return res.status(400).json({
error:
"Your team has zero data retention enabled. This is not supported on the v0 API. Please update your code to use the v1 API.",
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/controllers/v0/crawl-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type { DBScrape, PseudoJob } from "../v1/crawl-status";
import { getJobFromGCS } from "../../lib/gcs-jobs";
import { scrapeQueue, NuQJob } from "../../services/worker/nuq";
import { includesFormat } from "../../lib/format-utils";
import { getScrapeZDR } from "../../lib/zdr-helpers";
configDotenv();

async function getJobs(
Expand Down Expand Up @@ -96,7 +97,7 @@ export async function crawlStatusController(req: Request, res: Response) {
return res.status(auth.status).json({ error: auth.error });
}

if (auth.chunk?.flags?.forceZDR) {
if (getScrapeZDR(auth.chunk?.flags) === "forced") {
return res.status(400).json({
error:
"Your team has zero data retention enabled. This is not supported on the v0 API. Please update your code to use the v1 API.",
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/controllers/v0/crawl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { fromV0ScrapeOptions } from "../v2/types";
import { isSelfHosted } from "../../lib/deployment";
import { crawlGroup } from "../../services/worker/nuq";
import { logRequest } from "../../services/logging/log_job";
import { getScrapeZDR } from "../../lib/zdr-helpers";

export async function crawlController(req: Request, res: Response) {
try {
Expand All @@ -45,7 +46,7 @@ export async function crawlController(req: Request, res: Response) {

const { team_id, chunk } = auth;

if (chunk?.flags?.forceZDR) {
if (getScrapeZDR(chunk?.flags) === "forced") {
return res.status(400).json({
error:
"Your team has zero data retention enabled. This is not supported on the v0 API. Please update your code to use the v1 API.",
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/controllers/v0/keyAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Request, Response } from "express";
import { authenticateUser } from "../auth";
import { redisEvictConnection } from "../../../src/services/redis";
import { logger } from "../../lib/logger";
import { getScrapeZDR } from "../../lib/zdr-helpers";

export const keyAuthController = async (req: Request, res: Response) => {
try {
Expand All @@ -13,7 +14,7 @@ export const keyAuthController = async (req: Request, res: Response) => {
return res.status(auth.status).json({ error: auth.error });
}

if (auth.chunk?.flags?.forceZDR) {
if (getScrapeZDR(auth.chunk?.flags) === "forced") {
return res.status(400).json({
error:
"Your team has zero data retention enabled. This is not supported on the v0 API. Please update your code to use the v1 API.",
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/controllers/v0/scrape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { ScrapeJobTimeoutError } from "../../lib/error";
import { scrapeQueue } from "../../services/worker/nuq";
import { getErrorContactMessage } from "../../lib/deployment";
import { logRequest } from "../../services/logging/log_job";
import { getScrapeZDR } from "../../lib/zdr-helpers";

async function scrapeHelper(
jobId: string,
Expand Down Expand Up @@ -185,7 +186,7 @@ export async function scrapeController(req: Request, res: Response) {

const { team_id, chunk } = auth;

if (chunk?.flags?.forceZDR) {
if (getScrapeZDR(chunk?.flags) === "forced") {
return res.status(400).json({
error:
"Your team has zero data retention enabled. This is not supported on the v0 API. Please update your code to use the v1 API.",
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/controllers/v0/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { fromV0Combo } from "../v2/types";
import { ScrapeJobTimeoutError } from "../../lib/error";
import { scrapeQueue } from "../../services/worker/nuq";
import { defaultOrigin } from "../../lib/default-values";
import { getSearchZDR } from "../../lib/zdr-helpers";

async function searchHelper(
jobId: string,
Expand Down Expand Up @@ -176,7 +177,7 @@ export async function searchController(req: Request, res: Response) {
}
const { team_id, chunk } = auth;

if (chunk?.flags?.forceZDR) {
if (getSearchZDR(chunk?.flags) === "forced") {
return res.status(400).json({
error:
"Your team has zero data retention enabled. This is not supported on the v0 API. Please update your code to use the v1 API.",
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/controllers/v1/batch-scrape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { fromV1ScrapeOptions } from "../v2/types";
import { checkPermissions } from "../../lib/permissions";
import { crawlGroup } from "../../services/worker/nuq";
import { logRequest } from "../../services/logging/log_job";
import { getScrapeZDR } from "../../lib/zdr-helpers";

export async function batchScrapeController(
req: RequestWithAuth<{}, BatchScrapeResponse, BatchScrapeRequest>,
Expand All @@ -49,7 +50,7 @@ export async function batchScrapeController(
}

const zeroDataRetention =
req.acuc?.flags?.forceZDR || req.body.zeroDataRetention;
getScrapeZDR(req.acuc?.flags) === "forced" || req.body.zeroDataRetention;

const id = req.body.appendToId ?? uuidv7();
const logger = _logger.child({
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/controllers/v1/crawl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { fromV1ScrapeOptions } from "../v2/types";
import { checkPermissions } from "../../lib/permissions";
import { crawlGroup } from "../../services/worker/nuq";
import { logRequest } from "../../services/logging/log_job";
import { getScrapeZDR } from "../../lib/zdr-helpers";

export async function crawlController(
req: RequestWithAuth<{}, CrawlResponse, CrawlRequest>,
Expand All @@ -37,7 +38,7 @@ export async function crawlController(
}

const zeroDataRetention =
req.acuc?.flags?.forceZDR || req.body.zeroDataRetention;
getScrapeZDR(req.acuc?.flags) === "forced" || req.body.zeroDataRetention;

const id = uuidv7();
const logger = _logger.child({
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/controllers/v1/deep-research.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as Sentry from "@sentry/node";
import { saveDeepResearch } from "../../lib/deep-research/deep-research-redis";
import { z } from "zod";
import { logRequest } from "../../services/logging/log_job";
import { getScrapeZDR } from "../../lib/zdr-helpers";

const deepResearchRequestSchema = z
.object({
Expand Down Expand Up @@ -81,7 +82,7 @@ export async function deepResearchController(
req: RequestWithAuth<{}, DeepResearchResponse, DeepResearchRequest>,
res: Response<DeepResearchResponse>,
) {
if (req.acuc?.flags?.forceZDR) {
if (getScrapeZDR(req.acuc?.flags) === "forced") {
return res.status(400).json({
success: false,
error:
Expand Down
7 changes: 4 additions & 3 deletions apps/api/src/controllers/v1/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from "../v2/types";
import { createWebhookSender, WebhookEvent } from "../../services/webhook";
import { logRequest } from "../../services/logging/log_job";
import { getScrapeZDR } from "../../lib/zdr-helpers";

import { config } from "../../config";
async function oldExtract(
Expand Down Expand Up @@ -105,7 +106,7 @@ export async function extractController(
const originalRequest = { ...req.body };
req.body = extractRequestSchema.parse(req.body);

if (req.acuc?.flags?.forceZDR) {
if (getScrapeZDR(req.acuc?.flags) === "forced") {
return res.status(400).json({
success: false,
error:
Expand Down Expand Up @@ -138,7 +139,7 @@ export async function extractController(
team_id: req.auth.team_id,
subId: req.acuc?.sub_id,
extractId,
zeroDataRetention: req.acuc?.flags?.forceZDR,
zeroDataRetention: getScrapeZDR(req.acuc?.flags) === "forced",
});

await logRequest({
Expand Down Expand Up @@ -193,7 +194,7 @@ export async function extractController(
showLLMUsage: req.body.__experimental_llmUsage,
showSources: req.body.__experimental_showSources || req.body.showSources,
showCostTracking: req.body.__experimental_showCostTracking,
zeroDataRetention: req.acuc?.flags?.forceZDR,
zeroDataRetention: getScrapeZDR(req.acuc?.flags) === "forced",
});

await addExtractJobToQueue(extractId, jobData);
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/controllers/v1/generate-llmstxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getGenerateLlmsTxtQueue } from "../../services/queue-service";
import * as Sentry from "@sentry/node";
import { saveGeneratedLlmsTxt } from "../../lib/generate-llmstxt/generate-llmstxt-redis";
import { logRequest } from "../../services/logging/log_job";
import { getScrapeZDR } from "../../lib/zdr-helpers";

type GenerateLLMsTextResponse =
| ErrorResponse
Expand All @@ -28,7 +29,7 @@ export async function generateLLMsTextController(
req: RequestWithAuth<{}, GenerateLLMsTextResponse, GenerateLLMsTextRequest>,
res: Response<GenerateLLMsTextResponse>,
) {
if (req.acuc?.flags?.forceZDR) {
if (getScrapeZDR(req.acuc?.flags) === "forced") {
return res.status(400).json({
success: false,
error:
Expand Down
5 changes: 3 additions & 2 deletions apps/api/src/controllers/v1/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
} from "../../services/index";
import { MapTimeoutError } from "../../lib/error";
import { checkPermissions } from "../../lib/permissions";
import { getScrapeZDR } from "../../lib/zdr-helpers";

configDotenv();
const redis = new Redis(config.REDIS_URL!);
Expand Down Expand Up @@ -126,7 +127,7 @@ export async function getMapResults({
let links: string[] = [url];
let mapResults: MapDocument[] = [];

const zeroDataRetention = flags?.forceZDR || false;
const zeroDataRetention = getScrapeZDR(flags) === "forced" || false;

const sc: StoredCrawl = {
originUrl: url,
Expand Down Expand Up @@ -369,7 +370,7 @@ export async function mapController(
const originalRequest = req.body;
req.body = mapRequestSchema.parse(req.body);

if (req.acuc?.flags?.forceZDR) {
if (getScrapeZDR(req.acuc?.flags) === "forced") {
return res.status(400).json({
success: false,
error:
Expand Down
Loading
Loading