Skip to content

Commit

Permalink
Merge branch 'master' into feat/add-addGuests-method
Browse files Browse the repository at this point in the history
# Conflicts:
#	examples/rest-api-client-demo/src/space.ts
#	packages/rest-api-client/docs/space.md
#	packages/rest-api-client/src/client/SpaceClient.ts
#	packages/rest-api-client/src/client/__tests__/SpaceClient.test.ts
#	packages/rest-api-client/src/client/types/space/index.ts
  • Loading branch information
hung-cybo committed Mar 19, 2024
2 parents b3b07fa + 981e6b6 commit 54a2961
Show file tree
Hide file tree
Showing 13 changed files with 362 additions and 194 deletions.
30 changes: 29 additions & 1 deletion examples/rest-api-client-demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,44 @@ We have an app ID in `customize-manifest.json`, so you have to update the app ID

### Run a script with `ts-node`

#### yarn

```
% yarn demo record getRecord
```

#### npm

```
% npm run demo record getRecord
```

#### pnpm

```
% yarn run-script record getRecord
% pnpm demo record getRecord
```

### Upload scripts to your Kintone environment

#### yarn

```
% yarn deploy
```

#### npm

```
% npm run deploy
```

#### pnpm

```
% pnpm deploy
```

## License

- [MIT](LICENSE)
2 changes: 1 addition & 1 deletion examples/rest-api-client-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"lint": "run-p -l lint:*",
"deploy": "rimraf scripts/dist && run-s webpack upload",
"upload": "kintone-customize-uploader customize-manifest.json",
"run-script": "ts-node src/run-node.ts",
"demo": "ts-node src/run-node.ts",
"webpack": "webpack"
},
"bugs": {
Expand Down
31 changes: 31 additions & 0 deletions examples/rest-api-client-demo/src/space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,37 @@ export class Space {
}
}

public async addThreadComment() {
const params = {
space: "8",
thread: "1",
comment: {
text: "This is a comment",
files: [
{
fileKey: "file1",
width: 100,
},
],
mentions: [
{
code: "user1",
type: "USER" as const,
},
{
code: "user2",
type: "USER" as const,
},
],
},
};
try {
console.log(await this.client.space.addThreadComment(params));
} catch (error) {
console.log(error);
}
}

public async addGuests() {
const guests = [
{
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@cybozu/eslint-config": "^22.0.2",
"@cybozu/license-manager": "^1.1.0",
"@types/jest": "^29.5.12",
"@types/node": "^18.19.23",
"@types/node": "^18.19.24",
"babel-jest": "^29.7.0",
"comment-json": "^4.2.3",
"eslint": "^8.56.0",
Expand All @@ -49,7 +49,7 @@
"rimraf": "^5.0.5",
"typescript": "^5.4.2"
},
"packageManager": "pnpm@8.15.4",
"packageManager": "pnpm@8.15.5",
"pnpm": {
"overrides": {
"follow-redirects@<1.15.4": ">=1.15.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/dts-gen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"license": "MIT",
"dependencies": {
"@cybozu/eslint-config": "^22.0.2",
"axios": "^1.6.7",
"axios": "^1.6.8",
"commander": "^11.1.0",
"eslint": "^8.56.0",
"form-data": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-packer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"jest-environment-jsdom": "^29.7.0",
"normalize.css": "^8.0.1",
"path-browserify": "^1.0.1",
"postcss": "^8.4.35",
"postcss": "^8.4.36",
"postcss-cli": "^11.0.0",
"process": "^0.11.10",
"redux-logger": "^3.0.6",
Expand Down
30 changes: 30 additions & 0 deletions packages/rest-api-client/docs/space.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [getSpaceMembers](#getSpaceMembers)
- [updateSpaceMembers](#updateSpaceMembers)
- [updateThread](#updateThread)
- [addThreadComment](#addThreadComment)
- [addGuests](#addGuests)

## Overview
Expand Down Expand Up @@ -191,6 +192,35 @@ An empty object.

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

### addThreadComment

Adds a comment to a Thread of a Space.

#### Parameters

| Name | Type | Required | Description |
| ----------------------- | :--------------: | :-------------------------: | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| id | Number or String | Yes | The space ID. |
| thread | Number or String | Yes | The thread ID. |
| comment | Object | | An object including comment details. |
| comment.text | String | Conditionally<br />Required | The comment contents.<br />A line break can be specified by LF.<br />The maximum characters of the comment is 65535. Required, if comment.files is not set. |
| comment.files | Array | Conditionally<br />Required | An array including data of attachment files.<br />The maximum number of the files is 5.<br />Required, if comment.text is not set. |
| comment.files[].fileKey | String | | The fileKey of the attachment file.<br />Use the fileKey that is responded from the [Upload File API](https://kintone.dev/en/docs/kintone/rest-api/files/upload-file/). |
| comment.files[].width | Number or String | | A width can be specified if the attachment file is an image.<br />The minimum is 100, and the maximum is 750.<br />If this parameter is ignored, the original width will be set (this width is the same size as the size when "Original" is chosen when adding an image to a thread via GUI). This parameter is ignored if the file is not an image. |
| comment.mentions | Array | | An array including mentions, that notify other Kintone users. |
| comment.mentions[].code | String | | The code of the user, group or department that will be mentioned.<br />The maximum number of mentions is 10.<br />The mentioned users will be placed in front of the comment text in the output. |
| comment.mentions[].type | String | | The entity type of the mentioned target.<br><ul><li><strong>USER</strong>: User<li><strong>GROUP</strong>: Group<li><strong>ORGANIZATION</strong>: Department |

#### Returns

| Name | Type | Description |
| ---- | :----: | -------------------------------------- |
| id | String | The comment ID of the created comment. |

#### Reference

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

### addGuests

Adds Guest users to Kintone.<br>
Expand Down
4 changes: 2 additions & 2 deletions packages/rest-api-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"@types/core-js": "^2.5.8",
"@types/js-base64": "^3.0.0",
"@types/mime": "^3.0.4",
"@types/qs": "^6.9.12",
"@types/qs": "^6.9.13",
"rollup": "^4.13.0",
"rollup-plugin-ecma-version-validator": "^0.2.13",
"rollup-plugin-license": "^3.3.1",
Expand All @@ -75,7 +75,7 @@
},
"dependencies": {
"core-js": "^3.35.1",
"axios": "^1.6.7",
"axios": "^1.6.8",
"form-data": "^4.0.0",
"js-base64": "^3.7.7",
"mime": "^3.0.0",
Expand Down
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 @@ -2,6 +2,7 @@ import type {
SpaceID,
ThreadID,
Space,
ThreadComment,
SpaceMemberForResponse,
SpaceMemberForRequest,
Guest,
Expand Down Expand Up @@ -60,6 +61,13 @@ export class SpaceClient extends BaseClient {
return this.client.put(path, params);
}

public addThreadComment(params: ThreadComment): Promise<{ id: string }> {
const path = this.buildPathWithGuestSpaceId({
endpointName: "space/thread/comment",
});
return this.client.post(path, params);
}

public addGuests(params: { guests: Guest[] }): Promise<{}> {
const path = this.buildPathWithGuestSpaceId({
endpointName: "guests",
Expand Down
31 changes: 31 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 @@ -2,6 +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";

const SPACE_ID = 1;
const THREAD_ID = 1;
Expand Down Expand Up @@ -154,6 +155,36 @@ describe("SpaceClient", () => {
});
});

describe("addThreadComment", () => {
const params: ThreadComment = {
space: "1",
thread: "2",
comment: {
text: "This is a comment",
mentions: [
{
code: "user1",
type: "USER",
},
],
},
};
beforeEach(async () => {
await spaceClient.addThreadComment(params);
});
it("should pass the path to the http client", () => {
expect(mockClient.getLogs()[0].path).toBe(
"/k/v1/space/thread/comment.json",
);
});
it("should send a POST request", () => {
expect(mockClient.getLogs()[0].method).toBe("post");
});
it("should pass space, thread, comment to the http client", () => {
expect(mockClient.getLogs()[0].params).toEqual(params);
});
});

describe("addGuests", () => {
const params = {
guests: [
Expand Down
24 changes: 24 additions & 0 deletions packages/rest-api-client/src/client/types/space/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { App } from "../app";
import type { Entity } from "../entity";
import type { SpaceID, ThreadID } from "../index";

type AttachedApp = Pick<
App,
Expand Down Expand Up @@ -45,6 +46,29 @@ export type SpaceMemberForRequest = {
includeSubs?: boolean;
};

type FileComment = {
fileKey: string;
width?: string | number;
};

export type CommentWithText = {
text: string;
files?: FileComment[];
mentions?: Entity[];
};

export type CommentWithFiles = {
text?: string;
files: FileComment[];
mentions?: Entity[];
};

export type ThreadComment = {
space: SpaceID;
thread: ThreadID;
comment: CommentWithText | CommentWithFiles;
};

export type Guest = {
name: string;
code: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-plugin-kintone-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"devDependencies": {
"@types/adm-zip": "^0.5.5",
"@types/chokidar": "^1.7.5",
"adm-zip": "^0.5.10",
"adm-zip": "^0.5.12",
"chokidar": "^3.5.3",
"rimraf": "^5.0.5",
"webpack": "^5.90.3",
Expand Down
Loading

0 comments on commit 54a2961

Please sign in to comment.