Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert the changes of moving common data models to interface file for externalAppCardAction(ForCEA) files #2535

Merged
merged 4 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { externalAppCardActions, IAdaptiveCardActionSubmit } from '@microsoft/teams-js';
import { externalAppCardActions } from '@microsoft/teams-js';
import React from 'react';

import { ApiWithoutInput, ApiWithTextInput } from '../utils';
Expand All @@ -15,7 +15,7 @@ const CheckExternalAppCardActionsCapability = (): React.ReactElement =>
const ProcessActionSubmit = (): React.ReactElement =>
ApiWithTextInput<{
appId: string;
actionSubmitPayload: IAdaptiveCardActionSubmit;
actionSubmitPayload: externalAppCardActions.IAdaptiveCardActionSubmit;
}>({
name: 'processActionSubmit',
title: 'Process Action Submit',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AppId, externalAppCardActionsForCEA, IAdaptiveCardActionSubmit } from '@microsoft/teams-js';
import { AppId, externalAppCardActions, externalAppCardActionsForCEA } from '@microsoft/teams-js';
import React from 'react';

import { ApiWithoutInput, ApiWithTextInput } from '../utils';
Expand All @@ -18,7 +18,7 @@ const ProcessActionSubmitForCEA = (): React.ReactElement =>
ApiWithTextInput<{
appId: string;
conversationId: string;
actionSubmitPayload: IAdaptiveCardActionSubmit;
actionSubmitPayload: externalAppCardActions.IAdaptiveCardActionSubmit;
}>({
name: 'processActionSubmitForCEA',
title: 'Process Action Submit For CEA',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Unified common data models for external card actions into `externalAppCardActions` namespace.",
"packageName": "@microsoft/teams-js",
"email": "[email protected]",
"dependentChangeType": "patch"
}
58 changes: 57 additions & 1 deletion packages/teams-js/src/private/externalAppCardActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ApiName, ApiVersionNumber, getApiVersionTag } from '../internal/telemet
import { AppId } from '../public';
import { errorNotSupportedOnPlatform, FrameContexts } from '../public/constants';
import { runtime } from '../public/runtime';
import { ActionOpenUrlError, ActionSubmitError, IAdaptiveCardActionSubmit } from './interfaces';
import { ExternalAppErrorCode } from './constants';

/**
* v2 APIs telemetry file: All of APIs in this capability file should send out API version v2 ONLY
Expand All @@ -31,6 +31,62 @@ export namespace externalAppCardActions {
GenericUrl = 'GenericUrl',
}

/**
* @beta
* @hidden
* Error that can be thrown from IExternalAppCardActionService.handleActionOpenUrl
* and IExternalAppCardActionForCEAService.handleActionOpenUrl
*
* @internal
* Limited to Microsoft-internal use
*/
export interface ActionOpenUrlError {
errorCode: ActionOpenUrlErrorCode;
message?: string;
}

/**
* @beta
* @hidden
* Error codes that can be thrown from IExternalAppCardActionService.handleActionOpenUrl
* and IExternalAppCardActionForCEAService.handleActionOpenUrl
*
* @internal
* Limited to Microsoft-internal use
*/
export enum ActionOpenUrlErrorCode {
INTERNAL_ERROR = 'INTERNAL_ERROR', // Generic error
INVALID_LINK = 'INVALID_LINK', // Deep link is invalid
NOT_SUPPORTED = 'NOT_SUPPORTED', // Deep link is not supported
}

/**
* @beta
* @hidden
* The payload that is used when executing an Adaptive Card Action.Submit
*
* @internal
* Limited to Microsoft-internal use
*/
export interface IAdaptiveCardActionSubmit {
id: string;
data: string | Record<string, unknown>;
}

/**
* @beta
* @hidden
* Error that can be thrown from IExternalAppCardActionService.handleActionSubmit
* and IExternalAppCardActionForCEAService.handleActionSubmit
*
* @internal
* Limited to Microsoft-internal use
*/
export interface ActionSubmitError {
errorCode: ExternalAppErrorCode;
message?: string;
}

/**
* @beta
* @hidden
Expand Down
12 changes: 7 additions & 5 deletions packages/teams-js/src/private/externalAppCardActionsForCEA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { validateId } from '../internal/utils';
import { AppId } from '../public';
import { errorNotSupportedOnPlatform, FrameContexts } from '../public/constants';
import { runtime } from '../public/runtime';
import { ActionOpenUrlError, ActionOpenUrlType, ActionSubmitError, IAdaptiveCardActionSubmit } from './interfaces';
import { externalAppCardActions } from './externalAppCardActions';

/**
* All of APIs in this capability file should send out API version v2 ONLY
Expand Down Expand Up @@ -35,13 +35,15 @@ export namespace externalAppCardActionsForCEA {
appId: AppId,
conversationId: string,
url: URL,
): Promise<ActionOpenUrlType> {
): Promise<externalAppCardActions.ActionOpenUrlType> {
ensureInitialized(runtime, FrameContexts.content);
if (!isSupported()) {
throw errorNotSupportedOnPlatform;
}
validateId(conversationId, new Error('conversation id is not valid.'));
const [error, response] = await sendMessageToParentAsync<[ActionOpenUrlError, ActionOpenUrlType]>(
const [error, response] = await sendMessageToParentAsync<
[externalAppCardActions.ActionOpenUrlError, externalAppCardActions.ActionOpenUrlType]
>(
getApiVersionTag(
externalAppCardActionsTelemetryVersionNumber,
ApiName.ExternalAppCardActionsForCEA_ProcessActionOpenUrl,
Expand Down Expand Up @@ -71,14 +73,14 @@ export namespace externalAppCardActionsForCEA {
export async function processActionSubmit(
appId: AppId,
conversationId: string,
actionSubmitPayload: IAdaptiveCardActionSubmit,
actionSubmitPayload: externalAppCardActions.IAdaptiveCardActionSubmit,
): Promise<void> {
ensureInitialized(runtime, FrameContexts.content);
if (!isSupported()) {
throw errorNotSupportedOnPlatform;
}
validateId(conversationId, new Error('conversation id is not valid.'));
const error = await sendAndUnwrap<ActionSubmitError | undefined>(
const error = await sendAndUnwrap<externalAppCardActions.ActionSubmitError | undefined>(
getApiVersionTag(
externalAppCardActionsTelemetryVersionNumber,
ApiName.ExternalAppCardActionsForCEA_ProcessActionSubmit,
Expand Down
72 changes: 0 additions & 72 deletions packages/teams-js/src/private/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { FileOpenPreference, TeamInformation } from '../public/interfaces';
import { ExternalAppErrorCode } from './constants';

/**
* @hidden
Expand Down Expand Up @@ -272,74 +271,3 @@ export interface UserJoinedTeamsInformation {
*/
userJoinedTeams: TeamInformation[];
}

/**
* @beta
* @hidden
* The types for ActionOpenUrl
*
* @internal
* Limited to Microsoft-internal use
*/
export enum ActionOpenUrlType {
DeepLinkDialog = 'DeepLinkDialog',
DeepLinkOther = 'DeepLinkOther',
DeepLinkStageView = 'DeepLinkStageView',
GenericUrl = 'GenericUrl',
}

/**
* @beta
* @hidden
* Error that can be thrown from IExternalAppCardActionService.handleActionOpenUrl
* and IExternalAppCardActionForCEAService.handleActionOpenUrl
*
* @internal
* Limited to Microsoft-internal use
*/
export interface ActionOpenUrlError {
errorCode: ActionOpenUrlErrorCode;
message?: string;
}

/**
* @beta
* @hidden
* Error codes that can be thrown from IExternalAppCardActionService.handleActionOpenUrl
* and IExternalAppCardActionForCEAService.handleActionOpenUrl
*
* @internal
* Limited to Microsoft-internal use
*/
export enum ActionOpenUrlErrorCode {
INTERNAL_ERROR = 'INTERNAL_ERROR', // Generic error
INVALID_LINK = 'INVALID_LINK', // Deep link is invalid
NOT_SUPPORTED = 'NOT_SUPPORTED', // Deep link is not supported
}

/**
* @beta
* @hidden
* The payload that is used when executing an Adaptive Card Action.Submit
*
* @internal
* Limited to Microsoft-internal use
*/
export interface IAdaptiveCardActionSubmit {
id: string;
data: string | Record<string, unknown>;
}

/**
* @beta
* @hidden
* Error that can be thrown from IExternalAppCardActionService.handleActionSubmit
* and IExternalAppCardActionForCEAService.handleActionSubmit
*
* @internal
* Limited to Microsoft-internal use
*/
export interface ActionSubmitError {
errorCode: ExternalAppErrorCode;
message?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { errorLibraryNotInitialized } from '../../src/internal/constants';
import { GlobalVars } from '../../src/internal/globalVars';
import { ExternalAppErrorCode } from '../../src/private/constants';
import { externalAppCardActions } from '../../src/private/externalAppCardActions';
import { ActionOpenUrlErrorCode } from '../../src/private/interfaces';
import { FrameContexts } from '../../src/public';
import { app } from '../../src/public/app';
import { errorNotSupportedOnPlatform } from '../../src/public/constants';
Expand Down Expand Up @@ -128,7 +127,7 @@ describe('externalAppCardActions', () => {
const allowedFrameContexts = [FrameContexts.content];
const testUrl = new URL('https://example.com');
const testError = {
errorCode: ActionOpenUrlErrorCode.INTERNAL_ERROR,
errorCode: externalAppCardActions.ActionOpenUrlErrorCode.INTERNAL_ERROR,
message: 'testMessage',
};
const testResponse = externalAppCardActions.ActionOpenUrlType.DeepLinkDialog;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { errorLibraryNotInitialized } from '../../src/internal/constants';
import { GlobalVars } from '../../src/internal/globalVars';
import { ApiName } from '../../src/internal/telemetry';
import { ExternalAppErrorCode } from '../../src/private/constants';
import { externalAppCardActions } from '../../src/private/externalAppCardActions';
import { externalAppCardActionsForCEA } from '../../src/private/externalAppCardActionsForCEA';
import { ActionOpenUrlErrorCode, ActionOpenUrlType } from '../../src/private/interfaces';
import { AppId, FrameContexts } from '../../src/public';
import { app } from '../../src/public/app';
import { errorNotSupportedOnPlatform } from '../../src/public/constants';
Expand Down Expand Up @@ -123,10 +123,10 @@ describe('externalAppCardActionsForCEA', () => {
const allowedFrameContexts = [FrameContexts.content];
const testUrl = new URL('https://example.com');
const testError = {
errorCode: ActionOpenUrlErrorCode.INTERNAL_ERROR,
errorCode: externalAppCardActions.ActionOpenUrlErrorCode.INTERNAL_ERROR,
message: 'testMessage',
};
const testResponse = ActionOpenUrlType.DeepLinkDialog;
const testResponse = externalAppCardActions.ActionOpenUrlType.DeepLinkDialog;

it('should not allow calls before initialization', async () => {
expect.assertions(1);
Expand Down