Skip to content

Commit 04cbf61

Browse files
committed
feat: add getAppActionCallResponse method to fetch raw response data
- Implemented `getAppActionCallResponse` method in the `createEnvironmentApi` to retrieve the raw response (headers/body) for completed App Action Calls. - Updated unit tests to validate the new API call functionality, ensuring correct request parameters and response handling.
1 parent 3ff9a26 commit 04cbf61

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

lib/create-environment-api.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import type { BasicQueryOptions, MakeRequest } from './common-types'
1111
import entities from './entities'
1212
import type { CreateAppInstallationProps } from './entities/app-installation'
1313
import type { CreateAppSignedRequestProps } from './entities/app-signed-request'
14-
import type { CreateAppActionCallProps } from './entities/app-action-call'
14+
import type {
15+
CreateAppActionCallProps,
16+
AppActionCallRawResponseProps,
17+
} from './entities/app-action-call'
1518
import type {
1619
AssetFileProp,
1720
AssetProps,
@@ -1597,6 +1600,46 @@ export default function createEnvironmentApi(makeRequest: MakeRequest) {
15971600
payload: data,
15981601
}).then((payload) => wrapAppActionCall(makeRequest, payload))
15991602
},
1603+
1604+
/**
1605+
* Gets the raw response (headers/body) for a completed App Action Call
1606+
* @param appDefinitionId - AppDefinition ID
1607+
* @param appActionId - App Action ID
1608+
* @param callId - App Action Call ID
1609+
* @return Promise for the raw response object including `response.body` and optional `response.headers`
1610+
* @example ```javascript
1611+
* const contentful = require('contentful-management')
1612+
*
1613+
* const client = contentful.createClient({
1614+
* accessToken: '<content_management_api_key>'
1615+
* })
1616+
*
1617+
* client
1618+
* .getSpace('<space_id>')
1619+
* .then((space) => space.getEnvironment('<environment_id>'))
1620+
* .then((environment) => environment.getAppActionCallResponse('<app_definition_id>', '<app_action_id>', '<call_id>'))
1621+
* .then((raw) => console.log(raw.response.body))
1622+
* .catch(console.error)
1623+
* ```
1624+
*/
1625+
getAppActionCallResponse(
1626+
appDefinitionId: string,
1627+
appActionId: string,
1628+
callId: string
1629+
): Promise<AppActionCallRawResponseProps> {
1630+
const raw = this.toPlainObject() as EnvironmentProps
1631+
return makeRequest({
1632+
entityType: 'AppActionCall',
1633+
action: 'getResponse',
1634+
params: {
1635+
spaceId: raw.sys.space.sys.id,
1636+
environmentId: raw.sys.id,
1637+
appDefinitionId,
1638+
appActionId,
1639+
callId,
1640+
},
1641+
})
1642+
},
16001643
/**
16011644
* Creates an app signed request
16021645
* @param appDefinitionId - AppDefinition ID

test/unit/create-environment-api.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { wrapAsset } from '../../lib/entities/asset'
3434
import { wrapTagCollection } from '../../lib/entities/tag'
3535
import setupMakeRequest from './mocks/makeRequest'
3636
import createEnvironmentApi from '../../lib/create-environment-api'
37+
import { AppActionCallRawResponseProps } from '../../lib/entities/app-action-call'
3738

3839
function setup<T>(promise: Promise<T>) {
3940
const entitiesMock = setupEntitiesMock()
@@ -540,6 +541,38 @@ describe('A createEnvironmentApi', () => {
540541
})
541542
})
542543

544+
test('API call getAppActionCallResponse', async () => {
545+
const rawResponse: AppActionCallRawResponseProps = {
546+
sys: {
547+
id: 'call-1',
548+
type: 'AppActionCallResponse',
549+
space: { sys: { type: 'Link', linkType: 'Space', id: 'spaceId' } },
550+
environment: { sys: { type: 'Link', linkType: 'Environment', id: 'envId' } },
551+
appInstallation: { sys: { type: 'Link', linkType: 'AppInstallation', id: 'appDef' } },
552+
appAction: { sys: { type: 'Link', linkType: 'AppAction', id: 'actionId' } },
553+
createdAt: new Date().toISOString(),
554+
},
555+
response: { body: '{"ok":true}' },
556+
}
557+
558+
const { api, makeRequest } = setup(Promise.resolve(rawResponse))
559+
560+
const result = await api.getAppActionCallResponse('appDef', 'actionId', 'call-1')
561+
562+
expect(result).to.eql(rawResponse)
563+
expect(makeRequest).toHaveBeenCalledWith({
564+
entityType: 'AppActionCall',
565+
action: 'getResponse',
566+
params: {
567+
spaceId: environmentMock.sys.space.sys.id,
568+
environmentId: environmentMock.sys.id,
569+
appDefinitionId: 'appDef',
570+
appActionId: 'actionId',
571+
callId: 'call-1',
572+
},
573+
})
574+
})
575+
543576
test('API call getAppInstallation', async () => {
544577
return makeGetEntityTest(setup, {
545578
entityType: 'appInstallation',

0 commit comments

Comments
 (0)