From bca0d9805636423c9de5694ea8f908149c9ff65f Mon Sep 17 00:00:00 2001 From: tasshi / Masaharu TASHIRO <33759872+mshrtsr@users.noreply.github.com> Date: Tue, 27 Apr 2021 05:26:25 +0000 Subject: [PATCH] feat(rest-api-client): Support App Action Settings API (#833) * 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 * refactor(data-loader): inline ActionProps into ActionPropertyForParameter Co-authored-by: nakajmg Co-authored-by: Shingo Yamazaki --- examples/rest-api-client-demo/src/app.ts | 61 +++++++++++++ packages/rest-api-client/docs/app.md | 54 +++++++++-- .../rest-api-client/src/client/AppClient.ts | 33 +++++++ .../src/client/__tests__/AppClient.test.ts | 89 +++++++++++++++++++ .../src/client/types/app/action.ts | 62 +++++++++++++ .../src/client/types/app/index.ts | 1 + .../src/client/types/app/report.ts | 12 +-- 7 files changed, 302 insertions(+), 10 deletions(-) create mode 100644 packages/rest-api-client/src/client/types/app/action.ts diff --git a/examples/rest-api-client-demo/src/app.ts b/examples/rest-api-client-demo/src/app.ts index c2480e340d..a327d908fc 100644 --- a/examples/rest-api-client-demo/src/app.ts +++ b/examples/rest-api-client-demo/src/app.ts @@ -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); + } + } } diff --git a/packages/rest-api-client/docs/app.md b/packages/rest-api-client/docs/app.md index 168fc7d9c9..f8456e1188 100644 --- a/packages/rest-api-client/docs/app.md +++ b/packages/rest-api-client/docs/app.md @@ -34,6 +34,8 @@ - [updateReminderNotifications](#updateReminderNotifications) - [getReports](#getReports) - [updateReports](#updateReports) +- [getAppActions](#getAppActions) +- [updateAppActions](#updateAppActions) ## Overview @@ -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. | @@ -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:
  • `default`: retrieves the default names
  • `en`: retrieves the localized English names
  • `zh`: retrieves the localized Chinese names
  • `ja`: retrieves the localized Japanese names
  • `user`: retrieves the localized names, in the same language as the language setting set on the user used for the authentication.
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.
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.
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.
The request will fail if the revision number is not the latest revision.
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 diff --git a/packages/rest-api-client/src/client/AppClient.ts b/packages/rest-api-client/src/client/AppClient.ts index a887049698..ac3b504064 100644 --- a/packages/rest-api-client/src/client/AppClient.ts +++ b/packages/rest-api-client/src/client/AppClient.ts @@ -33,6 +33,8 @@ import { ReminderNotificationForResponse, ReportForParameter, ReportForResponse, + AppActionsForParameter, + AppActionsForResponse, } from "./types"; type RowLayoutForParameter = { type: "ROW"; @@ -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; 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 4375318c29..e21a9dc890 100644 --- a/packages/rest-api-client/src/client/__tests__/AppClient.test.ts +++ b/packages/rest-api-client/src/client/__tests__/AppClient.test.ts @@ -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", () => { diff --git a/packages/rest-api-client/src/client/types/app/action.ts b/packages/rest-api-client/src/client/types/app/action.ts new file mode 100644 index 0000000000..4d4977d170 --- /dev/null +++ b/packages/rest-api-client/src/client/types/app/action.ts @@ -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; + }; 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 e0c976e524..9796574602 100644 --- a/packages/rest-api-client/src/client/types/app/index.ts +++ b/packages/rest-api-client/src/client/types/app/index.ts @@ -24,3 +24,4 @@ export * from "./processManagement"; export * from "./customize"; export * from "./notification"; export * from "./report"; +export * from "./action"; diff --git a/packages/rest-api-client/src/client/types/app/report.ts b/packages/rest-api-client/src/client/types/app/report.ts index f0ed5850c2..d081282677 100644 --- a/packages/rest-api-client/src/client/types/app/report.ts +++ b/packages/rest-api-client/src/client/types/app/report.ts @@ -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;