From 056dbb3a94c3ac40f9ab5686d8184f1394f27a64 Mon Sep 17 00:00:00 2001 From: "K.Utsunomiya" Date: Thu, 9 Apr 2026 14:20:42 +0900 Subject: [PATCH 1/3] feat: Enhance createClient to support isClosed flag and validate isDraft and isClosed combination. --- src/createClient.ts | 16 ++++++++- src/types.ts | 1 + tests/createClient.test.ts | 73 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 1 deletion(-) diff --git a/src/createClient.ts b/src/createClient.ts index 36432ec..ddbbdb4 100644 --- a/src/createClient.ts +++ b/src/createClient.ts @@ -327,13 +327,27 @@ export const createClient = ({ contentId, content, isDraft = false, + isClosed = false, customRequestInit, }: CreateRequest): Promise => { if (!endpoint) { return Promise.reject(new Error('endpoint is required')); } - const queries: MakeRequest['queries'] = isDraft ? { status: 'draft' } : {}; + // if `isClosed` and `isDraft` are true, return an error + if (isClosed && isDraft) { + return Promise.reject( + new Error('isClosed and isDraft cannot be true at the same time'), + ); + } + + const queries: MakeRequest['queries'] = {}; + if (isDraft) { + queries.status = 'draft'; + } else if (isClosed) { + queries.status = 'closed'; + } + const requestInit: MakeRequest['requestInit'] = { ...customRequestInit, method: contentId ? 'PUT' : 'POST', diff --git a/src/types.ts b/src/types.ts index bbf3ae3..f6ff71f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -152,6 +152,7 @@ export interface CreateRequest { contentId?: string; content: T; isDraft?: boolean; + isClosed?: boolean; customRequestInit?: CustomRequestInit; } diff --git a/tests/createClient.test.ts b/tests/createClient.test.ts index 39db356..e3b0a87 100644 --- a/tests/createClient.test.ts +++ b/tests/createClient.test.ts @@ -239,4 +239,77 @@ describe('createClient', () => { expect(apiCallCount).toBe(1); }, 30000); }); + + describe('create', () => { + const client = createClient({ + serviceDomain: 'serviceDomain', + apiKey: 'apiKey', + }); + + test('Rejects when `isDraft` and `isClosed` are both true', () => { + return expect( + client.create({ + endpoint: 'list-type', + content: { title: 'test' }, + isDraft: true, + isClosed: true, + }), + ).rejects.toThrow( + new Error('isClosed and isDraft cannot be true at the same time'), + ); + }); + + test('Sends `status=draft` when only `isDraft` is true', async () => { + let requestUrl = ''; + server.use( + http.post(`${testBaseUrl}/list-type`, ({ request }) => { + requestUrl = request.url; + return HttpResponse.json({ id: 'foo' }); + }), + ); + + await client.create({ + endpoint: 'list-type', + content: { title: 'test' }, + isDraft: true, + }); + + expect(new URL(requestUrl).searchParams.get('status')).toBe('draft'); + }); + + test('Sends `status=closed` when only `isClosed` is true', async () => { + let requestUrl = ''; + server.use( + http.post(`${testBaseUrl}/list-type`, ({ request }) => { + requestUrl = request.url; + return HttpResponse.json({ id: 'foo' }); + }), + ); + + await client.create({ + endpoint: 'list-type', + content: { title: 'test' }, + isClosed: true, + }); + + expect(new URL(requestUrl).searchParams.get('status')).toBe('closed'); + }); + + test('Does not send `status` when both `isDraft` and `isClosed` are false', async () => { + let requestUrl = ''; + server.use( + http.post(`${testBaseUrl}/list-type`, ({ request }) => { + requestUrl = request.url; + return HttpResponse.json({ id: 'foo' }); + }), + ); + + await client.create({ + endpoint: 'list-type', + content: { title: 'test' }, + }); + + expect(new URL(requestUrl).searchParams.get('status')).toBeNull(); + }); + }); }); From 757a327864db3120b76f94c45201d3fbbf65f8e8 Mon Sep 17 00:00:00 2001 From: "K.Utsunomiya" Date: Thu, 9 Apr 2026 15:09:34 +0900 Subject: [PATCH 2/3] docs: Add examples for creating closed content --- README.md | 37 +++++++++++++++++++++++++++++++++++++ README_jp.md | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/README.md b/README.md index 5a0e84c..b9b8cd1 100644 --- a/README.md +++ b/README.md @@ -344,6 +344,43 @@ client .catch((err) => console.error(err)); ``` +#### Create closed content + +By specifying the `isClosed` property, the content can be registered as archived. + +```javascript +client + .create({ + endpoint: 'endpoint', + content: { + title: 'title', + body: 'body', + }, + isClosed: true, + }) + .then((res) => console.log(res.id)) + .catch((err) => console.error(err)); +``` + +#### Create closed content with specified ID + +By specifying the `contentId` and `isClosed` properties, the content can be registered as archived with a specified ID. + +```javascript +client + .create({ + endpoint: 'endpoint', + contentId: 'contentId', + content: { + title: 'title', + body: 'body', + }, + isClosed: true, + }) + .then((res) => console.log(res.id)) + .catch((err) => console.error(err)); +``` + ### Update content The `update` method is used to update a single content specified by its ID. diff --git a/README_jp.md b/README_jp.md index fe1cc47..78426c1 100644 --- a/README_jp.md +++ b/README_jp.md @@ -344,6 +344,43 @@ client .catch((err) => console.error(err)); ``` +#### 公開終了のステータスでコンテンツを登録 + +`isClosed`プロパティを使用することで、公開終了のステータスでコンテンツを登録できます。 + +```javascript +client + .create({ + endpoint: 'endpoint', + content: { + title: 'タイトル', + body: '本文', + }, + isClosed: true, + }) + .then((res) => console.log(res.id)) + .catch((err) => console.error(err)); +``` + +#### 指定されたIDかつ公開終了のステータスでコンテンツを登録 + +`contentId`プロパティと`isClosed`プロパティを使用することで、指定されたIDかつ公開終了のステータスでコンテンツを登録できます。 + +```javascript +client + .create({ + endpoint: 'endpoint', + contentId: 'contentId', + content: { + title: 'タイトル', + body: '本文', + }, + isClosed: true, + }) + .then((res) => console.log(res.id)) + .catch((err) => console.error(err)); +``` + ### コンテンツの編集 `update`メソッドは特定のコンテンツを編集するために使用します。 From e8cc3c6fb3a8b0a95189e55f3ad89bb2dc99746c Mon Sep 17 00:00:00 2001 From: "K.Utsunomiya" Date: Mon, 13 Apr 2026 12:06:12 +0900 Subject: [PATCH 3/3] docs: Clarify mutual exclusivity of isDraft and isClosed in README --- README.md | 4 +++- README_jp.md | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b9b8cd1..b2579c2 100644 --- a/README.md +++ b/README.md @@ -348,6 +348,8 @@ client By specifying the `isClosed` property, the content can be registered as archived. +> **Note:** `isDraft` and `isClosed` are mutually exclusive. Do not pass both as `true`; the SDK rejects that combination at runtime with an error. When using `isClosed: true`, omit `isDraft` or set it to `false` (the default). + ```javascript client .create({ @@ -364,7 +366,7 @@ client #### Create closed content with specified ID -By specifying the `contentId` and `isClosed` properties, the content can be registered as archived with a specified ID. +By specifying the `contentId` and `isClosed` properties, the content can be registered as archived with a specified ID. The same rule applies as above: `isDraft` and `isClosed` cannot both be `true`. ```javascript client diff --git a/README_jp.md b/README_jp.md index 78426c1..f0953c3 100644 --- a/README_jp.md +++ b/README_jp.md @@ -348,6 +348,8 @@ client `isClosed`プロパティを使用することで、公開終了のステータスでコンテンツを登録できます。 +> **注:** `isDraft` と `isClosed` は同時に `true` にできません。両方を `true` で渡すと、SDK はランタイムでエラーとして拒否します。`isClosed: true` を使う場合は、`isDraft` を省略、または `false` を設定してください。 + ```javascript client .create({ @@ -364,7 +366,7 @@ client #### 指定されたIDかつ公開終了のステータスでコンテンツを登録 -`contentId`プロパティと`isClosed`プロパティを使用することで、指定されたIDかつ公開終了のステータスでコンテンツを登録できます。 +`contentId`プロパティと`isClosed`プロパティを使用することで、指定されたIDかつ公開終了のステータスでコンテンツを登録できます。上記と同様、`isDraft` と `isClosed` を同時に `true` にすることはできません。 ```javascript client