From 3a07cf5209d9215380b03f03170142e0cda9671b Mon Sep 17 00:00:00 2001 From: singhmanp0707 <133632776+singhmanp0707@users.noreply.github.com> Date: Thu, 21 Nov 2024 03:23:15 +0530 Subject: [PATCH] Supporting isNAAChannelRecommended flag for Legacy Teams Mobile Scenario (#2604) * updated isNAAChannelRecommended condition and added nestedAppAuth capability with version check in `runtime.ts` * updated the conditions for isNAAChannelRecommended pull from main and resolve conflicts * updated teams client version and added unit tests * addressed review comment --------- Co-authored-by: Trevor Harris --- ...-0bfc106c-dcbd-4193-b604-49700784ee6d.json | 7 ++ packages/teams-js/src/public/nestedAppAuth.ts | 25 ++++- packages/teams-js/src/public/runtime.ts | 6 ++ .../test/public/nestedAppAuth.spec.ts | 97 ++++++++++++++++++- packages/teams-js/test/public/runtime.spec.ts | 2 + 5 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 change/@microsoft-teams-js-0bfc106c-dcbd-4193-b604-49700784ee6d.json diff --git a/change/@microsoft-teams-js-0bfc106c-dcbd-4193-b604-49700784ee6d.json b/change/@microsoft-teams-js-0bfc106c-dcbd-4193-b604-49700784ee6d.json new file mode 100644 index 0000000000..d00f7a2ad2 --- /dev/null +++ b/change/@microsoft-teams-js-0bfc106c-dcbd-4193-b604-49700784ee6d.json @@ -0,0 +1,7 @@ +{ + "type": "minor", + "comment": "Added `nestedAppAuth` capability against a new client version `2.1.1` to support isNAAChannelRecommended for Teams Mobile", + "packageName": "@microsoft/teams-js", + "email": "singhmanp@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/packages/teams-js/src/public/nestedAppAuth.ts b/packages/teams-js/src/public/nestedAppAuth.ts index 47be26730e..8f01b1b252 100644 --- a/packages/teams-js/src/public/nestedAppAuth.ts +++ b/packages/teams-js/src/public/nestedAppAuth.ts @@ -4,7 +4,9 @@ * @module */ +import { GlobalVars } from '../internal/globalVars'; import { ensureInitialized } from '../internal/internalAPIs'; +import { HostClientType } from './constants'; import { runtime } from './runtime'; /** @@ -16,5 +18,26 @@ import { runtime } from './runtime'; * @beta */ export function isNAAChannelRecommended(): boolean { - return (ensureInitialized(runtime) && runtime.isNAAChannelRecommended) ?? false; + return ( + (ensureInitialized(runtime) && + (runtime.isNAAChannelRecommended || isNAAChannelRecommendedForLegacyTeamsMobile())) ?? + false + ); +} + +function isNAAChannelRecommendedForLegacyTeamsMobile(): boolean { + return ensureInitialized(runtime) && + isHostAndroidOrIOSOrIPadOS() && + runtime.isLegacyTeams && + runtime.supports.nestedAppAuth + ? true + : false; +} + +function isHostAndroidOrIOSOrIPadOS(): boolean { + return ( + GlobalVars.hostClientType === HostClientType.android || + GlobalVars.hostClientType === HostClientType.ios || + GlobalVars.hostClientType === HostClientType.ipados + ); } diff --git a/packages/teams-js/src/public/runtime.ts b/packages/teams-js/src/public/runtime.ts index bd300b2d70..635382edb2 100644 --- a/packages/teams-js/src/public/runtime.ts +++ b/packages/teams-js/src/public/runtime.ts @@ -592,6 +592,12 @@ export const mapTeamsVersionToSupportedCapabilities: Record { +describe('nestedAppAuth.isNAAChannelRecommended', () => { const utils = new Utils(); beforeEach(() => { @@ -63,4 +63,97 @@ describe('nestedAppAuth', () => { utils.setRuntimeConfig(runtimeConfig); expect(nestedAppAuth.isNAAChannelRecommended()).toBeFalsy(); }); + + it('should return false if isNAAChannelRecommended is false in runtimeConfig for macos client', async () => { + await utils.initializeWithContext(FrameContexts.content, HostClientType.macos); + const runtimeConfig: Runtime = { + apiVersion: 4, + supports: {}, + isNAAChannelRecommended: false, + }; + utils.setRuntimeConfig(runtimeConfig); + expect(nestedAppAuth.isNAAChannelRecommended()).toBeFalsy(); + }); + + it('should return false if isNAAChannelRecommended is false in runtimeConfig for desktop client', async () => { + await utils.initializeWithContext(FrameContexts.content, HostClientType.desktop); + const runtimeConfig: Runtime = { + apiVersion: 4, + supports: {}, + isNAAChannelRecommended: false, + }; + utils.setRuntimeConfig(runtimeConfig); + expect(nestedAppAuth.isNAAChannelRecommended()).toBeFalsy(); + }); + + it('should return false if isNAAChannelRecommended is false in runtimeConfig for web client', async () => { + await utils.initializeWithContext(FrameContexts.content, HostClientType.web); + const runtimeConfig: Runtime = { + apiVersion: 4, + supports: {}, + isNAAChannelRecommended: false, + }; + utils.setRuntimeConfig(runtimeConfig); + expect(nestedAppAuth.isNAAChannelRecommended()).toBeFalsy(); + }); + + it('should return false if isNAAChannelRecommended is false and isLegacyTeams is false in runtimeConfig', async () => { + await utils.initializeWithContext(FrameContexts.content, HostClientType.android); + const runtimeConfig: Runtime = { + apiVersion: 4, + supports: {}, + isNAAChannelRecommended: false, + isLegacyTeams: false, + }; + utils.setRuntimeConfig(runtimeConfig); + expect(nestedAppAuth.isNAAChannelRecommended()).toBeFalsy(); + }); + + it('should return false if isNAAChannelRecommended is false and isLegacyTeams is true in runtimeConfig for android client that does not supports nestedAppAuth', async () => { + await utils.initializeWithContext(FrameContexts.content, HostClientType.android); + const runtimeConfig: Runtime = { + apiVersion: 4, + supports: {}, + isNAAChannelRecommended: false, + isLegacyTeams: true, + }; + utils.setRuntimeConfig(runtimeConfig); + expect(nestedAppAuth.isNAAChannelRecommended()).toBeFalsy(); + }); + + it('should return true if isNAAChannelRecommended is false and isLegacyTeams is true in runtimeConfig for android client that supports nestedAppAuth', async () => { + await utils.initializeWithContext(FrameContexts.content, HostClientType.android); + const runtimeConfig: Runtime = { + apiVersion: 4, + supports: { nestedAppAuth }, + isNAAChannelRecommended: false, + isLegacyTeams: true, + }; + utils.setRuntimeConfig(runtimeConfig); + expect(nestedAppAuth.isNAAChannelRecommended()).toBeTruthy(); + }); + + it('should return true if isNAAChannelRecommended is false and isLegacyTeams is true in runtimeConfig for ios client that supports nestedAppAuth', async () => { + await utils.initializeWithContext(FrameContexts.content, HostClientType.ios); + const runtimeConfig: Runtime = { + apiVersion: 4, + supports: { nestedAppAuth }, + isNAAChannelRecommended: false, + isLegacyTeams: true, + }; + utils.setRuntimeConfig(runtimeConfig); + expect(nestedAppAuth.isNAAChannelRecommended()).toBeTruthy(); + }); + + it('should return true if isNAAChannelRecommended is false and isLegacyTeams is true in runtimeConfig for ipados client that supports nestedAppAuth', async () => { + await utils.initializeWithContext(FrameContexts.content, HostClientType.ipados); + const runtimeConfig: Runtime = { + apiVersion: 4, + supports: { nestedAppAuth }, + isNAAChannelRecommended: false, + isLegacyTeams: true, + }; + utils.setRuntimeConfig(runtimeConfig); + expect(nestedAppAuth.isNAAChannelRecommended()).toBeTruthy(); + }); }); diff --git a/packages/teams-js/test/public/runtime.spec.ts b/packages/teams-js/test/public/runtime.spec.ts index 1c351c3858..29904a6e6b 100644 --- a/packages/teams-js/test/public/runtime.spec.ts +++ b/packages/teams-js/test/public/runtime.spec.ts @@ -1,6 +1,7 @@ /* eslint-disable @typescript-eslint/ban-types */ import { errorRuntimeNotInitialized } from '../../src/internal/constants'; +import { GlobalVars } from '../../src/internal/globalVars'; import { compareSDKVersions } from '../../src/internal/utils'; import { app, HostClientType } from '../../src/public'; import { @@ -243,6 +244,7 @@ describe('runtime', () => { for (const clientType of capabilityAdditionsInASpecificVersion.hostClientTypes) { await utils.initializeWithContext('content', clientType); + GlobalVars.hostClientType = clientType; const generatedCapabilityObjectForThisVersion = generateVersionBasedTeamsRuntimeConfig( version, versionAndPlatformAgnosticTeamsRuntimeConfig,