diff --git a/client.ts b/client.ts index 306aed2..1cb7190 100644 --- a/client.ts +++ b/client.ts @@ -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 = { @@ -49,6 +49,7 @@ export interface ClientListContentOpts { cursor?: string; userEmail?: string | null; cortexName?: string; + status?: ContentStatus; } export interface ClientListChatOpts { pageSize?: number; diff --git a/content.test.ts b/content.test.ts index 858db71..82efd52 100644 --- a/content.test.ts +++ b/content.test.ts @@ -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(); }); diff --git a/content.ts b/content.ts index 9758b97..6b1a562 100644 --- a/content.ts +++ b/content.ts @@ -87,6 +87,7 @@ export type ContentListOptions = { pageSize?: number; userEmail?: string | null; cortexName?: string; + status?: ContentStatus; }; export type ContentMetadata = { @@ -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) { diff --git a/package.json b/package.json index 504dec2..dee6f39 100644 --- a/package.json +++ b/package.json @@ -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": {