Skip to content

Commit

Permalink
feat(rest-client): add Document Info endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
wreckah committed Nov 10, 2023
1 parent 8e06a32 commit 7f0c528
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/rest-client/src/api/conversion/conversionInfo.test.ts
Original file line number Diff line number Diff line change
@@ -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<string>(({ name }) => name)).toContain(
'pdf'
)
})
})
31 changes: 31 additions & 0 deletions packages/rest-client/src/api/conversion/conversionInfo.ts
Original file line number Diff line number Diff line change
@@ -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<string, string>
}

export async function conversionInfo(
options: ConversionInfoOptions,
userSettings: ApiRequestSettings
): Promise<ConversionInfoResponse> {
const apiRequest = await makeApiRequest(
{
method: 'GET',
path: `/convert/document/${options.uuid}/`
},
userSettings
)
return handleApiRequest({ apiRequest, okCodes: [200] })
}
1 change: 1 addition & 0 deletions packages/rest-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 7f0c528

Please sign in to comment.