Skip to content

Commit

Permalink
feat(rest-api-client): add method of plugin.installPlugin (#2931)
Browse files Browse the repository at this point in the history
  • Loading branch information
chihiro-adachi authored Aug 15, 2024
1 parent 0c074a7 commit 510a580
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/rest-api-client/docs/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- [getRequiredPlugins](#getRequiredPlugins)
- [getApps](#getApps)
- [updatePlugin](#updatePlugin)
- [installPlugin](#installPlugin)

## Overview

Expand Down Expand Up @@ -119,3 +120,24 @@ Updates an imported plug-in in the Kintone environment.
#### Reference

- https://kintone.dev/en/docs/kintone/rest-api/plugins/update-plugin/

### installPlugin

Install an imported plug-in in the Kintone environment.

#### Parameters

| Name | Type | Required | Description |
| ------- | :----: | :------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| fileKey | String | Yes | The fileKey representing an uploaded file.<br />Use the following API to upload the file and retrieve the fileKey: [Upload File](https://kintone.dev/en/docs/kintone/rest-api/files/upload-file/) |

#### Returns

| Name | Type | Description |
| ------- | :----: | ---------------------------------- |
| id | String | The installed plug-in ID. |
| version | String | The version number of the plug-in. |

#### Reference

- https://kintone.dev/en/docs/kintone/rest-api/plugins/install-plugin/
9 changes: 9 additions & 0 deletions packages/rest-api-client/src/client/PluginClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import type {
GetRequiredPluginsForResponse,
UpdatePluginForRequest,
UpdatePluginForResponse,
InstallPluginForRequest,
InstallPluginForResponse,
} from "./types/plugin";

export class PluginClient extends BaseClient {
Expand Down Expand Up @@ -36,4 +38,11 @@ export class PluginClient extends BaseClient {
const path = this.buildPath({ endpointName: "plugin" });
return this.client.put(path, params);
}

public installPlugin(
params: InstallPluginForRequest,
): Promise<InstallPluginForResponse> {
const path = this.buildPath({ endpointName: "plugin" });
return this.client.post(path, params);
}
}
18 changes: 18 additions & 0 deletions packages/rest-api-client/src/client/__tests__/PluginClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,22 @@ describe("PluginClient", () => {
expect(mockClient.getLogs()[0].params).toEqual(params);
});
});

describe("installPlugin", () => {
const params = {
fileKey: "fileKey",
};
beforeEach(async () => {
await pluginClient.installPlugin(params);
});
it("should pass the path to the http client", () => {
expect(mockClient.getLogs()[0].path).toBe("/k/v1/plugin.json");
});
it("should send a POST request", () => {
expect(mockClient.getLogs()[0].method).toBe("post");
});
it("should pass the param to the http client", () => {
expect(mockClient.getLogs()[0].params).toEqual(params);
});
});
});
9 changes: 9 additions & 0 deletions packages/rest-api-client/src/client/types/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,12 @@ export type UpdatePluginForResponse = {
id: PluginID;
version: string;
};

export type InstallPluginForRequest = {
fileKey: string;
};

export type InstallPluginForResponse = {
id: PluginID;
version: string;
};

0 comments on commit 510a580

Please sign in to comment.