From 428b352a9ed7cb1eca64c2d312ef324eddfe3ec4 Mon Sep 17 00:00:00 2001 From: Andrew Jiang Date: Thu, 20 Jun 2024 16:52:35 -0400 Subject: [PATCH] fix: docsv2 distinct by domain (#1056) --- .../definition/docs/v2/read/__package__.yml | 35 ++--- .../v2/resources/read/client/Client.ts | 123 ++++++++++-------- .../v2/resources/read/client/index.ts | 2 +- .../resources/read/client/listAllDocsUrls.ts | 19 ++- .../client/requests/ListAllDocsUrlsRequest.ts | 7 +- .../resources/read/client/requests/index.ts | 2 +- .../src/__test__/local/services/docs.test.ts | 16 +++ .../resources/read/service/ReadService.d.ts | 17 +-- .../v2/resources/read/service/ReadService.js | 31 +++-- .../docs/v2/getDocsReadV2Service.ts | 11 +- servers/fdr/src/db/docs/DocsV2Dao.ts | 34 ++++- 11 files changed, 195 insertions(+), 102 deletions(-) diff --git a/fern/apis/fdr/definition/docs/v2/read/__package__.yml b/fern/apis/fdr/definition/docs/v2/read/__package__.yml index 99f2533094..d8fb5980da 100644 --- a/fern/apis/fdr/definition/docs/v2/read/__package__.yml +++ b/fern/apis/fdr/definition/docs/v2/read/__package__.yml @@ -50,6 +50,26 @@ service: - DomainNotRegisteredError - rootCommons.UnauthorizedError + listAllDocsUrls: + method: GET + auth: true + path: /urls/list + request: + name: ListAllDocsUrlsRequest + query-parameters: + page: optional + limit: optional + custom: + type: optional + docs: If true, filters to only docs with a custom URL. + response: ListAllDocsUrlsResponse + docs: Returns a list of all public docs. + errors: + - rootCommons.UnauthorizedError + # pagination: + # offset: $request.page + # results: $response.urls + getDocsConfigById: method: GET path: /{docsConfigId} @@ -73,21 +93,6 @@ service: errors: - IndexSegmentNotFoundError - listAllDocsUrls: - auth: true - method: GET - path: /urls - request: - name: ListAllDocsUrlsRequest - query-parameters: - page: optional - limit: optional - response: ListAllDocsUrlsResponse - docs: Returns a list of all public docs. - # pagination: - # offset: $request.page - # results: $response.urls - types: GetDocsConfigByIdResponse: properties: diff --git a/packages/fdr-sdk/src/client/generated/api/resources/docs/resources/v2/resources/read/client/Client.ts b/packages/fdr-sdk/src/client/generated/api/resources/docs/resources/v2/resources/read/client/Client.ts index 144fb158d1..7ac9eb1d61 100644 --- a/packages/fdr-sdk/src/client/generated/api/resources/docs/resources/v2/resources/read/client/Client.ts +++ b/packages/fdr-sdk/src/client/generated/api/resources/docs/resources/v2/resources/read/client/Client.ts @@ -198,27 +198,45 @@ export class Read { } /** - * Loads the Docs Config and any referenced APIs by ID. + * Returns a list of all public docs. * - * @param {FernRegistry.DocsConfigId} docsConfigId + * @param {FernRegistry.docs.v2.read.ListAllDocsUrlsRequest} request * @param {Read.RequestOptions} requestOptions - Request-specific configuration. * * @example - * await fernRegistry.docs.v2.read.getDocsConfigById("string") + * await fernRegistry.docs.v2.read.listAllDocsUrls({ + * page: 1, + * limit: 1, + * custom: true + * }) */ - public async getDocsConfigById( - docsConfigId: FernRegistry.DocsConfigId, + public async listAllDocsUrls( + request: FernRegistry.docs.v2.read.ListAllDocsUrlsRequest = {}, requestOptions?: Read.RequestOptions ): Promise< core.APIResponse< - FernRegistry.docs.v2.read.GetDocsConfigByIdResponse, - FernRegistry.docs.v2.read.getDocsConfigById.Error + FernRegistry.docs.v2.read.ListAllDocsUrlsResponse, + FernRegistry.docs.v2.read.listAllDocsUrls.Error > > { + const { page, limit, custom } = request; + const _queryParams: Record = {}; + if (page != null) { + _queryParams["page"] = page.toString(); + } + + if (limit != null) { + _queryParams["limit"] = limit.toString(); + } + + if (custom != null) { + _queryParams["custom"] = custom.toString(); + } + const _response = await core.fetcher({ url: urlJoin( (await core.Supplier.get(this._options.environment)) ?? environments.FernRegistryEnvironment.Prod, - `/v2/registry/docs/${encodeURIComponent(docsConfigId)}` + "/v2/registry/docs/urls/list" ), method: "GET", headers: { @@ -228,6 +246,7 @@ export class Read { "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + queryParameters: _queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : undefined, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -235,50 +254,50 @@ export class Read { if (_response.ok) { return { ok: true, - body: _response.body as FernRegistry.docs.v2.read.GetDocsConfigByIdResponse, + body: _response.body as FernRegistry.docs.v2.read.ListAllDocsUrlsResponse, }; } if (_response.error.reason === "status-code") { - switch ((_response.error.body as FernRegistry.docs.v2.read.getDocsConfigById.Error)?.error) { - case "DocsDefinitionNotFoundError": + switch ((_response.error.body as FernRegistry.docs.v2.read.listAllDocsUrls.Error)?.error) { + case "UnauthorizedError": return { ok: false, - error: _response.error.body as FernRegistry.docs.v2.read.getDocsConfigById.Error, + error: _response.error.body as FernRegistry.docs.v2.read.listAllDocsUrls.Error, }; } } return { ok: false, - error: FernRegistry.docs.v2.read.getDocsConfigById.Error._unknown(_response.error), + error: FernRegistry.docs.v2.read.listAllDocsUrls.Error._unknown(_response.error), }; } /** - * @param {FernRegistry.docs.v2.read.GetSearchApiKeyForIndexSegmentRequest} request + * Loads the Docs Config and any referenced APIs by ID. + * + * @param {FernRegistry.DocsConfigId} docsConfigId * @param {Read.RequestOptions} requestOptions - Request-specific configuration. * * @example - * await fernRegistry.docs.v2.read.getSearchApiKeyForIndexSegment({ - * indexSegmentId: "string" - * }) + * await fernRegistry.docs.v2.read.getDocsConfigById("string") */ - public async getSearchApiKeyForIndexSegment( - request: FernRegistry.docs.v2.read.GetSearchApiKeyForIndexSegmentRequest, + public async getDocsConfigById( + docsConfigId: FernRegistry.DocsConfigId, requestOptions?: Read.RequestOptions ): Promise< core.APIResponse< - FernRegistry.docs.v2.read.GetSearchApiKeyForIndexSegmentResponse, - FernRegistry.docs.v2.read.getSearchApiKeyForIndexSegment.Error + FernRegistry.docs.v2.read.GetDocsConfigByIdResponse, + FernRegistry.docs.v2.read.getDocsConfigById.Error > > { const _response = await core.fetcher({ url: urlJoin( (await core.Supplier.get(this._options.environment)) ?? environments.FernRegistryEnvironment.Prod, - "/v2/registry/docs/search-api-key-with-index-segment" + `/v2/registry/docs/${encodeURIComponent(docsConfigId)}` ), - method: "POST", + method: "GET", headers: { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", @@ -286,7 +305,6 @@ export class Read { "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : undefined, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -294,63 +312,50 @@ export class Read { if (_response.ok) { return { ok: true, - body: _response.body as FernRegistry.docs.v2.read.GetSearchApiKeyForIndexSegmentResponse, + body: _response.body as FernRegistry.docs.v2.read.GetDocsConfigByIdResponse, }; } if (_response.error.reason === "status-code") { - switch ((_response.error.body as FernRegistry.docs.v2.read.getSearchApiKeyForIndexSegment.Error)?.error) { - case "IndexSegmentNotFoundError": + switch ((_response.error.body as FernRegistry.docs.v2.read.getDocsConfigById.Error)?.error) { + case "DocsDefinitionNotFoundError": return { ok: false, - error: _response.error.body as FernRegistry.docs.v2.read.getSearchApiKeyForIndexSegment.Error, + error: _response.error.body as FernRegistry.docs.v2.read.getDocsConfigById.Error, }; } } return { ok: false, - error: FernRegistry.docs.v2.read.getSearchApiKeyForIndexSegment.Error._unknown(_response.error), + error: FernRegistry.docs.v2.read.getDocsConfigById.Error._unknown(_response.error), }; } /** - * Returns a list of all public docs. - * - * @param {FernRegistry.docs.v2.read.ListAllDocsUrlsRequest} request + * @param {FernRegistry.docs.v2.read.GetSearchApiKeyForIndexSegmentRequest} request * @param {Read.RequestOptions} requestOptions - Request-specific configuration. * * @example - * await fernRegistry.docs.v2.read.listAllDocsUrls({ - * page: 1, - * limit: 1 + * await fernRegistry.docs.v2.read.getSearchApiKeyForIndexSegment({ + * indexSegmentId: "string" * }) */ - public async listAllDocsUrls( - request: FernRegistry.docs.v2.read.ListAllDocsUrlsRequest = {}, + public async getSearchApiKeyForIndexSegment( + request: FernRegistry.docs.v2.read.GetSearchApiKeyForIndexSegmentRequest, requestOptions?: Read.RequestOptions ): Promise< core.APIResponse< - FernRegistry.docs.v2.read.ListAllDocsUrlsResponse, - FernRegistry.docs.v2.read.listAllDocsUrls.Error + FernRegistry.docs.v2.read.GetSearchApiKeyForIndexSegmentResponse, + FernRegistry.docs.v2.read.getSearchApiKeyForIndexSegment.Error > > { - const { page, limit } = request; - const _queryParams: Record = {}; - if (page != null) { - _queryParams["page"] = page.toString(); - } - - if (limit != null) { - _queryParams["limit"] = limit.toString(); - } - const _response = await core.fetcher({ url: urlJoin( (await core.Supplier.get(this._options.environment)) ?? environments.FernRegistryEnvironment.Prod, - "/v2/registry/docs/urls" + "/v2/registry/docs/search-api-key-with-index-segment" ), - method: "GET", + method: "POST", headers: { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", @@ -358,7 +363,7 @@ export class Read { "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - queryParameters: _queryParams, + body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : undefined, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -366,13 +371,23 @@ export class Read { if (_response.ok) { return { ok: true, - body: _response.body as FernRegistry.docs.v2.read.ListAllDocsUrlsResponse, + body: _response.body as FernRegistry.docs.v2.read.GetSearchApiKeyForIndexSegmentResponse, }; } + if (_response.error.reason === "status-code") { + switch ((_response.error.body as FernRegistry.docs.v2.read.getSearchApiKeyForIndexSegment.Error)?.error) { + case "IndexSegmentNotFoundError": + return { + ok: false, + error: _response.error.body as FernRegistry.docs.v2.read.getSearchApiKeyForIndexSegment.Error, + }; + } + } + return { ok: false, - error: FernRegistry.docs.v2.read.listAllDocsUrls.Error._unknown(_response.error), + error: FernRegistry.docs.v2.read.getSearchApiKeyForIndexSegment.Error._unknown(_response.error), }; } diff --git a/packages/fdr-sdk/src/client/generated/api/resources/docs/resources/v2/resources/read/client/index.ts b/packages/fdr-sdk/src/client/generated/api/resources/docs/resources/v2/resources/read/client/index.ts index 0a70fb1c99..1a2745262b 100644 --- a/packages/fdr-sdk/src/client/generated/api/resources/docs/resources/v2/resources/read/client/index.ts +++ b/packages/fdr-sdk/src/client/generated/api/resources/docs/resources/v2/resources/read/client/index.ts @@ -2,6 +2,6 @@ export * from "./requests"; export * as getOrganizationForUrl from "./getOrganizationForUrl"; export * as getDocsForUrl from "./getDocsForUrl"; export * as getPrivateDocsForUrl from "./getPrivateDocsForUrl"; +export * as listAllDocsUrls from "./listAllDocsUrls"; export * as getDocsConfigById from "./getDocsConfigById"; export * as getSearchApiKeyForIndexSegment from "./getSearchApiKeyForIndexSegment"; -export * as listAllDocsUrls from "./listAllDocsUrls"; diff --git a/packages/fdr-sdk/src/client/generated/api/resources/docs/resources/v2/resources/read/client/listAllDocsUrls.ts b/packages/fdr-sdk/src/client/generated/api/resources/docs/resources/v2/resources/read/client/listAllDocsUrls.ts index f6979058b0..25a3c0feeb 100644 --- a/packages/fdr-sdk/src/client/generated/api/resources/docs/resources/v2/resources/read/client/listAllDocsUrls.ts +++ b/packages/fdr-sdk/src/client/generated/api/resources/docs/resources/v2/resources/read/client/listAllDocsUrls.ts @@ -5,20 +5,35 @@ import * as FernRegistry from "../../../../../../../index"; import * as core from "../../../../../../../../core"; -export type Error = FernRegistry.docs.v2.read.listAllDocsUrls.Error._Unknown; +export type Error = + | FernRegistry.docs.v2.read.listAllDocsUrls.Error.UnauthorizedError + | FernRegistry.docs.v2.read.listAllDocsUrls.Error._Unknown; export declare namespace Error { + interface UnauthorizedError { + error: "UnauthorizedError"; + content: string; + } + interface _Unknown { error: void; content: core.Fetcher.Error; } interface _Visitor<_Result> { + unauthorizedError: (value: string) => _Result; _other: (value: core.Fetcher.Error) => _Result; } } export const Error = { + unauthorizedError: (value: string): FernRegistry.docs.v2.read.listAllDocsUrls.Error.UnauthorizedError => { + return { + content: value, + error: "UnauthorizedError", + }; + }, + _unknown: (fetcherError: core.Fetcher.Error): FernRegistry.docs.v2.read.listAllDocsUrls.Error._Unknown => { return { error: undefined, @@ -31,6 +46,8 @@ export const Error = { visitor: FernRegistry.docs.v2.read.listAllDocsUrls.Error._Visitor<_Result> ): _Result => { switch (value.error) { + case "UnauthorizedError": + return visitor.unauthorizedError(value.content); default: return visitor._other(value as any); } diff --git a/packages/fdr-sdk/src/client/generated/api/resources/docs/resources/v2/resources/read/client/requests/ListAllDocsUrlsRequest.ts b/packages/fdr-sdk/src/client/generated/api/resources/docs/resources/v2/resources/read/client/requests/ListAllDocsUrlsRequest.ts index 91a50b0e37..5b99e66761 100644 --- a/packages/fdr-sdk/src/client/generated/api/resources/docs/resources/v2/resources/read/client/requests/ListAllDocsUrlsRequest.ts +++ b/packages/fdr-sdk/src/client/generated/api/resources/docs/resources/v2/resources/read/client/requests/ListAllDocsUrlsRequest.ts @@ -6,10 +6,15 @@ * @example * { * page: 1, - * limit: 1 + * limit: 1, + * custom: true * } */ export interface ListAllDocsUrlsRequest { page?: number; limit?: number; + /** + * If true, filters to only docs with a custom URL. + */ + custom?: boolean; } diff --git a/packages/fdr-sdk/src/client/generated/api/resources/docs/resources/v2/resources/read/client/requests/index.ts b/packages/fdr-sdk/src/client/generated/api/resources/docs/resources/v2/resources/read/client/requests/index.ts index d0d75835fa..d764509d55 100644 --- a/packages/fdr-sdk/src/client/generated/api/resources/docs/resources/v2/resources/read/client/requests/index.ts +++ b/packages/fdr-sdk/src/client/generated/api/resources/docs/resources/v2/resources/read/client/requests/index.ts @@ -1,5 +1,5 @@ export { type GetOrganizationForUrlRequest } from "./GetOrganizationForUrlRequest"; export { type LoadDocsForUrlRequest } from "./LoadDocsForUrlRequest"; export { type LoadPrivateDocsForUrlRequest } from "./LoadPrivateDocsForUrlRequest"; -export { type GetSearchApiKeyForIndexSegmentRequest } from "./GetSearchApiKeyForIndexSegmentRequest"; export { type ListAllDocsUrlsRequest } from "./ListAllDocsUrlsRequest"; +export { type GetSearchApiKeyForIndexSegmentRequest } from "./GetSearchApiKeyForIndexSegmentRequest"; diff --git a/servers/fdr/src/__test__/local/services/docs.test.ts b/servers/fdr/src/__test__/local/services/docs.test.ts index 2c78e324d1..61685dc688 100644 --- a/servers/fdr/src/__test__/local/services/docs.test.ts +++ b/servers/fdr/src/__test__/local/services/docs.test.ts @@ -155,3 +155,19 @@ it("docs reindex", async () => { expect(first.definition.search.value).not.toEqual(second.definition.search.value); }); + +test.sequential("revalidates a custom docs domain", async () => { + const fdr = getClient({ authed: true, url: inject("url") }); + + const resp = await fdr.docs.v2.read.listAllDocsUrls(); + console.log(resp); + + if (!resp.ok) { + throw new Error("Failed to list all docs urls"); + } + + const { urls } = resp.body; + console.log(urls); + + expect(urls.length).toBeGreaterThan(0); +}); diff --git a/servers/fdr/src/api/generated/api/resources/docs/resources/v2/resources/read/service/ReadService.d.ts b/servers/fdr/src/api/generated/api/resources/docs/resources/v2/resources/read/service/ReadService.d.ts index ef5566d693..06ceaceaca 100644 --- a/servers/fdr/src/api/generated/api/resources/docs/resources/v2/resources/read/service/ReadService.d.ts +++ b/servers/fdr/src/api/generated/api/resources/docs/resources/v2/resources/read/service/ReadService.d.ts @@ -19,6 +19,15 @@ export interface ReadServiceMethods { cookie: (cookie: string, value: string, options?: express.CookieOptions) => void; locals: any; }): void | Promise; + listAllDocsUrls(req: express.Request, res: { + send: (responseBody: FernRegistry.docs.v2.read.ListAllDocsUrlsResponse) => Promise; + cookie: (cookie: string, value: string, options?: express.CookieOptions) => void; + locals: any; + }): void | Promise; getDocsConfigById(req: express.Request<{ docsConfigId: FernRegistry.DocsConfigId; }, FernRegistry.docs.v2.read.GetDocsConfigByIdResponse, never, never>, res: { @@ -31,14 +40,6 @@ export interface ReadServiceMethods { cookie: (cookie: string, value: string, options?: express.CookieOptions) => void; locals: any; }): void | Promise; - listAllDocsUrls(req: express.Request, res: { - send: (responseBody: FernRegistry.docs.v2.read.ListAllDocsUrlsResponse) => Promise; - cookie: (cookie: string, value: string, options?: express.CookieOptions) => void; - locals: any; - }): void | Promise; } export declare class ReadService { private readonly methods; diff --git a/servers/fdr/src/api/generated/api/resources/docs/resources/v2/resources/read/service/ReadService.js b/servers/fdr/src/api/generated/api/resources/docs/resources/v2/resources/read/service/ReadService.js index f246183ba5..06ab1bee95 100644 --- a/servers/fdr/src/api/generated/api/resources/docs/resources/v2/resources/read/service/ReadService.js +++ b/servers/fdr/src/api/generated/api/resources/docs/resources/v2/resources/read/service/ReadService.js @@ -116,9 +116,9 @@ export class ReadService { next(error); } })); - this.router.get("/:docsConfigId", (req, res, next) => __awaiter(this, void 0, void 0, function* () { + this.router.get("/urls/list", (req, res, next) => __awaiter(this, void 0, void 0, function* () { try { - yield this.methods.getDocsConfigById(req, { + yield this.methods.listAllDocsUrls(req, { send: (responseBody) => __awaiter(this, void 0, void 0, function* () { res.json(responseBody); }), @@ -131,10 +131,10 @@ export class ReadService { console.error(error); if (error instanceof errors.FernRegistryError) { switch (error.errorName) { - case "DocsDefinitionNotFoundError": + case "UnauthorizedError": break; default: - console.warn(`Endpoint 'getDocsConfigById' unexpectedly threw ${error.constructor.name}.` + + console.warn(`Endpoint 'listAllDocsUrls' unexpectedly threw ${error.constructor.name}.` + ` If this was intentional, please add ${error.constructor.name} to` + " the endpoint's errors list in your Fern Definition."); } @@ -146,9 +146,9 @@ export class ReadService { next(error); } })); - this.router.post("/search-api-key-with-index-segment", (req, res, next) => __awaiter(this, void 0, void 0, function* () { + this.router.get("/:docsConfigId", (req, res, next) => __awaiter(this, void 0, void 0, function* () { try { - yield this.methods.getSearchApiKeyForIndexSegment(req, { + yield this.methods.getDocsConfigById(req, { send: (responseBody) => __awaiter(this, void 0, void 0, function* () { res.json(responseBody); }), @@ -161,10 +161,10 @@ export class ReadService { console.error(error); if (error instanceof errors.FernRegistryError) { switch (error.errorName) { - case "IndexSegmentNotFoundError": + case "DocsDefinitionNotFoundError": break; default: - console.warn(`Endpoint 'getSearchApiKeyForIndexSegment' unexpectedly threw ${error.constructor.name}.` + + console.warn(`Endpoint 'getDocsConfigById' unexpectedly threw ${error.constructor.name}.` + ` If this was intentional, please add ${error.constructor.name} to` + " the endpoint's errors list in your Fern Definition."); } @@ -176,9 +176,9 @@ export class ReadService { next(error); } })); - this.router.get("/urls", (req, res, next) => __awaiter(this, void 0, void 0, function* () { + this.router.post("/search-api-key-with-index-segment", (req, res, next) => __awaiter(this, void 0, void 0, function* () { try { - yield this.methods.listAllDocsUrls(req, { + yield this.methods.getSearchApiKeyForIndexSegment(req, { send: (responseBody) => __awaiter(this, void 0, void 0, function* () { res.json(responseBody); }), @@ -190,9 +190,14 @@ export class ReadService { catch (error) { console.error(error); if (error instanceof errors.FernRegistryError) { - console.warn(`Endpoint 'listAllDocsUrls' unexpectedly threw ${error.constructor.name}.` + - ` If this was intentional, please add ${error.constructor.name} to` + - " the endpoint's errors list in your Fern Definition."); + switch (error.errorName) { + case "IndexSegmentNotFoundError": + break; + default: + console.warn(`Endpoint 'getSearchApiKeyForIndexSegment' unexpectedly threw ${error.constructor.name}.` + + ` If this was intentional, please add ${error.constructor.name} to` + + " the endpoint's errors list in your Fern Definition."); + } yield error.send(res); } else { diff --git a/servers/fdr/src/controllers/docs/v2/getDocsReadV2Service.ts b/servers/fdr/src/controllers/docs/v2/getDocsReadV2Service.ts index 4e70204962..d07e2fe263 100644 --- a/servers/fdr/src/controllers/docs/v2/getDocsReadV2Service.ts +++ b/servers/fdr/src/controllers/docs/v2/getDocsReadV2Service.ts @@ -65,14 +65,21 @@ export function getDocsReadV2Service(app: FdrApplication): DocsV2ReadService { const searchApiKey = app.services.algoliaIndexSegmentManager.generateAndCacheApiKey(indexSegmentId); return res.send({ searchApiKey }); }, - async listAllDocsUrls(req, res) { + listAllDocsUrls: async (req, res) => { // must be a fern employee await app.services.auth.checkUserBelongsToOrg({ authHeader: req.headers.authorization, orgId: "fern", }); - return res.send(await app.dao.docsV2().listAllDocsUrls(req.query.limit, req.query.page)); + return res.send( + await app.dao.docsV2().listAllDocsUrls({ + limit: req.query.limit, + page: req.query.page, + customOnly: req.query.custom, + domainSuffix: app.config.domainSuffix, + }), + ); }, }); } diff --git a/servers/fdr/src/db/docs/DocsV2Dao.ts b/servers/fdr/src/db/docs/DocsV2Dao.ts index 1886747b79..d5becea2ce 100644 --- a/servers/fdr/src/db/docs/DocsV2Dao.ts +++ b/servers/fdr/src/db/docs/DocsV2Dao.ts @@ -61,7 +61,12 @@ export interface DocsV2Dao { indexSegments: IndexSegment[]; }): Promise; - listAllDocsUrls(limit?: number, page?: number): Promise; + listAllDocsUrls(opts: { + limit?: number; + page?: number; + customOnly?: boolean; + domainSuffix: string; + }): Promise; } export class DocsV2DaoImpl implements DocsV2Dao { @@ -179,19 +184,36 @@ export class DocsV2DaoImpl implements DocsV2Dao { }); } - public async listAllDocsUrls(limit: number = 1000, page: number = 1): Promise { - limit = Math.min(limit, 2000); - const response = await this.prisma.docsV2.groupBy({ + public async listAllDocsUrls({ + limit = 1000, + page = 1, + customOnly = false, + domainSuffix, + }: { + limit?: number; + page?: number; + customOnly?: boolean; + domainSuffix: string; + }): Promise { + limit = Math.min(limit, 1000); + const response = await this.prisma.docsV2.findMany({ + select: { + orgID: true, + domain: true, + path: true, + updatedTime: true, + }, where: { isPreview: false, authType: "PUBLIC", + domain: customOnly ? { not: { endsWith: domainSuffix } } : undefined, }, - by: ["orgID", "domain", "path", "updatedTime"], + distinct: "domain", orderBy: { updatedTime: "desc", }, take: limit, - skip: limit * (page - 1), + skip: Math.min(limit * (page - 1), 0), }); return {