Skip to content

Commit b14dcb3

Browse files
feat/EXT-6729/app-action-createWithResult (#10108)
fix: better schema validation with CMA changes - Upgrade CMA to version 11.58.1 - `AppActionCall.sys.result` and `AppActionCall.sys.error` exist when `AppActionCall.sys.status` exist. CMA changes are [here](contentful/contentful-management.js#2758). - Use typebox schemas for better assertions and schema validation - Corresponding unit tests for validations
1 parent 00d3be6 commit b14dcb3

30 files changed

Lines changed: 12658 additions & 13467 deletions

apps/microsoft-teams/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@contentful:registry=https://registry.npmjs.org/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@contentful:registry=https://registry.npmjs.org/

apps/microsoft-teams/app-actions/package-lock.json

Lines changed: 835 additions & 1408 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/microsoft-teams/app-actions/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"dependencies": {
1515
"@contentful/node-apps-toolkit": "^2.6.0",
16-
"contentful-management": "^11.38.0",
16+
"contentful-management": "^11.56.0",
1717
"mocha": "^10.8.2",
1818
"sinon": "^19.0.2"
1919
},

apps/microsoft-teams/app-actions/src/actions/handle-app-event.spec.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ import sinonChai from 'sinon-chai';
44
import { AppInstallationProps } from 'contentful-management';
55
import { AppActionCallContext } from '@contentful/node-apps-toolkit';
66
import {
7-
AppActionCallResponseError,
8-
AppActionCallResponseSuccess,
97
EntryActivity,
108
SendEntryActivityMessageResult,
119
MsTeamsBotServiceResponse,
12-
MessageResponse,
1310
SendWorkflowUpdateMessageResult,
1411
} from '../types';
12+
import { MessageResponse, AppActionResultSuccess, AppActionResultError } from '../../../types';
1513
import { makeMockAppActionCallContext, mockAppInstallation, mockEntry } from '../../test/mocks';
1614
import { handler } from './handle-app-event';
1715
import helpers from '../helpers';
@@ -53,7 +51,7 @@ describe('handle-app-event.handler', () => {
5351
eventDatetime: '2024-01-18T21:43:54.267Z',
5452
},
5553
context
56-
)) as AppActionCallResponseSuccess<SendEntryActivityMessageResult[]>;
54+
)) as AppActionResultSuccess<SendEntryActivityMessageResult[]>;
5755

5856
expect(result).to.have.property('ok', true);
5957
expect(result.data).to.deep.include({
@@ -89,7 +87,7 @@ describe('handle-app-event.handler', () => {
8987
eventDatetime: '2024-01-18T21:43:54.267Z',
9088
},
9189
context
92-
)) as AppActionCallResponseSuccess<SendWorkflowUpdateMessageResult>;
90+
)) as AppActionResultSuccess<SendWorkflowUpdateMessageResult>;
9391

9492
expect(result.ok).to.equal(true);
9593
expect(result.data.sendWorkflowUpdateResult.ok).to.equal(true);
@@ -113,7 +111,7 @@ describe('handle-app-event.handler', () => {
113111
eventDatetime: '2024-01-18T21:43:54.267Z',
114112
},
115113
context
116-
)) as AppActionCallResponseError;
114+
)) as AppActionResultError;
117115

118116
expect(result).to.have.property('ok', false);
119117
expect(result.error).to.have.property('type', 'Error');

apps/microsoft-teams/app-actions/src/actions/handle-app-event.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { AppActionCallContext } from '@contentful/node-apps-toolkit';
22
import {
3-
AppActionCallResponse,
43
EntryActivityMessage,
54
SendEntryActivityMessageResult,
65
SendWorkflowUpdateMessageResult,
76
Topic,
87
WorkflowPayload,
98
WorkflowUpdateMessage,
109
} from '../types';
10+
import { AppActionResult } from '../../../types';
1111
import { EntryProps } from 'contentful-management/types';
1212
import helpers from '../helpers';
1313
import { parametersFromAppInstallation } from '../helpers/app-installation';
@@ -26,7 +26,7 @@ export const handler = withAsyncAppActionErrorHandling(
2626
parameters: AppActionCallParameters,
2727
context: AppActionCallContext
2828
): Promise<
29-
AppActionCallResponse<SendEntryActivityMessageResult[] | SendWorkflowUpdateMessageResult>
29+
AppActionResult<SendEntryActivityMessageResult[] | SendWorkflowUpdateMessageResult>
3030
> => {
3131
const {
3232
cma,

apps/microsoft-teams/app-actions/src/actions/list-channels.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import sinonChai from 'sinon-chai';
44
import { AppInstallationProps, SysLink } from 'contentful-management';
55
import { AppActionCallContext } from '@contentful/node-apps-toolkit';
66
import { handler } from './list-channels';
7-
import { AppActionCallResponseSuccess, Channel } from '../types';
7+
import { AppActionResultSuccess } from '../../../types';
8+
import { Channel } from '../../../types';
89
import { makeMockAppActionCallContext, mockChannels } from '../../test/mocks';
910
import helpers from '../helpers';
1011

@@ -22,6 +23,7 @@ describe('listChannels.handler', () => {
2223
appDefinition: {} as SysLink,
2324
environment: {} as SysLink,
2425
space: {} as SysLink,
26+
organization: {} as SysLink,
2527
version: 1,
2628
createdAt: 'createdAt',
2729
updatedAt: 'updatedAt',
@@ -44,7 +46,7 @@ describe('listChannels.handler', () => {
4446
tenantId,
4547
},
4648
context
47-
)) as AppActionCallResponseSuccess<Channel[]>;
49+
)) as AppActionResultSuccess<Channel[]>;
4850

4951
expect(result).to.have.property('ok', true);
5052
expect(result).to.have.property('data', mockChannels);

apps/microsoft-teams/app-actions/src/actions/list-channels.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
import { AppActionCallContext } from '@contentful/node-apps-toolkit';
2-
import { AppActionCallResponse, Channel } from '../types';
2+
import { AppActionResult, Channel } from '../../../types';
33
import { fetchTenantId } from '../utils';
44
import helpers from '../helpers';
55
import { withAsyncAppActionErrorHandling } from '../helpers/error-handling';
66

77
export const handler = withAsyncAppActionErrorHandling(
8-
async (
9-
_payload: {},
10-
context: AppActionCallContext
11-
): Promise<AppActionCallResponse<Channel[]>> => {
8+
async (_payload: {}, context: AppActionCallContext): Promise<AppActionResult<Channel[]>> => {
129
const {
1310
cma,
14-
appActionCallContext: { appInstallationId, userId, environmentId, spaceId },
11+
appActionCallContext: { appInstallationId: appDefinitionId, userId, environmentId, spaceId },
1512
} = context;
1613

17-
const tenantId = await fetchTenantId(cma, appInstallationId);
18-
const channels = await helpers.getChannelsList(tenantId, {
19-
appInstallationId,
14+
const tenantId = await fetchTenantId(cma, appDefinitionId);
15+
let channels: Channel[] = [];
16+
channels = await helpers.getChannelsList(tenantId, {
17+
appInstallationId: appDefinitionId,
2018
userId,
2119
environmentId,
2220
spaceId,

apps/microsoft-teams/app-actions/src/actions/send-test.spec.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {
99
AppInstallationProps,
1010
} from 'contentful-management';
1111
import { AppActionCallContext } from '@contentful/node-apps-toolkit';
12-
import helpers from '../helpers';
13-
import { AppActionCallResponseSuccess, MessageResponse, MsTeamsBotServiceResponse } from '../types';
12+
import { MsTeamsBotServiceResponse } from '../types';
13+
import { AppActionResultSuccess, MessageResponse } from '../../../types';
1414
import { MsTeamsBotService } from '../services/msteams-bot-service';
1515
import { config } from '../config';
1616

@@ -51,6 +51,7 @@ describe('sendTestMessage.handler', () => {
5151
appDefinition: {} as SysLink,
5252
environment: {} as SysLink,
5353
space: {} as SysLink,
54+
organization: {} as SysLink,
5455
version: 1,
5556
createdAt: 'createdAt',
5657
updatedAt: 'updatedAt',
@@ -78,10 +79,7 @@ describe('sendTestMessage.handler', () => {
7879
});
7980

8081
it('returns the ok result', async () => {
81-
const result = (await handler(
82-
parameters,
83-
context
84-
)) as AppActionCallResponseSuccess<MessageResponse>;
82+
const result = (await handler(parameters, context)) as AppActionResultSuccess<MessageResponse>;
8583
expect(result).to.have.property('ok', true);
8684
expect(result.data).to.have.property('messageResponseId', 'message-response-id');
8785
});

apps/microsoft-teams/app-actions/src/actions/send-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AppActionCallContext } from '@contentful/node-apps-toolkit';
2-
import { AppActionCallResponse, MessageResponse } from '../types';
2+
import { AppActionResult, MessageResponse } from '../../../types';
33
import { fetchTenantId } from '../utils';
44
import { config } from '../config';
55
import { withAsyncAppActionErrorHandling } from '../helpers/error-handling';
@@ -14,7 +14,7 @@ export const handler = withAsyncAppActionErrorHandling(
1414
async (
1515
payload: AppActionCallParameters,
1616
context: AppActionCallContext
17-
): Promise<AppActionCallResponse<MessageResponse>> => {
17+
): Promise<AppActionResult<MessageResponse>> => {
1818
const { channelId, teamId, contentTypeId } = payload;
1919
const {
2020
cma,

0 commit comments

Comments
 (0)