Skip to content

Commit

Permalink
feat(rest-api-client): add space.getSpace() method (#2582)
Browse files Browse the repository at this point in the history
Co-authored-by: tasshi / Masaharu Tashiro <33759872+tasshi-me@users.noreply.github.com>
  • Loading branch information
tuanphamcybozu and tasshi-me authored Feb 26, 2024
1 parent d2d39bc commit e417752
Show file tree
Hide file tree
Showing 11 changed files with 230 additions and 3 deletions.
2 changes: 2 additions & 0 deletions examples/rest-api-client-demo/src/run-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { KintoneRestAPIClient } from "@kintone/rest-api-client";
import { Record } from "./record";
import { App } from "./app";
import { File } from "./file";
import { Space } from "./space";

declare const window: {
KintoneRestAPIClientDemo: any;
Expand All @@ -18,5 +19,6 @@ const client = new KintoneRestAPIClient({
window.KintoneRestAPIClientDemo = {
record: new Record(client),
app: new App(client),
space: new Space(client),
file: new File(client),
};
10 changes: 10 additions & 0 deletions examples/rest-api-client-demo/src/run-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { loadProfile } from "@kintone/profile-loader";
import yargs from "yargs";
import { Record } from "./record";
import { App } from "./app";
import { Space } from "./space";
import { File } from "./file";
import { BulkRequest } from "./bulkRequest";

Expand Down Expand Up @@ -60,6 +61,15 @@ yargs
new Record(buildClient(argv))[argv.method]();
},
)
.command(
"space [method]",
"run script for SpaceClient",
prepareMethod,
(argv: any) => {
// @ts-ignore
new Space(buildClient(argv))[argv.method]();
},
)
.command(
"file [method]",
"run script for FileClient",
Expand Down
17 changes: 17 additions & 0 deletions examples/rest-api-client-demo/src/space.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { KintoneRestAPIClient } from "@kintone/rest-api-client";

const SPACE_ID = 8;

export class Space {
private client: KintoneRestAPIClient;
constructor(client: KintoneRestAPIClient) {
this.client = client;
}
public async getSpace() {
try {
console.log(await this.client.space.getSpace({ id: SPACE_ID }));
} catch (error) {
console.log(error);
}
}
}
1 change: 1 addition & 0 deletions packages/rest-api-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ See [TypeScript Definitions](https://github.com/kintone/js-sdk/tree/master/packa

- [Record](https://github.com/kintone/js-sdk/tree/master/packages/rest-api-client/docs/record.md)
- [App](https://github.com/kintone/js-sdk/tree/master/packages/rest-api-client/docs/app.md)
- [Space](https://github.com/kintone/js-sdk/tree/master/packages/rest-api-client/docs/space.md)
- [File](https://github.com/kintone/js-sdk/tree/master/packages/rest-api-client/docs/file.md)
- [BulkRequest](https://github.com/kintone/js-sdk/tree/master/packages/rest-api-client/docs/bulkRequest.md)

Expand Down
79 changes: 79 additions & 0 deletions packages/rest-api-client/docs/space.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Space

- [getSpace](#getSpace)

## Overview

```ts
const client = new KintoneRestAPIClient();

(async () => {
try {
console.log(await client.space.getSpace({ id: "1" }));
} catch (error) {
console.log(error);
}
})();
```

- All methods are defined on the `space` property.
- All methods return a Promise object that is resolved with an object having properties in each `Returns` section.
- If the Space or Guest Space feature is turned off, an error will be returned.

## Methods

### getSpace

Gets general information of a space.

#### Parameters

| Name | Type | Required | Description |
| ---- | :--------------: | :------: | ------------- |
| id | Number or String | Yes | The space ID. |

#### Returns

| Name | Type | Description |
| ---------------------------- | :-----: | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| id | String | The space ID. |
| name | String | The name of the space. |
| defaultThread | String | The Thread ID of the default thread that was created when the Space was made. |
| isPrivate | Boolean | The "Private" settings of the Space.<br /><strong>true</strong>: The Space is private.<br /><strong>false</strong>: The Space is not private. |
| creator | Object | The information of the user who created the space. |
| creator.code | String | The login name of the creator.<br />An empty string is returned for inactive users and deleted users. |
| creator.name | String | The display name of the creator.<br />An empty string is returned for inactive users and deleted users. |
| modifier | Object | The information of the user who last modified the space. |
| modifier.code | String | The login name of the modifier.<br />An empty string is returned for inactive users and deleted users. |
| modifier.name | String | The display name of the modifier.<br />An empty string is returned for inactive users and deleted users. |
| memberCount | String | The number of members of the Space. |
| coverType | String | The image type of the Cover Photo.<br /><strong>BLOB</strong>: An uploaded image.<br /><strong>PRESET</strong>: A preset image. |
| coverKey | String | The key of the Cover Photo. |
| coverUrl | String | The URL of the Cover Photo. |
| body | String | The HTML of the Space body. |
| useMultiThread | Boolean | The "Enable multiple threads." setting.<br /><strong>true</strong>: The Space is a Multi-threaded Space.<br /><strong>false</strong>: The Space is a Single-threaded Space. |
| isGuest | Boolean | The Guest Space setting.<br /><strong>true</strong>: The Space is a Guest Space.<br /><strong>false</strong>: The Space is not a Guest Space. |
| attachedApps | Object | A list of Apps that are in the thread.<br />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.<br />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.<br />An empty string is returned if an App Code is not set in the App's settings. |
| attachedApps[].name | String | The name of the App.<br />If the App has localization settings, the localized name will be returned. |
| attachedApps[].description | String | The description of the App.<br />If the App has localization settings, the localized description will be returned. |
| attachedApps[].createdAt | String | The date of when the App was created. |
| attachedApps[].creator | Object | The information of the user who created the App. |
| attachedApps[].creator.code | String | The log in name of the creator.<br />An empty string is returned for inactive users and deleted users. |
| attachedApps[].creator.name | String | The display name of the creator.<br />An empty string is returned for inactive users and deleted users. |
| attachedApps[].modifiedAt | String | The date of when the app was last modified. |
| attachedApps[].modifier | Object | The information of the user who last updated the app. |
| attachedApps[].modifier.code | String | The login name of the last updater. An empty string is returned for inactive users and deleted users. |
| attachedApps[].modifier.name | String | The display name of the last updater. An empty string is returned for inactive users and deleted users. |
| fixedMember | Boolean | The "Block users from joining or leaving the space and following or unfollowing the threads." setting.<br /><strong>true</strong>: Users cannot join/leave the Space or follow/unfollow threads.<br /><strong>false</strong>: Users can join/leave the Space and follow/unfollow threads. |
| showAnnouncement | Boolean | Display status of "Announcement" for portals of spaces with "Enable multiple threads. Note: This setting cannot be reverted." enabled<br /><strong>true</strong>: display<br /><strong>false</strong>: not displayed<br />For spaces/guest spaces that use only one thread, "null" is returned. |
| showThreadList | Boolean | Display status of "Threads" for portals of spaces with "Enable multiple threads. Note: This setting cannot be reverted." enabled<br /><strong>true</strong>: display<br /><strong>false</strong>: not displayed<br />For spaces/guest spaces that use only one thread, "null" is returned. |
| showAppList | Boolean | Display status of "Apps" for portals of spaces with "Enable multiple threads. Note: This setting cannot be reverted." enabled<br /><strong>true</strong>: display<br /><strong>false</strong>: not displayed<br />For spaces/guest spaces that use only one thread, "null" is returned. |
| showMemberList | Boolean | Display status of "People" for portals of spaces with "Enable multiple threads. Note: This setting cannot be reverted." enabled<br /><strong>true</strong>: display<br /><strong>false</strong>: not displayed<br />For spaces/guest spaces that use only one thread, "null" is returned. |
| showRelatedLinkList | Boolean | Display status of "Related Apps & Spaces" for portals of spaces with "Enable multiple threads. Note: This setting cannot be reverted." enabled<br /><strong>true</strong>: display<br /><strong>false</strong>: not displayed<br />For spaces/guest spaces that use only one thread, "null" is returned. |

#### Reference

- https://kintone.dev/en/docs/kintone/rest-api/spaces/get-space/
5 changes: 2 additions & 3 deletions packages/rest-api-client/src/KintoneResponseHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import type {
Response,
ResponseHandler,
} from "./http/HttpClientInterface";
import { KintoneAbortSearchError } from "./error/KintoneAbortSearchError";
import type { KintoneErrorResponse } from "./error/KintoneRestAPIError";
import { KintoneRestAPIError } from "./error/KintoneRestAPIError";
import { KintoneAbortSearchError, KintoneRestAPIError } from "./error";
import type { KintoneErrorResponse } from "./error";

export class KintoneResponseHandler implements ResponseHandler {
private enableAbortSearchError: boolean;
Expand Down
3 changes: 3 additions & 0 deletions packages/rest-api-client/src/KintoneRestAPIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { EndpointName } from "./client/BulkRequestClient";
import { BulkRequestClient } from "./client/BulkRequestClient";
import { AppClient } from "./client/AppClient";
import { RecordClient } from "./client/RecordClient";
import { SpaceClient } from "./client/SpaceClient";
import { FileClient } from "./client/FileClient";
import { DefaultHttpClient } from "./http/";
import type { ProxyConfig } from "./http/HttpClientInterface";
Expand Down Expand Up @@ -63,6 +64,7 @@ const buildDiscriminatedAuth = (auth: Auth): DiscriminatedAuth => {
export class KintoneRestAPIClient {
record: RecordClient;
app: AppClient;
space: SpaceClient;
file: FileClient;
private bulkRequest_: BulkRequestClient;
private baseUrl?: string;
Expand Down Expand Up @@ -93,6 +95,7 @@ export class KintoneRestAPIClient {
this.bulkRequest_ = new BulkRequestClient(httpClient, guestSpaceId);
this.record = new RecordClient(httpClient, this.bulkRequest_, guestSpaceId);
this.app = new AppClient(httpClient, guestSpaceId);
this.space = new SpaceClient(httpClient, guestSpaceId);
this.file = new FileClient(httpClient, guestSpaceId);
}

Expand Down
27 changes: 27 additions & 0 deletions packages/rest-api-client/src/client/SpaceClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { HttpClient } from "../http";
import { buildPath } from "../url";
import type { SpaceID, Space } from "./types";

export class SpaceClient {
private client: HttpClient;
private readonly guestSpaceId?: number | string;

constructor(client: HttpClient, guestSpaceId?: number | string) {
this.client = client;
this.guestSpaceId = guestSpaceId;
}

public getSpace(params: { id: SpaceID }): Promise<Space> {
const path = this.buildPathWithGuestSpaceId({
endpointName: "space",
});
return this.client.get(path, params);
}

private buildPathWithGuestSpaceId(params: { endpointName: string }) {
return buildPath({
...params,
guestSpaceId: this.guestSpaceId,
});
}
}
Loading

0 comments on commit e417752

Please sign in to comment.