From 7f0c5280108426e95664c1fb9ae4ec429b9a8c97 Mon Sep 17 00:00:00 2001 From: Alexander Perlamutrov Date: Sat, 11 Nov 2023 00:30:11 +0300 Subject: [PATCH] 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 */