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

feat(rest-api-client): add space.addGuests() method #2622

Merged
merged 16 commits into from
Mar 19, 2024
Merged
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
22 changes: 22 additions & 0 deletions examples/rest-api-client-demo/src/space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,26 @@ export class Space {
console.log(error);
}
}

public async addGuests() {
const guests = [
{
code: "guest1@example.com",
password: "password123",
timezone: "America/Los_Angeles",
locale: "en" as const,
image: "78a586f2-e73e-4a70-bec2-43976a60746e", // replace with the fileKey of the uploaded file
name: "John Doe",
company: "Company Name",
division: "Sales",
phone: "999-456-7890",
callto: "skypecallto",
},
];
try {
console.log(await this.client.space.addGuests({ guests }));
} catch (error) {
console.log(error);
}
}
}
33 changes: 33 additions & 0 deletions packages/rest-api-client/docs/space.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [updateSpaceMembers](#updateSpaceMembers)
- [updateThread](#updateThread)
- [addThreadComment](#addThreadComment)
- [addGuests](#addGuests)

## Overview

Expand Down Expand Up @@ -219,3 +220,35 @@ Adds a comment to a Thread of a Space.
#### Reference

- https://kintone.dev/en/docs/kintone/rest-api/spaces/add-thread-comment/

### addGuests

Adds Guest users to Kintone.<br>
This does not affiliate Guest users with any Guest Spaces, and does not send any invitation emails.<br>
To affiliate a Guest user with a Guest Space, use the Update Guest Members API.<br>

#### Parameters

| Name | Type | Required | Description |
| ------------------------- | :----: | :------: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| guests | Array | Yes | A list of Guest user data. |
| guests[].name | String | Yes | The display name of the user.<br />Must be between 1 - 128 characters. |
| guests[].code | String | Yes | The email address (log in name) of the Guest user. |
| guests[].password | String | Yes | The log in password of the Guest user. |
| guests[].timezone | String | Yes | The timezone of the Guest user. |
| guests[].locale | String | | The language settings of the Guest user.<br/>- <strong>auto</strong>: Use web browser settings.<br />- <strong>en</strong>: English<br />- <strong>zh</strong>: Chinese<br />- <strong>ja</strong>: Japanese<br />If ignored, <strong>auto</strong> will be set. |
| guests[].image | String | | The profile image of the Guest user.<br />Specify a fileKey of an uploaded file. fileKeys can be found from the response of the [Upload File API](https://kintone.dev/en/docs/kintone/rest-api/files/upload-file/).<br />If ignored, a default image will be set. |
| guests[].surNameReading | String | | The Phonetic Surname settings of the Guest User. The maximum limit is 64 characters. |
| guests[].givenNameReading | String | | The Phonetic Given Name settings of the Guest User. The maximum limit is 64 characters. |
| guests[].company | String | | The Company name to display on the Guest User's profile.<br />The maximum limit is 100 characters. |
| guests[].division | String | | The Department name to display on the Guest User's profile.<br />The maximum limit is 100 characters. |
| guests[].phone | String | | The Phone number to display on the Guest User's profile.<br />The maximum limit is 100 characters. |
| guests[].callto | String | | The Skype Name of the Guest user.<br />The maximum limit is 256 characters. |

#### Returns

An empty object.

#### Reference

- https://kintone.dev/en/docs/kintone/rest-api/spaces/add-guests/
8 changes: 8 additions & 0 deletions packages/rest-api-client/src/client/SpaceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
ThreadComment,
SpaceMemberForResponse,
SpaceMemberForRequest,
Guest,
} from "./types";
import { BaseClient } from "./BaseClient";

Expand Down Expand Up @@ -66,4 +67,11 @@ export class SpaceClient extends BaseClient {
});
return this.client.post(path, params);
}

public addGuests(params: { guests: Guest[] }): Promise<{}> {
const path = this.buildPathWithGuestSpaceId({
endpointName: "guests",
});
return this.client.post(path, params);
}
}
33 changes: 33 additions & 0 deletions packages/rest-api-client/src/client/__tests__/SpaceClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,39 @@ describe("SpaceClient", () => {
expect(mockClient.getLogs()[0].params).toEqual(params);
});
});

describe("addGuests", () => {
const params = {
guests: [
{
name: "John Doe",
code: "johndoe@gmail.com",
password: "password123",
timezone: "America/Los_Angeles",
locale: "en" as const,
image: "image",
surNameReading: "Doe",
givenNameReading: "John",
company: "company",
division: "division",
phone: "phone",
callto: "callto",
},
],
};
beforeEach(async () => {
await spaceClient.addGuests(params);
});
it("should pass the path to the http client", () => {
expect(mockClient.getLogs()[0].path).toBe("/k/v1/guests.json");
});
it("should send a POST request", () => {
expect(mockClient.getLogs()[0].method).toBe("post");
});
it("should pass guests to the http client", () => {
expect(mockClient.getLogs()[0].params).toEqual(params);
});
});
});

describe("SpaceClient with guestSpaceId", () => {
Expand Down
15 changes: 15 additions & 0 deletions packages/rest-api-client/src/client/types/space/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,18 @@ export type ThreadComment = {
thread: ThreadID;
comment: CommentWithText | CommentWithFiles;
};

export type Guest = {
name: string;
code: string;
password: string;
timezone: string;
locale?: "auto" | "en" | "zh" | "ja";
image?: string;
surNameReading?: string;
givenNameReading?: string;
company?: string;
division?: string;
phone?: string;
callto?: string;
};
Loading