From c4d753892db71e7a4c21077ed65e49c528b535d6 Mon Sep 17 00:00:00 2001 From: shabaraba Date: Tue, 2 Jul 2024 14:13:50 +0900 Subject: [PATCH 1/4] chore(rest-api-client): fix doc for get app actions --- packages/rest-api-client/docs/app.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/rest-api-client/docs/app.md b/packages/rest-api-client/docs/app.md index eadb84ab16..1cc5bb155e 100644 --- a/packages/rest-api-client/docs/app.md +++ b/packages/rest-api-client/docs/app.md @@ -1321,10 +1321,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 From 4684de29e8831cea880a345f7f02918ef641f20e Mon Sep 17 00:00:00 2001 From: shabaraba Date: Tue, 2 Jul 2024 14:29:49 +0900 Subject: [PATCH 2/4] feat(rest-api-client): add app.getPlugins method --- examples/rest-api-client-demo/src/app.ts | 8 +++ packages/rest-api-client/docs/app.md | 24 +++++++++ .../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, 104 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..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 @@ -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: 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; +}; From 51e8539a26edc7a312a27db823cd4f236ec7baf2 Mon Sep 17 00:00:00 2001 From: shabaraba Date: Tue, 2 Jul 2024 15:32:27 +0900 Subject: [PATCH 3/4] fix(rest-api-client): fix lang type for request parameter --- examples/rest-api-client-demo/src/app.ts | 4 +++- packages/rest-api-client/src/client/AppClient.ts | 2 +- .../rest-api-client/src/client/__tests__/AppClient.test.ts | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/rest-api-client-demo/src/app.ts b/examples/rest-api-client-demo/src/app.ts index ce319fc44a..7e4d09df55 100644 --- a/examples/rest-api-client-demo/src/app.ts +++ b/examples/rest-api-client-demo/src/app.ts @@ -767,7 +767,9 @@ export class App { public async getPlugins() { try { - console.log(await this.client.app.getPlugins({ app: APP_ID })); + console.log( + await this.client.app.getPlugins({ app: APP_ID, lang: "en" }), + ); } catch (error) { console.log(error); } diff --git a/packages/rest-api-client/src/client/AppClient.ts b/packages/rest-api-client/src/client/AppClient.ts index c37dee8493..7c46628864 100644 --- a/packages/rest-api-client/src/client/AppClient.ts +++ b/packages/rest-api-client/src/client/AppClient.ts @@ -620,7 +620,7 @@ export class AppClient extends BaseClient { public getPlugins(params: { app: AppID; - lang?: Lang; + lang?: Exclude; preview?: boolean; }): Promise<{ plugins: AppPlugin[]; 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 caeadd844d..f155423e13 100644 --- a/packages/rest-api-client/src/client/__tests__/AppClient.test.ts +++ b/packages/rest-api-client/src/client/__tests__/AppClient.test.ts @@ -1325,7 +1325,7 @@ describe("AppClient: plugins", () => { appClient = new AppClient(mockClient); }); describe("getPlugins", () => { - const params = { app: APP_ID } as const; + const params = { app: APP_ID, lang: "en" } as const; describe("without preview", () => { beforeEach(async () => { await appClient.getPlugins(params); From d7a04492f6fcfd8c8bfaed21c4e5b9767bbd40aa Mon Sep 17 00:00:00 2001 From: shabaraba Date: Fri, 5 Jul 2024 20:30:39 +0900 Subject: [PATCH 4/4] feat(rest-api-client): Lang type split into AppLang and PluginLocale --- .../rest-api-client/src/client/AppClient.ts | 23 ++++++++++--------- .../src/client/types/app/index.ts | 4 +++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/packages/rest-api-client/src/client/AppClient.ts b/packages/rest-api-client/src/client/AppClient.ts index 7c46628864..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,6 +33,7 @@ import type { ReportForResponse, AppActionsForParameter, AppActionsForResponse, + PluginLocale, } from "./types"; import { BaseClient } from "./BaseClient"; import type { AppPlugin } from "./types/app/plugin"; @@ -69,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; @@ -142,7 +143,7 @@ export class AppClient extends BaseClient { public getViews(params: { app: AppID; - lang?: Lang; + lang?: AppLang; preview?: boolean; }): Promise<{ views: { [viewName: string]: ViewForResponse }; @@ -222,7 +223,7 @@ export class AppClient extends BaseClient { public getAppSettings(params: { app: AppID; - lang?: Lang; + lang?: AppLang; preview?: boolean; }): Promise<{ name: string; @@ -293,7 +294,7 @@ export class AppClient extends BaseClient { public getProcessManagement(params: { app: AppID; - lang?: Lang; + lang?: AppLang; preview?: boolean; }): Promise<{ enable: boolean; @@ -414,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; @@ -500,7 +501,7 @@ export class AppClient extends BaseClient { public getPerRecordNotifications(params: { app: AppID; - lang?: Lang; + lang?: AppLang; preview?: boolean; }): Promise<{ notifications: PerRecordNotificationForResponse[]; @@ -528,7 +529,7 @@ export class AppClient extends BaseClient { public getReminderNotifications(params: { app: AppID; - lang?: Lang; + lang?: AppLang; preview?: boolean; }): Promise<{ notifications: ReminderNotificationForResponse[]; @@ -558,7 +559,7 @@ export class AppClient extends BaseClient { public getReports(params: { app: AppID; - lang?: Lang; + lang?: AppLang; preview?: boolean; }): Promise<{ reports: { [reportName: string]: ReportForResponse }; @@ -589,7 +590,7 @@ export class AppClient extends BaseClient { public getAppActions(params: { app: AppID; - lang?: Lang; + lang?: AppLang; preview?: boolean; }): Promise<{ actions: AppActionsForResponse; @@ -620,7 +621,7 @@ export class AppClient extends BaseClient { public getPlugins(params: { app: AppID; - lang?: Exclude; + lang?: PluginLocale; preview?: boolean; }): Promise<{ plugins: AppPlugin[]; 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 = {