-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
noahdarveau/ The Last Treeshaking PR (#2593)
* updated last of private capabilities to be treeshakable
- Loading branch information
1 parent
6ce5c0a
commit f2f4757
Showing
20 changed files
with
927 additions
and
911 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@microsoft-teams-js-c23ceb97-a527-4ef9-8714-f4beff7446ec.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "minor", | ||
"comment": "Made the `copilot`, `hostEntity`, `messageChannels`, and `teams` files treeshakable", | ||
"packageName": "@microsoft/teams-js", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import * as eligibility from './eligibility'; | ||
|
||
export { eligibility }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { sendAndUnwrap } from '../../internal/communication'; | ||
import { ensureInitialized } from '../../internal/internalAPIs'; | ||
import { ApiName, ApiVersionNumber, getApiVersionTag, getLogger } from '../../internal/telemetry'; | ||
import { errorNotSupportedOnPlatform } from '../../public/constants'; | ||
import { AppEligibilityInformation, isSdkError, SdkError } from '../../public/interfaces'; | ||
import { runtime } from '../../public/runtime'; | ||
|
||
const copilotTelemetryVersionNumber: ApiVersionNumber = ApiVersionNumber.V_2; | ||
const copilotLogger = getLogger('copilot'); | ||
|
||
/** | ||
* @beta | ||
* @hidden | ||
* User information required by specific apps | ||
* @internal | ||
* Limited to Microsoft-internal use | ||
*/ | ||
/** | ||
* @hidden | ||
* @internal | ||
* Limited to Microsoft-internal use | ||
* @beta | ||
* @returns boolean to represent whether copilot.eligibility capability is supported | ||
* | ||
* @throws Error if {@linkcode app.initialize} has not successfully completed | ||
*/ | ||
export function isSupported(): boolean { | ||
return ( | ||
ensureInitialized(runtime) && | ||
(!!runtime.hostVersionsInfo?.appEligibilityInformation || !!runtime.supports.copilot?.eligibility) | ||
); | ||
} | ||
|
||
/** | ||
* @hidden | ||
* @internal | ||
* Limited to Microsoft-internal use | ||
* @beta | ||
* @returns the copilot eligibility information about the user | ||
* | ||
* @throws Error if {@linkcode app.initialize} has not successfully completed | ||
*/ | ||
export async function getEligibilityInfo(): Promise<AppEligibilityInformation> { | ||
ensureInitialized(runtime); | ||
if (!isSupported()) { | ||
throw new Error(`Error code: ${errorNotSupportedOnPlatform.errorCode}, message: Not supported on platform`); | ||
} | ||
|
||
// Return the eligibility information if it is already available | ||
if (runtime.hostVersionsInfo?.appEligibilityInformation) { | ||
copilotLogger('Eligibility information is already available on runtime.'); | ||
return runtime.hostVersionsInfo!.appEligibilityInformation; | ||
} | ||
|
||
copilotLogger('Eligibility information is not available on runtime. Requesting from host.'); | ||
// Send message to host SDK to get eligibility information | ||
const response = await sendAndUnwrap<AppEligibilityInformation | SdkError>( | ||
getApiVersionTag(copilotTelemetryVersionNumber, ApiName.Copilot_Eligibility_GetEligibilityInfo), | ||
ApiName.Copilot_Eligibility_GetEligibilityInfo, | ||
); | ||
|
||
if (isSdkError(response)) { | ||
throw new Error( | ||
`Error code: ${response.errorCode}, message: ${response.message ?? 'Failed to get eligibility information from the host.'}`, | ||
); | ||
} | ||
// validate response | ||
if (!isEligibilityInfoValid(response)) { | ||
throw new Error('Error deserializing eligibility information'); | ||
} | ||
return response; | ||
} | ||
|
||
function isEligibilityInfoValid(eligibilityInfo: AppEligibilityInformation): boolean { | ||
if ( | ||
eligibilityInfo.ageGroup === undefined || | ||
eligibilityInfo.cohort === undefined || | ||
eligibilityInfo.userClassification === undefined || | ||
eligibilityInfo.isCopilotEligible === undefined || | ||
eligibilityInfo.isCopilotEnabledRegion === undefined || | ||
eligibilityInfo.isOptedOutByAdmin === undefined | ||
) { | ||
return false; | ||
} | ||
return true; | ||
} |
Oops, something went wrong.