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 method of plugin.installPlugin #2931

Merged
merged 1 commit into from
Aug 15, 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 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);
}
}
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;
};