Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rest-api-client): add app.getPlugins method #2854

Merged
merged 4 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions examples/rest-api-client-demo/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
32 changes: 28 additions & 4 deletions packages/rest-api-client/docs/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
- [updateReports](#updateReports)
- [getAppActions](#getAppActions)
- [updateAppActions](#updateAppActions)
- [getPlugins](#getPlugins)

## Overview

Expand Down Expand Up @@ -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. <br/>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. <br/>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

Expand Down Expand Up @@ -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: <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. |
| 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. <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/) |

#### Reference

- https://kintone.dev/en/docs/kintone/rest-api/apps/get-app-plugins/
38 changes: 28 additions & 10 deletions packages/rest-api-client/src/client/AppClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
RecordID,
Revision,
Properties,
Lang,
AppLang,
Layout,
ViewForResponse,
ViewForParameter,
Expand Down Expand Up @@ -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 }>;
Expand Down Expand Up @@ -68,7 +70,7 @@ type SpaceResponseParameters = {
export class AppClient extends BaseClient {
public getFormFields<T extends Properties>(params: {
app: AppID;
lang?: Lang;
lang?: AppLang;
preview?: boolean;
}): Promise<{ properties: T; revision: string }> {
const { preview, ...rest } = params;
Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -221,7 +223,7 @@ export class AppClient extends BaseClient {

public getAppSettings(params: {
app: AppID;
lang?: Lang;
lang?: AppLang;
preview?: boolean;
}): Promise<{
name: string;
Expand Down Expand Up @@ -292,7 +294,7 @@ export class AppClient extends BaseClient {

public getProcessManagement(params: {
app: AppID;
lang?: Lang;
lang?: AppLang;
preview?: boolean;
}): Promise<{
enable: boolean;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -499,7 +501,7 @@ export class AppClient extends BaseClient {

public getPerRecordNotifications(params: {
app: AppID;
lang?: Lang;
lang?: AppLang;
preview?: boolean;
}): Promise<{
notifications: PerRecordNotificationForResponse[];
Expand Down Expand Up @@ -527,7 +529,7 @@ export class AppClient extends BaseClient {

public getReminderNotifications(params: {
app: AppID;
lang?: Lang;
lang?: AppLang;
preview?: boolean;
}): Promise<{
notifications: ReminderNotificationForResponse[];
Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -588,7 +590,7 @@ export class AppClient extends BaseClient {

public getAppActions(params: {
app: AppID;
lang?: Lang;
lang?: AppLang;
preview?: boolean;
}): Promise<{
actions: AppActionsForResponse;
Expand Down Expand Up @@ -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);
}
}
50 changes: 50 additions & 0 deletions packages/rest-api-client/src/client/__tests__/AppClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion packages/rest-api-client/src/client/types/app/index.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
5 changes: 5 additions & 0 deletions packages/rest-api-client/src/client/types/app/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type AppPlugin = {
id: string;
name: string;
enabled: boolean;
};