Skip to content

Commit

Permalink
feat(rest-api-client): add app.updateAdminNotes method
Browse files Browse the repository at this point in the history
  • Loading branch information
shabaraba committed Jun 28, 2024
1 parent 1bcbcef commit 89670b3
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
15 changes: 15 additions & 0 deletions examples/rest-api-client-demo/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,4 +774,19 @@ export class App {
console.log(error);
}
}

public async updateAdminNotes() {
try {
console.log(
await this.client.app.updateAdminNotes({
app: APP_ID,
content: "updated content via rest-api-client",
includeInTemplateAndDuplicates: true,
revision: -1,
}),
);
} catch (error) {
console.log(error);
}
}
}
24 changes: 24 additions & 0 deletions packages/rest-api-client/docs/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- [getAppActions](#getAppActions)
- [updateAppActions](#updateAppActions)
- [getAdminNotes](#getAdminNotes)
- [updateAdminNotes](#updateAdminNotes)

## Overview

Expand Down Expand Up @@ -1377,3 +1378,26 @@ Gets notes for app administrators and their settings.
#### Reference

- https://kintone.dev/en/docs/kintone/rest-api/apps/get-app-admin-notes/

### updateAdminNotes

Updates the notes for App administrators and their settings.

#### Parameters

| Name | Type | Required | Description |
| ------------------------------ | :--------------: | :------: | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| app | Number or String | Yes | The App ID. |
| content | String | | The content of the notes.<br />The content must be between 0 to 10000 characters.<br />If the parameter is omitted, the content will not change. |
| includeInTemplateAndDuplicates | Boolean | | The permission settings to include this note in app templates or duplicates. |
| revision | String | | The revision number of the App settings. |

#### Returns

| Name | Type | Description |
| -------- | :----: | ---------------------------------------------------- |
| revision | String | The revision number after changing the app settings. |

#### Reference

- https://kintone.dev/en/docs/kintone/rest-api/apps/update-app-admin-notes/
11 changes: 11 additions & 0 deletions packages/rest-api-client/src/client/AppClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import type {
AppActionsForParameter,
AppActionsForResponse,
AdminNotes,
AdminNoteForParameter,
} from "./types";
import { BaseClient } from "./BaseClient";
type RowLayoutForParameter = {
Expand Down Expand Up @@ -630,4 +631,14 @@ export class AppClient extends BaseClient {
});
return this.client.get(path, rest);
}

public updateAdminNotes(
params: AdminNoteForParameter,
): Promise<{ revision: string }> {
const path = this.buildPathWithGuestSpaceId({
endpointName: "app/adminNotes",
preview: true,
});
return this.client.put(path, params);
}
}
28 changes: 28 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 @@ -1310,7 +1310,20 @@ describe("AppClient", () => {
expect(mockClient.getLogs()[0].params).toEqual(params);
});
});
});

describe("AppClient: AdminNodes", () => {
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("getAdminNotes", () => {
const params = { app: APP_ID } as const;
describe("without preview", () => {
Expand Down Expand Up @@ -1347,6 +1360,21 @@ describe("AppClient", () => {
});
});
});
describe("updateAdminNotes", () => {
const params = { app: APP_ID } as const;
beforeEach(async () => {
await appClient.updateAdminNotes(params);
});
it("should pass the path to the http client", () => {
expect(mockClient.getLogs()[0].path).toBe("/k/v1/preview/app/adminNotes.json");
});
it("should send a put request", () => {
expect(mockClient.getLogs()[0].method).toBe("put");
});
it("should pass app, content, includeInTemplateAndDuplicates, and revision as a param to the http client", () => {
expect(mockClient.getLogs()[0].params).toEqual(params);
});
});
});

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

export type AdminNotes = {
content: string;
includeInTemplateAndDuplicates: boolean;
};

export type AdminNoteForParameter = Partial<AdminNotes> & {
app: AppID;
revision?: Revision;
};

0 comments on commit 89670b3

Please sign in to comment.