Skip to content

Commit

Permalink
fix: Content pieces API accept ID list
Browse files Browse the repository at this point in the history
  • Loading branch information
areknawo committed Jul 7, 2024
1 parent 8dc418b commit 517ad0d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 16 deletions.
5 changes: 4 additions & 1 deletion packages/backend/src/lib/mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { z } from "zod";
type UnderscoreID<T extends Record<string, any>> = Omit<T, "id"> & { _id: T["id"] };

const zodId = (): z.ZodString => z.string().regex(/^[a-f\d]{24}$/i, "invalid id");
const zodIdList = (): z.ZodString => {
return z.string().regex(/^[a-f\d]{24}(,[a-f\d]{24})*$/i, "invalid id list");
};

export { zodId };
export { zodId, zodIdList };
export type { UnderscoreID };
4 changes: 2 additions & 2 deletions packages/backend/src/routes/content-pieces/handlers/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
getContentVariantsCollection
} from "#collections";
import { AuthenticatedContext } from "#lib/middleware";
import { zodId } from "#lib/mongo";
import { zodId, zodIdList } from "#lib/mongo";
import {
fetchEntryMembers,
fetchContentPieceTags,
Expand All @@ -22,7 +22,7 @@ import { DocJSON, bufferToJSON } from "#lib/content-processing";

const inputSchema = z.object({
content: z.boolean().describe("Whether to fetch the JSON content").default(false),
contentGroupId: zodId()
contentGroupId: zodIdList()
.describe("Comma-separated list of IDs of the content groups which contain the content pieces")
.optional(),
variant: zodId()
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/javascript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vrite/sdk",
"version": "0.4.8",
"version": "0.4.9",
"private": false,
"description": "JavaScript SDK and API client for Vrite - open-source developer content platform",
"license": "MIT",
Expand Down
29 changes: 18 additions & 11 deletions packages/sdk/javascript/src/api/content-pieces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ interface ContentPiecesEndpoints {
>(
input: PaginationParams & {
content?: IncludeContent;
contentGroupId: string;
contentGroupId: string | string[];
tagId?: string;
slug?: string;
variant?: string;
Expand Down Expand Up @@ -200,19 +200,26 @@ const createContentPiecesEndpoints = (sendRequest: SendRequest): ContentPiecesEn
list: <
CustomData extends Record<string, any> = Record<string, any>,
IncludeContent extends true | false = false
>(
input: PaginationParams & {
content?: IncludeContent;
contentGroupId: string;
tagId?: string;
slug?: string;
variant?: string;
}
) => {
>({
contentGroupId,
...input
}: PaginationParams & {
content?: IncludeContent;
contentGroupId: string | string[];
tagId?: string;
slug?: string;
variant?: string;
}) => {
return sendRequest<Array<ContentPieceWithAdditionalData<CustomData, IncludeContent>>>(
"GET",
`${basePath}/list`,
{ params: input }
{
params: {
...input,
contentGroupId:
typeof contentGroupId === "string" ? contentGroupId : contentGroupId.join(",")
}
}
);
}
});
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/javascript/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { createClient } from "./client";
export type { Client, SearchResult } from "./client";
export type { ContentGroup } from "./content-groups";
export type { ContentGroup, ContentGroupWithSubtree } from "./content-groups";
export type {
ContentPiece,
ContentPieceWithAdditionalData,
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/javascript/src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ declare module "virtual:vrite/client" {
BadRequestError,
Client,
ContentGroup,
ContentGroupWithSubtree,
ContentPiece,
ContentPieceWithAdditionalData,
JSONContent,
Expand Down

0 comments on commit 517ad0d

Please sign in to comment.