Skip to content

Commit

Permalink
feat(rest-api-client): add app.getPlugins method
Browse files Browse the repository at this point in the history
  • Loading branch information
shabaraba committed Jul 2, 2024
1 parent c4d7538 commit a9c9235
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 0 deletions.
8 changes: 8 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,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);
}
}
}
31 changes: 31 additions & 0 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 @@ -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: |

<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/
17 changes: 17 additions & 0 deletions packages/rest-api-client/src/client/AppClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }>;
Expand Down Expand Up @@ -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);
}
}
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 } 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
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;
};

0 comments on commit a9c9235

Please sign in to comment.