Skip to content

Commit

Permalink
[Task] Programmatically access the "real" App ID and Manifest Version (
Browse files Browse the repository at this point in the history
…#2694)

* add real app id

* added deserializes

* add unit tests to valid the appId and manigestVersion

* Added mockAppId and mockManifestVersion constants
  • Loading branch information
MengyiGong authored Feb 3, 2025
1 parent 87cce22 commit 3d6ab5d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Added the new parameters to `app.getContext` named `appId` and `manifestVersion`",
"packageName": "@microsoft/teams-js",
"email": "[email protected]",
"dependentChangeType": "patch"
}
13 changes: 13 additions & 0 deletions packages/teams-js/src/public/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ensureInitializeCalled } from '../../internal/internalAPIs';
import { ApiName, ApiVersionNumber, getApiVersionTag, getLogger } from '../../internal/telemetry';
import { inServerSideRenderingEnvironment } from '../../internal/utils';
import * as messageChannels from '../../private/messageChannels/messageChannels';
import { AppId } from '../appId';
import { ChannelType, FrameContexts, HostClientType, HostName, TeamType, UserTeamRole } from '../constants';
import {
ActionInfo,
Expand Down Expand Up @@ -185,6 +186,16 @@ export interface AppInfo {
* ID for the current visible app which is different for across cached sessions. Used for correlating telemetry data.
*/
appLaunchId?: string;

/**
* This ID is the unique identifier assigned to the app after deployment and is critical for ensuring the correct app instance is recognized across hosts.
*/
appId?: AppId;

/**
* The version of the manifest that the app is running.
*/
manifestVersion?: string;
}

/**
Expand Down Expand Up @@ -805,6 +816,8 @@ function transformLegacyContextToAppContext(legacyContext: LegacyContext): Conte
ringId: legacyContext.ringId,
},
appLaunchId: legacyContext.appLaunchId,
appId: legacyContext.appId ? new AppId(legacyContext.appId) : undefined,
manifestVersion: legacyContext.manifestVersion,
},
page: {
id: legacyContext.entityId,
Expand Down
16 changes: 16 additions & 0 deletions packages/teams-js/src/public/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,22 @@ export interface Context {
* They help pre-fill the dialog with necessary information (`dialogParameters`) along with other details.
*/
dialogParameters?: Record<string, string>;

/**
* @deprecated
* As of TeamsJS v2.0.0, please use {@link app.AppInfo.appId | app.Context.app.appId} instead
*
* This ID is the unique identifier assigned to the app after deployment and is critical for ensuring the correct app instance is recognized across hosts.
*/
appId?: string;

/**
* @deprecated
* As of TeamsJS v2.0.0, please use {@link app.AppInfo.manifestVersion | app.Context.app.manifestVersion} instead
*
* The version of the manifest that the app is running.
*/
manifestVersion?: string;
}

/** Represents the parameters used to share a deep link. */
Expand Down
11 changes: 10 additions & 1 deletion packages/teams-js/test/public/app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { errorLibraryNotInitialized } from '../../src/internal/constants';
import { GlobalVars } from '../../src/internal/globalVars';
import { DOMMessageEvent } from '../../src/internal/interfaces';
import { ensureInitialized } from '../../src/internal/internalAPIs';
import { authentication, dialog, menus, pages } from '../../src/public';
import { AppId, authentication, dialog, menus, pages } from '../../src/public';
import * as app from '../../src/public/app/app';
import {
ChannelType,
Expand Down Expand Up @@ -511,6 +511,8 @@ describe('Testing app capability', () => {
},
];

const mockAppIdString = 'mock.m365testapp.test';
const mockManifestVersion = '1.13';
const contextBridge: Context = {
actionInfo: {
actionId: 'actionId',
Expand Down Expand Up @@ -568,6 +570,8 @@ describe('Testing app capability', () => {
appLaunchId: 'appLaunchId',
userDisplayName: 'someTestUser',
teamSiteId: 'someSiteId',
appId: mockAppIdString,
manifestVersion: mockManifestVersion,
};

const expectedContext: app.Context = {
Expand All @@ -589,6 +593,8 @@ describe('Testing app capability', () => {
ringId: 'someRingId',
sessionId: 'someSessionId',
},
appId: new AppId(mockAppIdString),
manifestVersion: mockManifestVersion,
},
page: {
id: 'someEntityId',
Expand Down Expand Up @@ -662,6 +668,9 @@ describe('Testing app capability', () => {
expect(actualContext.actionInfo?.actionObjects.length).toBe(5);
expect(firstActionItem.secondaryId?.name).toEqual(SecondaryM365ContentIdName.DriveId);
expect(isM365ContentType(secondActionItem)).toBe(false);
const expectedAppId = new AppId(mockAppIdString);
expect(actualContext.app.appId).toEqual(expectedAppId);
expect(actualContext.app.manifestVersion).toBe(mockManifestVersion);
});
});
});
Expand Down

0 comments on commit 3d6ab5d

Please sign in to comment.