From 7f0c5280108426e95664c1fb9ae4ec429b9a8c97 Mon Sep 17 00:00:00 2001 From: Alexander Perlamutrov Date: Sat, 11 Nov 2023 00:30:11 +0300 Subject: [PATCH 1/2] feat(rest-client): add Document Info endpoint --- .../src/api/conversion/conversionInfo.test.ts | 22 +++++++++++++ .../src/api/conversion/conversionInfo.ts | 31 +++++++++++++++++++ packages/rest-client/src/index.ts | 1 + 3 files changed, 54 insertions(+) create mode 100644 packages/rest-client/src/api/conversion/conversionInfo.test.ts create mode 100644 packages/rest-client/src/api/conversion/conversionInfo.ts diff --git a/packages/rest-client/src/api/conversion/conversionInfo.test.ts b/packages/rest-client/src/api/conversion/conversionInfo.test.ts new file mode 100644 index 000000000..5f315faf4 --- /dev/null +++ b/packages/rest-client/src/api/conversion/conversionInfo.test.ts @@ -0,0 +1,22 @@ +import { describe, it } from '@jest/globals' + +import 'jest-extended' +import { DOCUMENT_UUID } from '../../../test/fixtures' +import { testSettings } from '../../../test/helpers' +import { conversionInfo } from './conversionInfo' + +describe('conversionInfo', () => { + it('should work with txt document', async () => { + const { error, format } = await conversionInfo( + { uuid: DOCUMENT_UUID }, + testSettings + ) + + expect(error).toBeNull() + expect(format.name).toEqual('txt') + expect(format.conversionFormats).toBeArray() + expect(format.conversionFormats.map(({ name }) => name)).toContain( + 'pdf' + ) + }) +}) diff --git a/packages/rest-client/src/api/conversion/conversionInfo.ts b/packages/rest-client/src/api/conversion/conversionInfo.ts new file mode 100644 index 000000000..70a74270c --- /dev/null +++ b/packages/rest-client/src/api/conversion/conversionInfo.ts @@ -0,0 +1,31 @@ +import { ApiRequestSettings, makeApiRequest } from '../../makeApiRequest' +import { handleApiRequest } from '../handleApiRequest' + +export type ConversionInfoOptions = { + uuid: string +} + +export type ConversionInfoResponse = { + error: string | null + format: { + name: string + conversionFormats: { + name: string + }[] + } + convertedGroups: Record +} + +export async function conversionInfo( + options: ConversionInfoOptions, + userSettings: ApiRequestSettings +): Promise { + const apiRequest = await makeApiRequest( + { + method: 'GET', + path: `/convert/document/${options.uuid}/` + }, + userSettings + ) + return handleApiRequest({ apiRequest, okCodes: [200] }) +} diff --git a/packages/rest-client/src/index.ts b/packages/rest-client/src/index.ts index 9c10c1cae..1fe4a32a0 100644 --- a/packages/rest-client/src/index.ts +++ b/packages/rest-client/src/index.ts @@ -197,6 +197,7 @@ export { /** Low-level Conversion API */ export { convert } from './api/conversion/convert' +export { conversionInfo } from './api/conversion/conversionInfo' export { conversionJobStatus } from './api/conversion/conversionJobStatus' /** Low-level Addons API */ From 30bbbcc09abd0aa078c1ff28f69a1b13ae45ccf4 Mon Sep 17 00:00:00 2001 From: Alexander Perlamutrov Date: Sat, 11 Nov 2023 13:50:19 +0300 Subject: [PATCH 2/2] Fix review issue --- packages/rest-client/src/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/rest-client/src/index.ts b/packages/rest-client/src/index.ts index 1fe4a32a0..5ebec750a 100644 --- a/packages/rest-client/src/index.ts +++ b/packages/rest-client/src/index.ts @@ -197,7 +197,11 @@ export { /** Low-level Conversion API */ export { convert } from './api/conversion/convert' -export { conversionInfo } from './api/conversion/conversionInfo' +export { + conversionInfo, + ConversionInfoOptions, + ConversionInfoResponse +} from './api/conversion/conversionInfo' export { conversionJobStatus } from './api/conversion/conversionJobStatus' /** Low-level Addons API */