From e88b9f569df02485c1f91dcf9fb094d751efbb17 Mon Sep 17 00:00:00 2001
From: TakahikoKawakami <53943902+shabaraba@users.noreply.github.com>
Date: Wed, 10 Jul 2024 11:13:30 +0900
Subject: [PATCH] feat(rest-api-client): add app.getPlugins method (#2854)
---
examples/rest-api-client-demo/src/app.ts | 10 ++++
packages/rest-api-client/docs/app.md | 32 ++++++++++--
.../rest-api-client/src/client/AppClient.ts | 38 ++++++++++----
.../src/client/__tests__/AppClient.test.ts | 50 +++++++++++++++++++
.../src/client/types/app/index.ts | 4 +-
.../src/client/types/app/plugin.ts | 5 ++
6 files changed, 124 insertions(+), 15 deletions(-)
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..7e4d09df55 100644
--- a/examples/rest-api-client-demo/src/app.ts
+++ b/examples/rest-api-client-demo/src/app.ts
@@ -764,4 +764,14 @@ export class App {
console.log(error);
}
}
+
+ public async getPlugins() {
+ try {
+ console.log(
+ await this.client.app.getPlugins({ app: APP_ID, lang: "en" }),
+ );
+ } catch (error) {
+ console.log(error);
+ }
+ }
}
diff --git a/packages/rest-api-client/docs/app.md b/packages/rest-api-client/docs/app.md
index eadb84ab16..823fd8c1c2 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
@@ -1321,10 +1322,10 @@ Get the [Action](https://get.kintone.help/k/en/user/app_settings/appaction/set_a
#### Returns
-| Name | Type | Description |
-| -------- | :----: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| revision | String | The revision number of the App settings. |
-| actions | Object | An object listing Action settings. An object listing Action settings.
For each property of this object, see “Response Parameters” section of [the reference](https://kintone.dev/en/docs/kintone/rest-api/apps/get-action-settings/) |
+| Name | Type | Description |
+| -------- | :----: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
+| revision | String | The revision number of the App settings. |
+| actions | Object | An object listing Action settings.
For each property of this object, see “Response Parameters” section of [the reference](https://kintone.dev/en/docs/kintone/rest-api/apps/get-action-settings/) |
#### Reference
@@ -1353,3 +1354,26 @@ 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:
- `en`: retrieves the localized English names
- `zh`: retrieves the localized Chinese names
- `ja`: retrieves the localized Japanese names
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..0c10d13c30 100644
--- a/packages/rest-api-client/src/client/AppClient.ts
+++ b/packages/rest-api-client/src/client/AppClient.ts
@@ -3,7 +3,7 @@ import type {
RecordID,
Revision,
Properties,
- Lang,
+ AppLang,
Layout,
ViewForResponse,
ViewForParameter,
@@ -33,8 +33,10 @@ import type {
ReportForResponse,
AppActionsForParameter,
AppActionsForResponse,
+ PluginLocale,
} from "./types";
import { BaseClient } from "./BaseClient";
+import type { AppPlugin } from "./types/app/plugin";
type RowLayoutForParameter = {
type: "ROW";
fields: Array<{ [key: string]: unknown }>;
@@ -68,7 +70,7 @@ type SpaceResponseParameters = {
export class AppClient extends BaseClient {
public getFormFields(params: {
app: AppID;
- lang?: Lang;
+ lang?: AppLang;
preview?: boolean;
}): Promise<{ properties: T; revision: string }> {
const { preview, ...rest } = params;
@@ -141,7 +143,7 @@ export class AppClient extends BaseClient {
public getViews(params: {
app: AppID;
- lang?: Lang;
+ lang?: AppLang;
preview?: boolean;
}): Promise<{
views: { [viewName: string]: ViewForResponse };
@@ -221,7 +223,7 @@ export class AppClient extends BaseClient {
public getAppSettings(params: {
app: AppID;
- lang?: Lang;
+ lang?: AppLang;
preview?: boolean;
}): Promise<{
name: string;
@@ -292,7 +294,7 @@ export class AppClient extends BaseClient {
public getProcessManagement(params: {
app: AppID;
- lang?: Lang;
+ lang?: AppLang;
preview?: boolean;
}): Promise<{
enable: boolean;
@@ -413,7 +415,7 @@ export class AppClient extends BaseClient {
public getRecordAcl(params: {
app: AppID;
- lang?: Lang;
+ lang?: AppLang;
preview?: boolean;
}): Promise<{ rights: RecordRightForResponse[]; revision: string }> {
const { preview, ...rest } = params;
@@ -499,7 +501,7 @@ export class AppClient extends BaseClient {
public getPerRecordNotifications(params: {
app: AppID;
- lang?: Lang;
+ lang?: AppLang;
preview?: boolean;
}): Promise<{
notifications: PerRecordNotificationForResponse[];
@@ -527,7 +529,7 @@ export class AppClient extends BaseClient {
public getReminderNotifications(params: {
app: AppID;
- lang?: Lang;
+ lang?: AppLang;
preview?: boolean;
}): Promise<{
notifications: ReminderNotificationForResponse[];
@@ -557,7 +559,7 @@ export class AppClient extends BaseClient {
public getReports(params: {
app: AppID;
- lang?: Lang;
+ lang?: AppLang;
preview?: boolean;
}): Promise<{
reports: { [reportName: string]: ReportForResponse };
@@ -588,7 +590,7 @@ export class AppClient extends BaseClient {
public getAppActions(params: {
app: AppID;
- lang?: Lang;
+ lang?: AppLang;
preview?: boolean;
}): Promise<{
actions: AppActionsForResponse;
@@ -616,4 +618,20 @@ export class AppClient extends BaseClient {
});
return this.client.put(path, params);
}
+
+ public getPlugins(params: {
+ app: AppID;
+ lang?: PluginLocale;
+ 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..f155423e13 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, lang: "en" } 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/index.ts b/packages/rest-api-client/src/client/types/app/index.ts
index 9796574602..3439ecfe10 100644
--- a/packages/rest-api-client/src/client/types/app/index.ts
+++ b/packages/rest-api-client/src/client/types/app/index.ts
@@ -1,4 +1,6 @@
-export type Lang = "ja" | "en" | "zh" | "user" | "default";
+type Lang = "ja" | "en" | "zh";
+export type AppLang = Lang | "default" | "user";
+export type PluginLocale = Lang;
export type DeployStatus = "PROCESSING" | "SUCCESS" | "FAIL" | "CANCEL";
export type App = {
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;
+};