From 3a1fff028b2de4be386cf2ee7eca12c225b53c45 Mon Sep 17 00:00:00 2001 From: wato787 Date: Thu, 27 Nov 2025 13:49:34 +0900 Subject: [PATCH 1/4] =?UTF-8?q?update=E3=81=AE=E3=83=AA=E3=82=AF=E3=82=A8?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=81=ABisDraft=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/createClient.ts | 3 +++ src/types.ts | 1 + tests/write.test.ts | 48 +++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/createClient.ts b/src/createClient.ts index c7bed10..36432ec 100644 --- a/src/createClient.ts +++ b/src/createClient.ts @@ -358,12 +358,14 @@ export const createClient = ({ endpoint, contentId, content, + isDraft = false, customRequestInit, }: UpdateRequest): Promise => { if (!endpoint) { return Promise.reject(new Error('endpoint is required')); } + const queries: MakeRequest['queries'] = isDraft ? { status: 'draft' } : {}; const requestInit: MakeRequest['requestInit'] = { ...customRequestInit, method: 'PATCH', @@ -376,6 +378,7 @@ export const createClient = ({ return makeRequest({ endpoint, contentId, + queries, requestInit, }); }; diff --git a/src/types.ts b/src/types.ts index ea97bfa..bbf3ae3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -159,6 +159,7 @@ export interface UpdateRequest { endpoint: string; contentId?: string; content: Partial; + isDraft?: boolean; customRequestInit?: CustomRequestInit; } diff --git a/tests/write.test.ts b/tests/write.test.ts index 82e9501..b11f98f 100644 --- a/tests/write.test.ts +++ b/tests/write.test.ts @@ -131,13 +131,17 @@ describe('update', () => { beforeEach(() => { server.use( http.patch(`${testBaseUrl}/list-type/foo`, async ({ request }) => { + const url = new URL(request.url); + const statusParams = url.searchParams.get('status'); const body = await request.json(); - patchListApiMockFn(body); + patchListApiMockFn(statusParams, body); return HttpResponse.json({ id: 'foo' }, { status: 200 }); }), http.patch(`${testBaseUrl}/object-type`, async ({ request }) => { + const url = new URL(request.url); + const statusParams = url.searchParams.get('status'); const body = await request.json(); - patchObjectApiMockFn(body); + patchObjectApiMockFn(statusParams, body); return HttpResponse.json({ id: 'foo' }, { status: 200 }); }), ); @@ -159,10 +163,29 @@ describe('update', () => { // Confirm PUT api was called expect(patchListApiMockFn).toHaveBeenCalledTimes(1); // Confirm that body is specified. - expect(patchListApiMockFn).toHaveBeenCalledWith({ + expect(patchListApiMockFn).toHaveBeenCalledWith(null, { + title: 'title', + }); + }); + + test('Draft list format content can be updated', async () => { + const data = await client.update({ + endpoint: 'list-type', + contentId: 'foo', + content: { + title: 'title', + }, + isDraft: true, + }); + expect(data).toEqual({ id: 'foo' }); + // Confirm PUT api was called + expect(patchListApiMockFn).toHaveBeenCalledTimes(1); + // Confirm that body is specified. + expect(patchListApiMockFn).toHaveBeenCalledWith('draft', { title: 'title', }); }); + test('Object type content can be updated', async () => { const data = await client.update({ endpoint: 'object-type', @@ -174,7 +197,24 @@ describe('update', () => { // Confirm PUT api was called expect(patchObjectApiMockFn).toHaveBeenCalledTimes(1); // Confirm that body is specified. - expect(patchObjectApiMockFn).toHaveBeenCalledWith({ + expect(patchObjectApiMockFn).toHaveBeenCalledWith(null, { + title: 'title', + }); + }); + + test('Draft object type content can be updated', async () => { + const data = await client.update({ + endpoint: 'object-type', + content: { + title: 'title', + }, + isDraft: true, + }); + expect(data).toEqual({ id: 'foo' }); + // Confirm PUT api was called + expect(patchObjectApiMockFn).toHaveBeenCalledTimes(1); + // Confirm that body is specified. + expect(patchObjectApiMockFn).toHaveBeenCalledWith('draft', { title: 'title', }); }); From b047944811b58eeb52404720b5ac8024a2309016 Mon Sep 17 00:00:00 2001 From: wato787 Date: Thu, 27 Nov 2025 13:59:10 +0900 Subject: [PATCH 2/4] =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/write.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/write.test.ts b/tests/write.test.ts index b11f98f..b0239b6 100644 --- a/tests/write.test.ts +++ b/tests/write.test.ts @@ -160,7 +160,7 @@ describe('update', () => { }, }); expect(data).toEqual({ id: 'foo' }); - // Confirm PUT api was called + // Confirm PATCH api was called expect(patchListApiMockFn).toHaveBeenCalledTimes(1); // Confirm that body is specified. expect(patchListApiMockFn).toHaveBeenCalledWith(null, { @@ -178,7 +178,7 @@ describe('update', () => { isDraft: true, }); expect(data).toEqual({ id: 'foo' }); - // Confirm PUT api was called + // Confirm PATCH api was called expect(patchListApiMockFn).toHaveBeenCalledTimes(1); // Confirm that body is specified. expect(patchListApiMockFn).toHaveBeenCalledWith('draft', { @@ -194,7 +194,7 @@ describe('update', () => { }, }); expect(data).toEqual({ id: 'foo' }); - // Confirm PUT api was called + // Confirm PATCH api was called expect(patchObjectApiMockFn).toHaveBeenCalledTimes(1); // Confirm that body is specified. expect(patchObjectApiMockFn).toHaveBeenCalledWith(null, { @@ -211,7 +211,7 @@ describe('update', () => { isDraft: true, }); expect(data).toEqual({ id: 'foo' }); - // Confirm PUT api was called + // Confirm PATCH api was called expect(patchObjectApiMockFn).toHaveBeenCalledTimes(1); // Confirm that body is specified. expect(patchObjectApiMockFn).toHaveBeenCalledWith('draft', { From 278e8046dfeb35c9481dd4b12eddd5b9b953c2fd Mon Sep 17 00:00:00 2001 From: wato787 Date: Fri, 28 Nov 2025 09:08:30 +0900 Subject: [PATCH 3/4] =?UTF-8?q?README:isDraft=E3=81=AB=E9=96=A2=E3=81=99?= =?UTF-8?q?=E3=82=8B=E8=A8=98=E8=BF=B0=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 22 ++++++++++++++++++---- README_jp.md | 22 ++++++++++++++++++---- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 406077b..5a0e84c 100644 --- a/README.md +++ b/README.md @@ -319,8 +319,6 @@ client title: 'title', body: 'body', }, - // Available with microCMS paid plans - // https://microcms.io/pricing isDraft: true, }) .then((res) => console.log(res.id)) @@ -340,8 +338,6 @@ client title: 'title', body: 'body', }, - // Available with microCMS paid plans - // https://microcms.io/pricing isDraft: true, }) .then((res) => console.log(res.id)) @@ -365,6 +361,24 @@ client .catch((err) => console.error(err)); ``` +#### Update content as draft + +By specifying the `isDraft` property, it is possible to update the content as a draft. + +```javascript +client + .update({ + endpoint: 'endpoint', + contentId: 'contentId', + content: { + title: 'title', + }, + isDraft: true, + }) + .then((res) => console.log(res.id)) + .catch((err) => console.error(err)); +``` + #### Update object format content When updating object content, use the `update` method without specifying a `contentId` property. diff --git a/README_jp.md b/README_jp.md index 608437e..fe1cc47 100644 --- a/README_jp.md +++ b/README_jp.md @@ -319,8 +319,6 @@ client title: 'タイトル', body: '本文', }, - // 有料プランから利用可能 - // https://microcms.io/pricing isDraft: true, }) .then((res) => console.log(res.id)) @@ -340,8 +338,6 @@ client title: 'タイトル', body: '本文', }, - // 有料プランから利用可能 - // https://microcms.io/pricing isDraft: true, }) .then((res) => console.log(res.id)) @@ -365,6 +361,24 @@ client .catch((err) => console.error(err)); ``` +#### コンテンツの下書き更新 + +`isDraft` プロパティを指定することで、コンテンツを下書き状態で更新することができます。 + +```javascript +client + .update({ + endpoint: 'endpoint', + contentId: 'contentId', + content: { + title: 'タイトル', + }, + isDraft: true, + }) + .then((res) => console.log(res.id)) + .catch((err) => console.error(err)); +``` + #### オブジェクト形式のコンテンツの編集 APIの型がオブジェクト形式のコンテンツを編集する場合は、`contentId`プロパティを使用せずに、エンドポイントのみを指定します。 From 7e952f7b0beb8ab3a33541a9deb4c903fbf475bc Mon Sep 17 00:00:00 2001 From: wato787 Date: Mon, 9 Feb 2026 13:42:58 +0900 Subject: [PATCH 4/4] Update version to 3.3.0 in package.json --- package-lock.json | 14 ++------------ package.json | 2 +- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8fe2ce1..b087e38 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "microcms-js-sdk", - "version": "3.2.0", + "version": "3.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "microcms-js-sdk", - "version": "3.2.0", + "version": "3.3.0", "license": "Apache-2.0", "dependencies": { "async-retry": "^1.3.3" @@ -152,7 +152,6 @@ "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.24.0.tgz", "integrity": "sha512-fQfkg0Gjkza3nf0c7/w6Xf34BW4YvzNfACRLmmb7XRLa6XHdR+K9AlJlxneFfWYf6uhOzuzZVTjF/8KfndZANw==", "dev": true, - "peer": true, "dependencies": { "@ampproject/remapping": "^2.2.0", "@babel/code-frame": "^7.23.5", @@ -2113,7 +2112,6 @@ "integrity": "sha512-uY2RSJcFPgNOEg12RQZL197LZX+MunGiKxsbxmh22VfVxrOYGRvh4mPANFlrD1yb38CgmW1wI6YgIi8LkIwmWg==", "dev": true, "hasInstallScript": true, - "peer": true, "dependencies": { "@swc/counter": "^0.1.2", "@swc/types": "^0.1.5" @@ -2497,7 +2495,6 @@ "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.2.0.tgz", "integrity": "sha512-mdekAHOqS9UjlmyF/LSs6AIEvfceV749GFxoBAjwAv0nkevfKHWQFDMcBZWUiIC5ft6ePWivXoS36aKQ0Cy3sw==", "dev": true, - "peer": true, "dependencies": { "@eslint-community/regexpp": "^4.5.1", "@typescript-eslint/scope-manager": "7.2.0", @@ -2533,7 +2530,6 @@ "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.2.0.tgz", "integrity": "sha512-5FKsVcHTk6TafQKQbuIVkXq58Fnbkd2wDL4LB7AURN7RUOu1utVP+G8+6u3ZhEroW3DF6hyo3ZEXxgKgp4KeCg==", "dev": true, - "peer": true, "dependencies": { "@typescript-eslint/scope-manager": "7.2.0", "@typescript-eslint/types": "7.2.0", @@ -2695,7 +2691,6 @@ "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz", "integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==", "dev": true, - "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -2992,7 +2987,6 @@ "url": "https://github.com/sponsors/ai" } ], - "peer": true, "dependencies": { "caniuse-lite": "^1.0.30001587", "electron-to-chromium": "^1.4.668", @@ -3461,7 +3455,6 @@ "integrity": "sha512-aARqgq8roFBj054KvQr5f1sFu0D65G+miZRCuJyJ0G13Zwx7vRar5Zhn2tkQNzIXcBrNVsv/8stehpj+GAjgbg==", "dev": true, "hasInstallScript": true, - "peer": true, "bin": { "esbuild": "bin/esbuild" }, @@ -3520,7 +3513,6 @@ "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.57.0.tgz", "integrity": "sha512-dZ6+mexnaTIbSBZWgou51U6OmzIhYM2VcNdtiTtI7qPNZm35Akpr0f6vtw3w1Kmn5PYo+tZVfh13WrhpS6oLqQ==", "dev": true, - "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.6.1", @@ -4565,7 +4557,6 @@ "resolved": "https://registry.npmjs.org/jest/-/jest-29.7.0.tgz", "integrity": "sha512-NIy3oAFp9shda19hy4HK0HRTWKtPJmGdnvywu01nOqNC2vZg+Z+fvJDxpMQA88eb2I9EcafcdjYgsDthnYTvGw==", "dev": true, - "peer": true, "dependencies": { "@jest/core": "^29.7.0", "@jest/types": "^29.6.3", @@ -6723,7 +6714,6 @@ "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.2.tgz", "integrity": "sha512-+2/g0Fds1ERlP6JsakQQDXjZdZMM+rqpamFZJEKh4kwTIn3iDkgKtby0CeNd5ATNZ4Ry1ax15TMx0W2V+miizQ==", "dev": true, - "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/package.json b/package.json index ede0c67..5efb005 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "microcms-js-sdk", - "version": "3.2.0", + "version": "3.3.0", "description": "JavaScript SDK Client for microCMS.", "engines": { "node": ">=18.0.0"