Skip to content

Commit 4684de2

Browse files
committed
feat(rest-api-client): add app.getPlugins method
1 parent c4d7538 commit 4684de2

File tree

5 files changed

+104
-0
lines changed

5 files changed

+104
-0
lines changed

examples/rest-api-client-demo/src/app.ts

+8
Original file line numberDiff line numberDiff line change
@@ -764,4 +764,12 @@ export class App {
764764
console.log(error);
765765
}
766766
}
767+
768+
public async getPlugins() {
769+
try {
770+
console.log(await this.client.app.getPlugins({ app: APP_ID }));
771+
} catch (error) {
772+
console.log(error);
773+
}
774+
}
767775
}

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

+24
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
- [updateReports](#updateReports)
3737
- [getAppActions](#getAppActions)
3838
- [updateAppActions](#updateAppActions)
39+
- [getPlugins](#getPlugins)
3940

4041
## Overview
4142

@@ -1353,3 +1354,26 @@ Updates the [Action](https://get.kintone.help/k/en/user/app_settings/appaction/s
13531354
#### Reference
13541355

13551356
- https://kintone.dev/en/docs/kintone/rest-api/apps/update-action-settings/
1357+
1358+
### getPlugins
1359+
1360+
Gets the list of Plug-ins added to an App.
1361+
1362+
#### Parameters
1363+
1364+
| Name | Type | Required | Description |
1365+
| ------- | :--------------: | :------: | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1366+
| app | Number or String | Yes | The App ID. |
1367+
| lang | String | | The localized language to retrieve the data in: <ul> <li>`en`: retrieves the localized English names</li> <li>`zh`: retrieves the localized Chinese names</li> <li>`ja`: retrieves the localized Japanese names</li> </ul>If ignored, the default names will be retrieved. |
1368+
| preview | Boolean | | A flag whether to get the app actions for pre-live environment |
1369+
1370+
#### Returns
1371+
1372+
| Name | Type | Description |
1373+
| -------- | :----: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1374+
| revision | String | The revision number of the App settings. |
1375+
| plugins | Object | An object listing Plug-ins. <br/>For each property of this object, see “Response Parameters” section of [the reference](https://kintone.dev/en/docs/kintone/rest-api/apps/get-app-plugins/) |
1376+
1377+
#### Reference
1378+
1379+
- https://kintone.dev/en/docs/kintone/rest-api/apps/get-app-plugins/

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

+17
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import type {
3535
AppActionsForResponse,
3636
} from "./types";
3737
import { BaseClient } from "./BaseClient";
38+
import type { AppPlugin } from "./types/app/plugin";
3839
type RowLayoutForParameter = {
3940
type: "ROW";
4041
fields: Array<{ [key: string]: unknown }>;
@@ -616,4 +617,20 @@ export class AppClient extends BaseClient {
616617
});
617618
return this.client.put(path, params);
618619
}
620+
621+
public getPlugins(params: {
622+
app: AppID;
623+
lang?: Lang;
624+
preview?: boolean;
625+
}): Promise<{
626+
plugins: AppPlugin[];
627+
revision: string;
628+
}> {
629+
const { preview, ...rest } = params;
630+
const path = this.buildPathWithGuestSpaceId({
631+
endpointName: "app/plugins",
632+
preview,
633+
});
634+
return this.client.get(path, rest);
635+
}
619636
}

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

+50
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,56 @@ describe("AppClient", () => {
13121312
});
13131313
});
13141314

1315+
describe("AppClient: plugins", () => {
1316+
let mockClient: MockClient;
1317+
let appClient: AppClient;
1318+
1319+
beforeEach(() => {
1320+
const requestConfigBuilder = new KintoneRequestConfigBuilder({
1321+
baseUrl: "https://example.cybozu.com",
1322+
auth: { type: "apiToken", apiToken: "foo" },
1323+
});
1324+
mockClient = buildMockClient(requestConfigBuilder);
1325+
appClient = new AppClient(mockClient);
1326+
});
1327+
describe("getPlugins", () => {
1328+
const params = { app: APP_ID } as const;
1329+
describe("without preview", () => {
1330+
beforeEach(async () => {
1331+
await appClient.getPlugins(params);
1332+
});
1333+
it("should pass the path to the http client", () => {
1334+
expect(mockClient.getLogs()[0].path).toBe("/k/v1/app/plugins.json");
1335+
});
1336+
it("should send a get request", () => {
1337+
expect(mockClient.getLogs()[0].method).toBe("get");
1338+
});
1339+
it("should pass app and lang as a param to the http client", () => {
1340+
expect(mockClient.getLogs()[0].params).toEqual(params);
1341+
});
1342+
});
1343+
describe("preview: true", () => {
1344+
beforeEach(async () => {
1345+
await appClient.getPlugins({
1346+
...params,
1347+
preview: true,
1348+
});
1349+
});
1350+
it("should pass the path to the http client", () => {
1351+
expect(mockClient.getLogs()[0].path).toBe(
1352+
"/k/v1/preview/app/plugins.json",
1353+
);
1354+
});
1355+
it("should send a get request", () => {
1356+
expect(mockClient.getLogs()[0].method).toBe("get");
1357+
});
1358+
it("should pass app and lang as a param to the http client", () => {
1359+
expect(mockClient.getLogs()[0].params).toEqual(params);
1360+
});
1361+
});
1362+
});
1363+
});
1364+
13151365
describe("AppClient with guestSpaceId", () => {
13161366
it("should pass the path to the http client", async () => {
13171367
const GUEST_SPACE_ID = 2;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export type AppPlugin = {
2+
id: string;
3+
name: string;
4+
enabled: boolean;
5+
};

0 commit comments

Comments
 (0)