From a9c923549a97a9e0ced62f094f67a269d3bd9326 Mon Sep 17 00:00:00 2001 From: shabaraba Date: Tue, 2 Jul 2024 14:29:49 +0900 Subject: [PATCH] feat(rest-api-client): add app.getPlugins method --- examples/rest-api-client-demo/src/app.ts | 8 +++ packages/rest-api-client/docs/app.md | 31 ++++++++++++ .../rest-api-client/src/client/AppClient.ts | 17 +++++++ .../src/client/__tests__/AppClient.test.ts | 50 +++++++++++++++++++ .../src/client/types/app/plugin.ts | 5 ++ 5 files changed, 111 insertions(+) create mode 100644 packages/rest-api-client/src/client/types/app/plugin.ts diff --git a/examples/rest-api-client-demo/src/app.ts b/examples/rest-api-client-demo/src/app.ts index 187b2fc69e..ce319fc44a 100644 --- a/examples/rest-api-client-demo/src/app.ts +++ b/examples/rest-api-client-demo/src/app.ts @@ -764,4 +764,12 @@ export class App { console.log(error); } } + + public async getPlugins() { + try { + console.log(await this.client.app.getPlugins({ app: APP_ID })); + } catch (error) { + console.log(error); + } + } } diff --git a/packages/rest-api-client/docs/app.md b/packages/rest-api-client/docs/app.md index 1cc5bb155e..8aeb40db1e 100644 --- a/packages/rest-api-client/docs/app.md +++ b/packages/rest-api-client/docs/app.md @@ -36,6 +36,7 @@ - [updateReports](#updateReports) - [getAppActions](#getAppActions) - [updateAppActions](#updateAppActions) + = [getPlugins](#getPlugins) ## Overview @@ -1353,3 +1354,33 @@ Updates the [Action](https://get.kintone.help/k/en/user/app_settings/appaction/s #### Reference - https://kintone.dev/en/docs/kintone/rest-api/apps/update-action-settings/ + +### getPlugins + +Gets the list of Plug-ins added to an App. + +#### Parameters + +| Name | Type | Required | Description | +| ---- | :--------------: | :------: | ----------------------------------------------- | +| app | Number or String | Yes | The App ID. | +| lang | String | | The localized language to retrieve the data in: | + + If ignored, the default names will be retrieved. | + +| preview | Boolean | | A flag whether to get the app actions for pre-live environment | + +#### Returns + +| Name | Type | Description | +| -------- | :----: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| revision | String | The revision number of the App settings. | +| plugins | Object | An object listing Plug-ins.
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/) | + +#### Reference + +- https://kintone.dev/en/docs/kintone/rest-api/apps/get-app-plugins/ diff --git a/packages/rest-api-client/src/client/AppClient.ts b/packages/rest-api-client/src/client/AppClient.ts index d008a45545..c37dee8493 100644 --- a/packages/rest-api-client/src/client/AppClient.ts +++ b/packages/rest-api-client/src/client/AppClient.ts @@ -35,6 +35,7 @@ import type { AppActionsForResponse, } from "./types"; import { BaseClient } from "./BaseClient"; +import type { AppPlugin } from "./types/app/plugin"; type RowLayoutForParameter = { type: "ROW"; fields: Array<{ [key: string]: unknown }>; @@ -616,4 +617,20 @@ export class AppClient extends BaseClient { }); return this.client.put(path, params); } + + public getPlugins(params: { + app: AppID; + lang?: Lang; + preview?: boolean; + }): Promise<{ + plugins: AppPlugin[]; + revision: string; + }> { + const { preview, ...rest } = params; + const path = this.buildPathWithGuestSpaceId({ + endpointName: "app/plugins", + preview, + }); + return this.client.get(path, rest); + } } diff --git a/packages/rest-api-client/src/client/__tests__/AppClient.test.ts b/packages/rest-api-client/src/client/__tests__/AppClient.test.ts index 7e33a0f4f1..caeadd844d 100644 --- a/packages/rest-api-client/src/client/__tests__/AppClient.test.ts +++ b/packages/rest-api-client/src/client/__tests__/AppClient.test.ts @@ -1312,6 +1312,56 @@ describe("AppClient", () => { }); }); +describe("AppClient: plugins", () => { + let mockClient: MockClient; + let appClient: AppClient; + + beforeEach(() => { + const requestConfigBuilder = new KintoneRequestConfigBuilder({ + baseUrl: "https://example.cybozu.com", + auth: { type: "apiToken", apiToken: "foo" }, + }); + mockClient = buildMockClient(requestConfigBuilder); + appClient = new AppClient(mockClient); + }); + describe("getPlugins", () => { + const params = { app: APP_ID } as const; + describe("without preview", () => { + beforeEach(async () => { + await appClient.getPlugins(params); + }); + it("should pass the path to the http client", () => { + expect(mockClient.getLogs()[0].path).toBe("/k/v1/app/plugins.json"); + }); + it("should send a get request", () => { + expect(mockClient.getLogs()[0].method).toBe("get"); + }); + it("should pass app and lang as a param to the http client", () => { + expect(mockClient.getLogs()[0].params).toEqual(params); + }); + }); + describe("preview: true", () => { + beforeEach(async () => { + await appClient.getPlugins({ + ...params, + preview: true, + }); + }); + it("should pass the path to the http client", () => { + expect(mockClient.getLogs()[0].path).toBe( + "/k/v1/preview/app/plugins.json", + ); + }); + it("should send a get request", () => { + expect(mockClient.getLogs()[0].method).toBe("get"); + }); + it("should pass app and lang as a param to the http client", () => { + expect(mockClient.getLogs()[0].params).toEqual(params); + }); + }); + }); +}); + describe("AppClient with guestSpaceId", () => { it("should pass the path to the http client", async () => { const GUEST_SPACE_ID = 2; diff --git a/packages/rest-api-client/src/client/types/app/plugin.ts b/packages/rest-api-client/src/client/types/app/plugin.ts new file mode 100644 index 0000000000..7c0bfb76c9 --- /dev/null +++ b/packages/rest-api-client/src/client/types/app/plugin.ts @@ -0,0 +1,5 @@ +export type AppPlugin = { + id: string; + name: string; + enabled: boolean; +};