Skip to content

Commit 1d0815b

Browse files
authored
feat(rest-api-client): update get plugins api (#3480)
1 parent 7150850 commit 1d0815b

File tree

4 files changed

+105
-13
lines changed

4 files changed

+105
-13
lines changed

packages/rest-api-client/docs/plugin.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ Gets the list of plug-ins imported into Kintone.
3232

3333
#### Parameters
3434

35-
| Name | Type | Required | Description |
36-
| ------ | :----: | :------: | ---------------------------------------------------------------------------------------------------------- |
37-
| offset | Number | | The number of plug-ins to skip from the list of installed plug-ins.<br />If ignored, this value is 0. |
38-
| limit | Number | | The maximum number of plug-ins to retrieve.<br />Must be between 1 and 100.The default<br />number is 100. |
35+
| Name | Type | Required | Description |
36+
| ------ | :----: | :------: | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
37+
| offset | Number | | The number of plug-ins to skip from the list of installed plug-ins.<br />If ignored, this value is 0. |
38+
| limit | Number | | The maximum number of plug-ins to retrieve.<br />Must be between 1 and 100. The default<br />number is 100. |
39+
| ids | Array | | The IDs of the plug-ins to retrieve.<br />A maximum of 100 plug-in IDs can be specified.<br />If an empty array is specified, this parameter will be treated as if it was omitted, and all plug-ins will be retrieved. |
3940

4041
#### Returns
4142

@@ -44,6 +45,7 @@ Gets the list of plug-ins imported into Kintone.
4445
| plugins | Array | A list of Plug-ins added to the App.<br />Plug-ins are listed in descending order of the datetime they are added. |
4546
| plugins[].id | String | The Plugin ID. |
4647
| plugins[].name | String | The name of the Plugin. |
48+
| plugins[].description | String | The description of the plug-in.<br />An empty string is returned if no description is set. |
4749
| plugins[].isMarketPlugin | Boolean | States whether or not the plug-in is a Marketplace plug-in.<br /><strong>true</strong>: The plug-in is a Marketplace plug-in.<br /><strong>false</strong>: The plug-in is not a Marketplace plug-in. |
4850
| plugins[].version | String | The version number of the plug-in |
4951

@@ -58,10 +60,10 @@ This can occur when a plug-in is installed, added to an App, and then proceeded
5860

5961
#### Parameters
6062

61-
| Name | Type | Required | Description |
62-
| ------ | :----: | :------: | ---------------------------------------------------------------------------------------------------------- |
63-
| offset | Number | | The number of plug-ins to skip from the list of required plug-ins.<br />If ignored, this value is 0. |
64-
| limit | Number | | The maximum number of plug-ins to retrieve.<br />Must be between 1 and 100.The default<br />number is 100. |
63+
| Name | Type | Required | Description |
64+
| ------ | :----: | :------: | ----------------------------------------------------------------------------------------------------------- |
65+
| offset | Number | | The number of plug-ins to skip from the list of required plug-ins.<br />If ignored, this value is 0. |
66+
| limit | Number | | The maximum number of plug-ins to retrieve.<br />Must be between 1 and 100. The default<br />number is 100. |
6567

6668
#### Returns
6769

@@ -82,11 +84,11 @@ Gets Apps that have the specified plug-in added.
8284

8385
#### Parameters
8486

85-
| Name | Type | Required | Description |
86-
| ------ | :----: | :------: | ------------------------------------------------------------------------------------------------------ |
87-
| id | String | Yes | The ID of the plug-in. |
88-
| offset | Number | | The number of apps to skip from the list of app.<br />If ignored, this value is 0. |
89-
| limit | Number | | The maximum number of apps to retrieve.<br />Must be between 1 and 500.The default<br />number is 100. |
87+
| Name | Type | Required | Description |
88+
| ------ | :----: | :------: | ------------------------------------------------------------------------------------------------------- |
89+
| id | String | Yes | The ID of the plug-in. |
90+
| offset | Number | | The number of apps to skip from the list of app.<br />If ignored, this value is 0. |
91+
| limit | Number | | The maximum number of apps to retrieve.<br />Must be between 1 and 500. The default<br />number is 100. |
9092

9193
#### Returns
9294

packages/rest-api-client/src/client/PluginClient.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ export class PluginClient extends BaseClient {
1717
public getPlugins(
1818
params: GetPluginsForRequest,
1919
): Promise<GetPluginsForResponse> {
20+
if (params.ids !== undefined) {
21+
if (
22+
!Array.isArray(params.ids) ||
23+
!params.ids.every((id) => typeof id === "string")
24+
) {
25+
throw new Error("the `ids` parameter must be an array of string.");
26+
}
27+
}
2028
const path = this.buildPath({ endpointName: "plugins" });
2129
return this.client.get(path, params);
2230
}

packages/rest-api-client/src/client/__tests__/PluginClient.test.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,86 @@ describe("PluginClient", () => {
3737
it("should pass the param to the http client", () => {
3838
expect(mockClient.getLogs()[0].params).toEqual(params);
3939
});
40+
41+
describe("with ids parameter", () => {
42+
const paramsWithIds = {
43+
offset: 0,
44+
limit: 10,
45+
ids: ["plugin1", "plugin2", "plugin3"],
46+
};
47+
beforeEach(async () => {
48+
mockClient.logs.length = 0;
49+
await pluginClient.getPlugins(paramsWithIds);
50+
});
51+
it("should pass the path to the http client", () => {
52+
expect(mockClient.getLogs()[0].path).toBe("/k/v1/plugins.json");
53+
});
54+
it("should send a GET request", () => {
55+
expect(mockClient.getLogs()[0].method).toBe("get");
56+
});
57+
it("should pass the ids param to the http client", () => {
58+
expect(mockClient.getLogs()[0].params).toEqual(paramsWithIds);
59+
});
60+
});
61+
62+
describe("validation for ids parameter", () => {
63+
it("should throw an error if ids is not an array", () => {
64+
const invalidParams = {
65+
offset: 0,
66+
limit: 10,
67+
ids: "not-an-array",
68+
};
69+
// @ts-expect-error Testing runtime validation
70+
expect(() => pluginClient.getPlugins(invalidParams)).toThrow(
71+
"the `ids` parameter must be an array of string.",
72+
);
73+
});
74+
75+
it("should throw an error if ids contains non-string values", () => {
76+
const invalidParams = {
77+
offset: 0,
78+
limit: 10,
79+
ids: ["plugin1", 123, "plugin3"],
80+
};
81+
// @ts-expect-error Testing runtime validation
82+
expect(() => pluginClient.getPlugins(invalidParams)).toThrow(
83+
"the `ids` parameter must be an array of string.",
84+
);
85+
});
86+
87+
it("should throw an error if ids contains object values", () => {
88+
const invalidParams = {
89+
offset: 0,
90+
limit: 10,
91+
ids: ["plugin1", { id: "plugin2" }, "plugin3"],
92+
};
93+
// @ts-expect-error Testing runtime validation
94+
expect(() => pluginClient.getPlugins(invalidParams)).toThrow(
95+
"the `ids` parameter must be an array of string.",
96+
);
97+
});
98+
99+
it("should not throw an error if ids is undefined", async () => {
100+
const validParams = {
101+
offset: 0,
102+
limit: 10,
103+
};
104+
await expect(
105+
pluginClient.getPlugins(validParams),
106+
).resolves.not.toThrow();
107+
});
108+
109+
it("should not throw an error if ids is an empty array", async () => {
110+
const validParams = {
111+
offset: 0,
112+
limit: 10,
113+
ids: [],
114+
};
115+
await expect(
116+
pluginClient.getPlugins(validParams),
117+
).resolves.not.toThrow();
118+
});
119+
});
40120
});
41121

42122
describe("getRequiredPlugins", () => {

packages/rest-api-client/src/client/types/plugin/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { PluginID } from "..";
33
type Plugin = {
44
id: string;
55
name: string;
6+
description: string;
67
isMarketPlugin: boolean;
78
version: string;
89
};
@@ -12,6 +13,7 @@ type RequiredPlugin = Omit<Plugin, "revision">;
1213
export type GetPluginsForRequest = {
1314
offset?: number;
1415
limit?: number;
16+
ids?: string[];
1517
};
1618

1719
export type GetPluginsForResponse = {

0 commit comments

Comments
 (0)