From 510a580a668c094de180dbd1c3d598c7354318c2 Mon Sep 17 00:00:00 2001 From: Chihiro Adachi <8196725+chihiro-adachi@users.noreply.github.com> Date: Fri, 16 Aug 2024 08:28:04 +0900 Subject: [PATCH] feat(rest-api-client): add method of plugin.installPlugin (#2931) --- packages/rest-api-client/docs/plugin.md | 22 +++++++++++++++++++ .../src/client/PluginClient.ts | 9 ++++++++ .../src/client/__tests__/PluginClient.test.ts | 18 +++++++++++++++ .../src/client/types/plugin/index.ts | 9 ++++++++ 4 files changed, 58 insertions(+) diff --git a/packages/rest-api-client/docs/plugin.md b/packages/rest-api-client/docs/plugin.md index 69c58b624e..ea49e2552e 100644 --- a/packages/rest-api-client/docs/plugin.md +++ b/packages/rest-api-client/docs/plugin.md @@ -4,6 +4,7 @@ - [getRequiredPlugins](#getRequiredPlugins) - [getApps](#getApps) - [updatePlugin](#updatePlugin) +- [installPlugin](#installPlugin) ## Overview @@ -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.
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/ diff --git a/packages/rest-api-client/src/client/PluginClient.ts b/packages/rest-api-client/src/client/PluginClient.ts index 2c6f580f89..e493f6f77a 100644 --- a/packages/rest-api-client/src/client/PluginClient.ts +++ b/packages/rest-api-client/src/client/PluginClient.ts @@ -8,6 +8,8 @@ import type { GetRequiredPluginsForResponse, UpdatePluginForRequest, UpdatePluginForResponse, + InstallPluginForRequest, + InstallPluginForResponse, } from "./types/plugin"; export class PluginClient extends BaseClient { @@ -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 { + const path = this.buildPath({ endpointName: "plugin" }); + return this.client.post(path, params); + } } diff --git a/packages/rest-api-client/src/client/__tests__/PluginClient.test.ts b/packages/rest-api-client/src/client/__tests__/PluginClient.test.ts index 665c8712e6..07955408d4 100644 --- a/packages/rest-api-client/src/client/__tests__/PluginClient.test.ts +++ b/packages/rest-api-client/src/client/__tests__/PluginClient.test.ts @@ -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); + }); + }); }); diff --git a/packages/rest-api-client/src/client/types/plugin/index.ts b/packages/rest-api-client/src/client/types/plugin/index.ts index 5cd3079e4d..387b46303b 100644 --- a/packages/rest-api-client/src/client/types/plugin/index.ts +++ b/packages/rest-api-client/src/client/types/plugin/index.ts @@ -46,3 +46,12 @@ export type UpdatePluginForResponse = { id: PluginID; version: string; }; + +export type InstallPluginForRequest = { + fileKey: string; +}; + +export type InstallPluginForResponse = { + id: PluginID; + version: string; +};