From 8ecc4d155d2363b6f69ff4db294aeb20ee7e06f7 Mon Sep 17 00:00:00 2001 From: TakahikoKawakami <53943902+shabaraba@users.noreply.github.com> Date: Thu, 25 Jul 2024 13:27:18 +0900 Subject: [PATCH] feat(rest-api-client): update space.getSpace method (#2876) --- packages/rest-api-client/docs/space.md | 34 ++++++++++++++++++- .../rest-api-client/src/client/SpaceClient.ts | 10 +++++- .../src/client/__tests__/SpaceClient.test.ts | 32 ++++++++++++++++- .../src/client/types/space/index.ts | 24 +++++++++++++ 4 files changed, 97 insertions(+), 3 deletions(-) diff --git a/packages/rest-api-client/docs/space.md b/packages/rest-api-client/docs/space.md index b56cf7ef2c..3b2c6ac0f4 100644 --- a/packages/rest-api-client/docs/space.md +++ b/packages/rest-api-client/docs/space.md @@ -1,6 +1,7 @@ # Space - [getSpace](#getSpace) +- [updateSpace](#updateSpace) - [deleteSpace](#deleteSpace) - [updateSpaceBody](#updateSpaceBody) - [getSpaceMembers](#getSpaceMembers) @@ -64,7 +65,7 @@ Gets general information of a space. | body | String | The HTML of the Space body. | | useMultiThread | Boolean | The "Enable multiple threads." setting.
true: The Space is a Multi-threaded Space.
false: The Space is a Single-threaded Space. | | isGuest | Boolean | The Guest Space setting.
true: The Space is a Guest Space.
false: The Space is not a Guest Space. | -| attachedApps | Object | A list of Apps that are in the thread.
This does not include Apps that are not live yet. | +| attachedApps | Array | A list of Apps that are in the thread.
This does not include Apps that are not live yet. | | attachedApps[].threadId | String | The Thread ID of the thread that the App was created in.
Apps that are created inside Spaces using the GUI will be automatically allocated to the default Thread. | | attachedApps[].appId | String | The App ID. | | attachedApps[].code | String | The App Code of the App.
An empty string is returned if an App Code is not set in the App's settings. | @@ -84,11 +85,42 @@ Gets general information of a space. | showAppList | Boolean | The display status for the Apps widget.
true: The Apps widget is displayed.
false: The Apps widget is not displayed.
null is returned for Spaces with the Enable multiple threads option turned off. | | showMemberList | Boolean | The display status for the People widget.
true: The People widget is displayed.
false: The People widget is not displayed.
null is returned for Spaces with the Enable multiple threads option turned off. | | showRelatedLinkList | Boolean | The display status for the Related Apps & Spaces widget.
true: The Related Apps & Spaces widget is displayed.
false: The Related Apps & Spaces widget is not displayed.
null is returned for Spaces with the Enable multiple threads option turned off. | +| permissions | Object | An object containing information of the space's permission settings. | +| permissions.createApp | String | The option set for the Only Allow Space Administrators to Create Apps setting.
EVERYONE: all users can create Apps.
ADMIN: only administrators can create Apps. | #### Reference - https://kintone.dev/en/docs/kintone/rest-api/spaces/get-space/ +### updateSpace + +Updates the settings of a Space. + +#### Parameters + +| Name | Type | Required | Description | +| --------------------- | :--------------: | :------: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| id | Number or String | Yes | The space ID. | +| name | String | | The new name of the space. | +| isPrivate | Boolean | | The "Private" settings of the Space.
true: The Space is private.
false: The Space is not private. | +| fixedMember | Boolean | | The "Block users from joining or leaving the space and following or unfollowing the threads." setting.
true: Users cannot join/leave the Space or follow/unfollow threads.
false: Users can join/leave the Space and follow/unfollow threads. | +| useMultiThread | Boolean | | The Enable multiple threads setting.
true: The Space is a Multi-threaded Space.
If this parameter is ignored or false is specified, this parameter will not be updated. | +| showAnnouncement | Boolean | | The display status for the Announcement widget.
true: The Announcement widget is displayed.
false: The Announcement widget is not displayed. | +| showThreadList | Boolean | | The display status for the Threads widget.
true: The Threads widget is displayed.
false: The Threads widget is not displayed. | +| showAppList | Boolean | | The display status for the Apps widget.
true: The Apps widget is displayed.
false: The Apps widget is not displayed. | +| showMemberList | Boolean | | The display status for the People widget.
true: The People widget is displayed.
false: The People widget is not displayed. | +| showRelatedLinkList | Boolean | | The display status for the Related Apps & Spaces widget.
true: The Related Apps & Spaces widget is displayed.
false: The Related Apps & Spaces widget is not displayed. | +| permissions | Object | | An object containing information of the space's permission settings. | +| permissions.createApp | String | | The option set for the Only Allow Space Administrators to Create Apps setting.
EVERYONE: all users can create apps.
ADMIN: only administrators can create apps. | + +#### Returns + +An empty object. + +#### Reference + +- https://kintone.dev/en/docs/kintone/rest-api/spaces/update-space/ + ### deleteSpace Deletes a space. diff --git a/packages/rest-api-client/src/client/SpaceClient.ts b/packages/rest-api-client/src/client/SpaceClient.ts index 2e8c6e25e0..085c6cf961 100644 --- a/packages/rest-api-client/src/client/SpaceClient.ts +++ b/packages/rest-api-client/src/client/SpaceClient.ts @@ -1,13 +1,14 @@ import type { SpaceID, ThreadID, - Space, ThreadComment, SpaceMemberForResponse, SpaceMemberForRequest, GuestSpaceID, Guest, SpaceTemplateID, + UpdateSpaceForRequest, + Space, } from "./types"; import { BaseClient } from "./BaseClient"; @@ -19,6 +20,13 @@ export class SpaceClient extends BaseClient { return this.client.get(path, params); } + public updateSpace(params: UpdateSpaceForRequest): Promise<{}> { + const path = this.buildPathWithGuestSpaceId({ + endpointName: "space", + }); + return this.client.put(path, params); + } + public deleteSpace(params: { id: SpaceID }): Promise<{}> { const path = this.buildPathWithGuestSpaceId({ endpointName: "space", diff --git a/packages/rest-api-client/src/client/__tests__/SpaceClient.test.ts b/packages/rest-api-client/src/client/__tests__/SpaceClient.test.ts index ad855c8c4a..b23cca0f0e 100644 --- a/packages/rest-api-client/src/client/__tests__/SpaceClient.test.ts +++ b/packages/rest-api-client/src/client/__tests__/SpaceClient.test.ts @@ -2,7 +2,7 @@ import type { MockClient } from "../../http/MockClient"; import { buildMockClient } from "../../http/MockClient"; import { SpaceClient } from "../SpaceClient"; import { KintoneRequestConfigBuilder } from "../../KintoneRequestConfigBuilder"; -import type { ThreadComment } from "../types"; +import type { ThreadComment, UpdateSpaceForRequest } from "../types"; const SPACE_ID = 1; const SPACE_TEMPLATE_ID = 1; @@ -39,6 +39,36 @@ describe("SpaceClient", () => { }); }); + describe("updateSpace", () => { + const params = { + id: SPACE_ID, + name: "updated", + isPrivate: false, + useMultiThread: false, + fixedMember: false, + showAnnouncement: false, + showThreadList: false, + showAppList: false, + showMemberList: false, + showRelatedLinkList: false, + permissions: { + createApp: "EVERYONE", + }, + } as UpdateSpaceForRequest; + beforeEach(async () => { + await spaceClient.updateSpace(params); + }); + it("should pass the path to the http client", () => { + expect(mockClient.getLogs()[0].path).toBe("/k/v1/space.json"); + }); + it("should send a PUT request", () => { + expect(mockClient.getLogs()[0].method).toBe("put"); + }); + it("should pass params to the http client", () => { + expect(mockClient.getLogs()[0].params).toEqual(params); + }); + }); + describe("deleteSpace", () => { const params = { id: SPACE_ID, diff --git a/packages/rest-api-client/src/client/types/space/index.ts b/packages/rest-api-client/src/client/types/space/index.ts index 3b4ff3b43e..28203f0e0f 100644 --- a/packages/rest-api-client/src/client/types/space/index.ts +++ b/packages/rest-api-client/src/client/types/space/index.ts @@ -15,6 +15,10 @@ type AttachedApp = Pick< | "modifier" >; +type Permissions = { + createApp: "EVERYONE" | "ADMIN"; +}; + export type Space = { id: string; name: string; @@ -31,6 +35,26 @@ export type Space = { isGuest: boolean; attachedApps: AttachedApp[]; fixedMember: boolean; + showAnnouncement: boolean | null; + showThreadList: boolean | null; + showAppList: boolean | null; + showMemberList: boolean | null; + showRelatedLinkList: boolean | null; + permissions: Permissions; +}; + +export type UpdateSpaceForRequest = { + id: SpaceID; + name?: string; + isPrivate?: boolean; + useMultiThread?: boolean; + fixedMember?: boolean; + showAnnouncement?: boolean; + showThreadList?: boolean; + showAppList?: boolean; + showMemberList?: boolean; + showRelatedLinkList?: boolean; + permissions?: Permissions; }; export type SpaceMemberForResponse = {