Skip to content

Commit

Permalink
feat(rest-api-client): Support App Action Settings API (#833)
Browse files Browse the repository at this point in the history
* feat(rest-api-client): implement `getAppActions` and `updateAppActions`

* chore(examples/rest-api-client-demo): add demo scripts for App Action Settings

- demo scripts for `getAppActions`
- demo script for `updateAppActions`

* test(rest-api-client): add test for getAppActions

* test(rest-api-client): add test for updateAppActions

* docs: add getAppActions and updateAppActions

* feat: fix action types

* refactor: report types

* test(data-loader): fix test description

Update packages/rest-api-client/src/client/__tests__/AppClient.test.ts

Co-authored-by: Shingo Yamazaki <shingoyamazaki00@gmail.com>

* refactor(data-loader): inline ActionProps into ActionPropertyForParameter

Co-authored-by: nakajmg <nakajima.jmg@gmail.com>
Co-authored-by: Shingo Yamazaki <shingoyamazaki00@gmail.com>
  • Loading branch information
3 people committed Apr 27, 2021
1 parent bcfe7ba commit bca0d98
Show file tree
Hide file tree
Showing 7 changed files with 302 additions and 10 deletions.
61 changes: 61 additions & 0 deletions examples/rest-api-client-demo/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,4 +703,65 @@ export class App {
console.log(error);
}
}

public async getAppActions() {
try {
console.log(await this.client.app.getAppActions({ app: APP_ID }));
} catch (error) {
console.log(error);
}
}

public async getAppActionsPreview() {
try {
console.log(
await this.client.app.getAppActions({ app: APP_ID, preview: true })
);
} catch (error) {
console.log(error);
}
}

public async updateAppActions() {
try {
console.log(
await this.client.app.updateAppActions({
app: APP_ID,
actions: {
Action_A: {
name: "Action_A",
index: "0",
destApp: {
code: "INVOICE",
},
mappings: [
{
srcType: "FIELD",
srcField: "CompanyName",
destField: "CompanyName",
},
{
srcType: "FIELD",
srcField: "DivisionName",
destField: "DivisionName",
},
{
srcType: "RECORD_URL",
destField: "URL",
},
],
entities: [
{
type: "USER",
code: "Administrator",
},
],
},
},
})
);
} catch (error) {
console.log(error);
}
}
}
54 changes: 49 additions & 5 deletions packages/rest-api-client/docs/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
- [updateReminderNotifications](#updateReminderNotifications)
- [getReports](#getReports)
- [updateReports](#updateReports)
- [getAppActions](#getAppActions)
- [updateAppActions](#updateAppActions)

## Overview

Expand Down Expand Up @@ -1260,11 +1262,6 @@ Updates the [Graph settings](https://get.kintone.help/k/en/user/app_settings/rep

#### Parameters

| Name | Type | Required | Description |
| ---- | :--: | :------: | ----------- |

#### Parameters

| Name | Type | Required | Description |
| ---------------------------------------------------- | :---------------: | :---------: | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| app | Number or String | Yes | The App ID. |
Expand Down Expand Up @@ -1307,3 +1304,50 @@ Updates the [Graph settings](https://get.kintone.help/k/en/user/app_settings/rep
#### Reference

- https://developer.kintone.io/hc/en-us/articles/900005300943

### getAppActions

Get the [Action](https://get.kintone.help/k/en/user/app_settings/appaction/set_appaction.html) settings of the 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>`default`: retrieves the default names</li><li>`en`: retrieves the localized English names</li><li>`zh`: retrieves the localized Chinese names</li><li>`ja`: retrieves the localized Japanese names</li><li>`user`: retrieves the localized names, in the same language as the language setting set on the user used for the authentication.</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. |
| 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://developer.kintone.io/hc/en-us/articles/900004690626) |

#### Reference

- https://developer.kintone.io/hc/en-us/articles/900004690626

### updateAppActions

Updates the [Action](https://get.kintone.help/k/en/user/app_settings/appaction/set_appaction.html) settings of the App.

#### Parameters

| Name | Type | Required | Description |
| -------- | :--------------: | :------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| app | Number or String | Yes | The App ID. |
| actions | Object | Yes | An object listing Action settings. <br/>For each property of this object, see “Request Parameters” section of [the reference](https://developer.kintone.io/hc/en-us/articles/900005635363) |
| revision | Number or String |   | Specify the revision number of the settings that will be deployed.<br>The request will fail if the revision number is not the latest revision.<br>The revision will not be checked if this parameter is ignored or `-1` is specified. |

#### Returns

| Name | Type | Description |
| ----------------------- | :----: | ---------------------------------------- |
| revision | String | The revision number of the App settings. |
| actions | Object | An object listing Action settings. |
| actions.{actionname}.id | String | The ID of the Action. |

#### Reference

- https://developer.kintone.io/hc/en-us/articles/900005635363
33 changes: 33 additions & 0 deletions packages/rest-api-client/src/client/AppClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import {
ReminderNotificationForResponse,
ReportForParameter,
ReportForResponse,
AppActionsForParameter,
AppActionsForResponse,
} from "./types";
type RowLayoutForParameter = {
type: "ROW";
Expand Down Expand Up @@ -588,6 +590,37 @@ export class AppClient {
return this.client.put(path, params);
}

public getAppActions(params: {
app: AppID;
lang?: Lang;
preview?: boolean;
}): Promise<{
actions: AppActionsForResponse;
revision: string;
}> {
const { preview, ...rest } = params;
const path = this.buildPathWithGuestSpaceId({
endpointName: "app/actions",
preview,
});
return this.client.get(path, rest);
}

public updateAppActions(params: {
app: AppID;
actions: AppActionsForParameter;
revision?: Revision;
}): Promise<{
revision: string;
actions: { [actionName: string]: { id: string } };
}> {
const path = this.buildPathWithGuestSpaceId({
endpointName: "app/actions",
preview: true,
});
return this.client.put(path, params);
}

private buildPathWithGuestSpaceId(params: {
endpointName: string;
preview?: boolean;
Expand Down
89 changes: 89 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 @@ -1220,6 +1220,95 @@ describe("AppClient", () => {
expect(mockClient.getLogs()[0].params).toEqual(params);
});
});

describe("getAppActions", () => {
const lang = "default";
const params = { app: APP_ID, lang } as const;
describe("without preview", () => {
beforeEach(async () => {
await appClient.getAppActions(params);
});
it("should pass the path to the http client", () => {
expect(mockClient.getLogs()[0].path).toBe("/k/v1/app/actions.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.getAppActions({
...params,
preview: true,
});
});
it("should pass the path to the http client", () => {
expect(mockClient.getLogs()[0].path).toBe(
"/k/v1/preview/app/actions.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("updateAppActions", () => {
const params = {
app: APP_ID,
actions: {
Action_A: {
name: "Action_A",
index: "0",
destApp: {
code: "INVOICE",
},
mappings: [
{
srcType: "FIELD" as const,
srcField: "CompanyName",
destField: "CompanyName",
},
{
srcType: "FIELD" as const,
srcField: "DivisionName",
destField: "DivisionName",
},
{
srcType: "RECORD_URL" as const,
destField: "URL",
},
],
entities: [
{
type: "USER" as const,
code: "Administrator",
},
],
},
},
};
beforeEach(async () => {
await appClient.updateAppActions(params);
});
it("should pass the path to the http client", () => {
expect(mockClient.getLogs()[0].path).toBe(
"/k/v1/preview/app/actions.json"
);
});
it("should send a put request", () => {
expect(mockClient.getLogs()[0].method).toBe("put");
});
it("should pass app and actions as a param to the http client", () => {
expect(mockClient.getLogs()[0].params).toEqual(params);
});
});
});

describe("AppClient with guestSpaceId", () => {
Expand Down
62 changes: 62 additions & 0 deletions packages/rest-api-client/src/client/types/app/action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Entity } from "../entity";
import { AppID } from "../index";

// --- Types for request ---

export type AppActionsForParameter = {
[actionName: string]: ActionPropertyForParameter;
};

type ActionPropertyForParameter = (
| {
destApp: DestAppForParameter;
mappings: Mapping[];
}
| {
mappings?: Mapping[];
}
) & {
name?: string;
index: string | number;
entities?: Entity[];
};

type DestAppForParameter =
| {
app: AppID;
code?: string;
}
| { app?: AppID; code: string };

// --- Types for response ---

export type AppActionsForResponse = {
[actionName: string]: ActionPropertyForResponse;
};

type ActionPropertyForResponse = {
name: string;
id: string;
index: string;
destApp: DestAppForResponse;
mappings: Mapping[];
entities: Entity[];
};

type DestAppForResponse = {
app: string;
code: string;
};

// --- Common types for both request and response ---

type Mapping =
| {
srcType: "FIELD";
srcField: string;
destField: string;
}
| {
srcType: "RECORD_URL";
destField: string;
};
1 change: 1 addition & 0 deletions packages/rest-api-client/src/client/types/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ export * from "./processManagement";
export * from "./customize";
export * from "./notification";
export * from "./report";
export * from "./action";
12 changes: 7 additions & 5 deletions packages/rest-api-client/src/client/types/app/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ type ChartProps = {
periodicReport?: PeriodicReportForParameters;
};

type ReportProperty =
| ({
type ReportProperty = (
| {
chartType: ChartTypeWithOptionalMode;
chartMode?: ChartMode;
} & ChartProps)
| ({
}
| {
chartType: ChartTypeWithRequiredMode;
chartMode: ChartMode;
} & ChartProps);
}
) &
ChartProps;

type PeriodicReportForParameters = {
active?: boolean | string;
Expand Down

0 comments on commit bca0d98

Please sign in to comment.