Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug(rest-api-client): adding new API getSpace #2578

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
74 changes: 74 additions & 0 deletions packages/rest-api-client/docs/space.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# 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.
- This method returns 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, including the name, body, attached apps, creator and updater information.

#### Parameters

| Name | Type | Required | Description |
| ---- | :-------------------: | :------: | ------------- |
| id | Number or<br />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. |

#### 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 { KintoneRestAPIError, KintoneAbortSearchError } 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 @@ -3,6 +3,7 @@ import { BulkRequestClient } from "./client/BulkRequestClient";
import { AppClient } from "./client/AppClient";
import { RecordClient } from "./client/RecordClient";
import { FileClient } from "./client/FileClient";
import { SpaceClient } from "./client/SpaceClient";
import { DefaultHttpClient } from "./http/";
import type { ProxyConfig } from "./http/HttpClientInterface";
import type { BasicAuth, DiscriminatedAuth } from "./types/auth";
Expand Down Expand Up @@ -64,6 +65,7 @@ export class KintoneRestAPIClient {
record: RecordClient;
app: AppClient;
file: FileClient;
space: SpaceClient;
private bulkRequest_: BulkRequestClient;
private baseUrl?: string;

Expand Down Expand Up @@ -94,6 +96,7 @@ export class KintoneRestAPIClient {
this.record = new RecordClient(httpClient, this.bulkRequest_, guestSpaceId);
this.app = new AppClient(httpClient, guestSpaceId);
this.file = new FileClient(httpClient, guestSpaceId);
this.space = new SpaceClient(httpClient, guestSpaceId);
}

public static get version() {
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,
});
}
}
55 changes: 55 additions & 0 deletions packages/rest-api-client/src/client/__tests__/SpaceClient.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import type { MockClient } from "../../http/MockClient";
import { buildMockClient } from "../../http/MockClient";
import { SpaceClient } from "../SpaceClient";
import { KintoneRequestConfigBuilder } from "../../KintoneRequestConfigBuilder";

const SPACE_ID = 1;

describe("SpaceClient", () => {
let mockClient: MockClient;
let spaceClient: SpaceClient;

beforeEach(() => {
const requestConfigBuilder = new KintoneRequestConfigBuilder({
baseUrl: "https://example.cybozu.com",
auth: { type: "apiToken", apiToken: "foo" },
});
mockClient = buildMockClient(requestConfigBuilder);
spaceClient = new SpaceClient(mockClient);
});

describe("getSpace", () => {
const params = {
id: SPACE_ID,
};
beforeEach(async () => {
await spaceClient.getSpace(params);
});
it("should pass the path to the http client", () => {
expect(mockClient.getLogs()[0].path).toBe("/k/v1/space.json");
});
it("should send a get request", () => {
expect(mockClient.getLogs()[0].method).toBe("get");
});
it("should pass id as a param to the http client", () => {
expect(mockClient.getLogs()[0].params).toEqual(params);
});
});
});

describe("SpaceClient with guestSpaceId", () => {
it("should pass the path to the http client", async () => {
const GUEST_SPACE_ID = 2;
const params = { id: GUEST_SPACE_ID };
const requestConfigBuilder = new KintoneRequestConfigBuilder({
baseUrl: "https://example.cybozu.com",
auth: { type: "session" },
});
const mockClient = buildMockClient(requestConfigBuilder);
const appClient = new SpaceClient(mockClient, GUEST_SPACE_ID);
await appClient.getSpace(params);
expect(mockClient.getLogs()[0].path).toBe(
`/k/guest/${GUEST_SPACE_ID}/v1/space.json`,
);
});
});
2 changes: 2 additions & 0 deletions packages/rest-api-client/src/client/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export type AppID = string | number;
export type RecordID = string | number;
export type SpaceID = string | number;
export type Revision = string | number;

export * from "./record";
export * from "./app";
export * from "./space";
21 changes: 21 additions & 0 deletions packages/rest-api-client/src/client/types/space/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { App } from "../app";

type AttachedApp = Omit<App, "spaceId">;

export type Space = {
id: string;
name: string;
defaultThread: string;
isPrivate: boolean;
creator: { code: string; name: string };
modifier: { code: string; name: string };
memberCount: string;
coverType: string;
coverKey: string;
coverUrl: string;
body: string;
useMultiThread: boolean;
isGuest: boolean;
attachedApps: AttachedApp[];
fixedMember: boolean;
};
Loading