Skip to content

Commit

Permalink
Support listing content by status. (#32)
Browse files Browse the repository at this point in the history
* Support listing content by status.

* Update version.

* Filter tests to just the cortex we created.

* Fix test.
  • Loading branch information
jmoseley authored Jul 23, 2024
1 parent 9305641 commit ce05731
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
3 changes: 2 additions & 1 deletion client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Catalog, CatalogConfig } from "./catalog.js";
import { OrgConfigOpts, OrgConfig } from "./org.js";
import { CortexApiClient } from "./api-client.js";
import { Chat, StreamingChatResult } from "./chat.js";
import { Content, StreamingContentResult } from "./content.js";
import { Content, ContentStatus, StreamingContentResult } from "./content.js";
import { Readable } from "stream";

export type CortexClientArgs = {
Expand Down Expand Up @@ -49,6 +49,7 @@ export interface ClientListContentOpts {
cursor?: string;
userEmail?: string | null;
cortexName?: string;
status?: ContentStatus;
}
export interface ClientListChatOpts {
pageSize?: number;
Expand Down
32 changes: 32 additions & 0 deletions content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,24 +280,56 @@ test(`test content status and publishing`, { timeout: 180000 }, async () => {

expect(content.status).toBe(ContentStatus.Draft);

const draftContent = await testClient.listContent({
cortexName: cortex.name,
status: ContentStatus.Draft,
});
expect(draftContent.content.length).toBe(1);

await content.setStatus(ContentStatus.InReview);

expect(content.status).toBe(ContentStatus.InReview);

const inReviewContent = await testClient.listContent({
cortexName: cortex.name,
status: ContentStatus.InReview,
});
expect(inReviewContent.content.length).toBe(1);

await content.setStatus(ContentStatus.Approved);

expect(content.status).toBe(ContentStatus.Approved);

const approvedContent = await testClient.listContent({
cortexName: cortex.name,
status: ContentStatus.Approved,
});
expect(approvedContent.content.length).toBe(1);

await content.publish();

expect(content.status).toBe(ContentStatus.Published);
expect(content.publishedVersion).toBe(0);

const publishedContent = await testClient.listContent({
cortexName: cortex.name,
status: ContentStatus.Published,
});
expect(publishedContent.content.length).toBe(1);

await content.unpublish();
expect(content.status).toBe(ContentStatus.Draft);
expect(content.publishedVersion).toBe(undefined);

const publishedContent2 = await testClient.listContent({
cortexName: cortex.name,
status: ContentStatus.Published,
});
expect(publishedContent2.content.length).toBe(0);

await content.publish();
expect(content.status).toBe(ContentStatus.Published);
expect(content.publishedVersion).toBe(0);

await cortex.delete();
});
4 changes: 4 additions & 0 deletions content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export type ContentListOptions = {
pageSize?: number;
userEmail?: string | null;
cortexName?: string;
status?: ContentStatus;
};

export type ContentMetadata = {
Expand Down Expand Up @@ -443,6 +444,9 @@ export class Content {
if (opts?.cortexName) {
query.set("cortexName", opts.cortexName);
}
if (opts?.status) {
query.set("status", opts.status);
}
query.set("pageSize", (opts?.pageSize || 50).toString());
const res = await client.GET(`/content?${query.toString()}`);
if (res.status !== 200) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"url": "https://github.com/cortexclick/cortex-sdk",
"type": "git"
},
"version": "0.0.5",
"version": "0.0.6",
"type": "module",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit ce05731

Please sign in to comment.