Skip to content

Commit

Permalink
fix: docsv2 distinct by domain (#1056)
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity authored Jun 20, 2024
1 parent 50b220a commit 428b352
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 102 deletions.
35 changes: 20 additions & 15 deletions fern/apis/fdr/definition/docs/v2/read/__package__.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ service:
- DomainNotRegisteredError
- rootCommons.UnauthorizedError

listAllDocsUrls:
method: GET
auth: true
path: /urls/list
request:
name: ListAllDocsUrlsRequest
query-parameters:
page: optional<integer>
limit: optional<integer>
custom:
type: optional<boolean>
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}
Expand All @@ -73,21 +93,6 @@ service:
errors:
- IndexSegmentNotFoundError

listAllDocsUrls:
auth: true
method: GET
path: /urls
request:
name: ListAllDocsUrlsRequest
query-parameters:
page: optional<integer>
limit: optional<integer>
response: ListAllDocsUrlsResponse
docs: Returns a list of all public docs.
# pagination:
# offset: $request.page
# results: $response.urls

types:
GetDocsConfigByIdResponse:
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string | string[] | object | object[]> = {};
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: {
Expand All @@ -228,151 +246,148 @@ 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,
});
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",
"X-Fern-Runtime": core.RUNTIME.type,
"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,
});
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<string, string | string[] | object | object[]> = {};
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",
"X-Fern-Runtime": core.RUNTIME.type,
"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,
});
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),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
@@ -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";
16 changes: 16 additions & 0 deletions servers/fdr/src/__test__/local/services/docs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Loading

0 comments on commit 428b352

Please sign in to comment.