Skip to content

Commit

Permalink
Merge pull request #494 from uploadcare/feature/document-info
Browse files Browse the repository at this point in the history
feat(rest-client): add Document Info endpoint
  • Loading branch information
wreckah authored Nov 13, 2023
2 parents 8e06a32 + 30bbbcc commit a489690
Show file tree
Hide file tree
Showing 3 changed files with 58 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] })
}
5 changes: 5 additions & 0 deletions packages/rest-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ export {

/** Low-level Conversion API */
export { convert } from './api/conversion/convert'
export {
conversionInfo,
ConversionInfoOptions,
ConversionInfoResponse
} from './api/conversion/conversionInfo'
export { conversionJobStatus } from './api/conversion/conversionJobStatus'

/** Low-level Addons API */
Expand Down

0 comments on commit a489690

Please sign in to comment.