@microsoft/sp-component-base 1.23.1 → 1.24.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/467dc675-7cc5-4709-8aac-78e3b71bd2f6.manifest.json +136 -141
- package/dist/{chunk.legacy-third-party-fabric-core-localfont_none_9e84ea19c68fdc8b9094.js → chunk.legacy-third-party-fabric-core-localfont_none_b7f7978a3e90166c361b.js} +1 -1
- package/dist/chunk.teams-apps-client_none_27d3c7c1d01080e4f131.js +2 -0
- package/dist/index-internal-beta.d.ts +30 -8
- package/dist/index-internal-public.d.ts +30 -8
- package/dist/index-internal.d.ts +30 -8
- package/dist/sp-component-base_default_8d535b51fa18aa47002b.js +22 -0
- package/dist/sp-component-base_en-us_8ce25dfb69a7786caece.js +22 -0
- package/dist/sp-component-base_qps-ploc_4fec831895d90df8aa7a.js +22 -0
- package/dist/sp-component-base_qps-ploca_b80610c8dff04dcec755.js +22 -0
- package/dist/tsdoc-metadata.json +1 -1
- package/lib-commonjs/BaseComponent.js +110 -145
- package/lib-commonjs/BaseComponentContext.js +126 -183
- package/lib-commonjs/DynamicDataProvider.js +251 -268
- package/lib-commonjs/DynamicDataSourceManager.js +218 -241
- package/lib-commonjs/DynamicProperty.js +232 -280
- package/lib-commonjs/EnsureIsolatedDomainUrl.js +14 -14
- package/lib-commonjs/IComponentPosition.js +8 -3
- package/lib-commonjs/IComponentPropertyMetadata.js +10 -3
- package/lib-commonjs/ISerializedServerProcessedData.js +24 -21
- package/lib-commonjs/LegacyThirdPartyFabricCoreLoader.js +53 -87
- package/lib-commonjs/PropertyMetadataProcessor.js +117 -150
- package/lib-commonjs/RenderableComponentContext.js +37 -0
- package/lib-commonjs/ShimmerFactory.js +66 -51
- package/lib-commonjs/chunks/legacy-third-party-fabric-core/FabricLocalFont.js +6 -4
- package/lib-commonjs/common/Flights.js +22 -10
- package/lib-commonjs/common/KillSwitches.js +13 -6
- package/lib-commonjs/dataCollector/IWebPartLoadData.js +35 -30
- package/lib-commonjs/dataCollector/WebPartLoadDataCollector.js +82 -91
- package/lib-commonjs/index.js +78 -38
- package/lib-commonjs/teams/DeferredTeamsAppsClient.js +30 -52
- package/lib-commonjs/teams/ITeamsAppCatalog.js +10 -3
- package/lib-commonjs/teams/TeamsAppsClient.js +189 -231
- package/lib-commonjs/test-api/MockComponent.js +38 -23
- package/lib-commonjs/test-api/MockComponentContext.js +21 -14
- package/lib-commonjs/test-api/index.js +21 -7
- package/lib-commonjs/themeProvider/ThemeProvider.js +68 -82
- package/lib-commonjs/themeProvider/themeInterfaces/IFontStyles.js +5 -2
- package/lib-commonjs/themeProvider/themeInterfaces/IPalette.js +10 -3
- package/lib-commonjs/themeProvider/themeInterfaces/ISemanticColors.js +59 -3
- package/lib-commonjs/themeProvider/themeInterfaces/ISemanticTextColors.js +10 -3
- package/lib-commonjs/themeProvider/themeInterfaces/ITheme.js +5 -2
- package/{lib → lib-dts}/BaseComponent.d.ts +8 -8
- package/{lib → lib-dts}/BaseComponentContext.d.ts +5 -5
- package/lib-dts/RenderableComponentContext.d.ts +35 -0
- package/{lib → lib-dts}/index.d.ts +1 -0
- package/lib-esm/BaseComponent.js +123 -0
- package/lib-esm/BaseComponentContext.js +157 -0
- package/lib-esm/DynamicDataProvider.js +401 -0
- package/lib-esm/DynamicDataSourceManager.js +358 -0
- package/lib-esm/DynamicProperty.js +344 -0
- package/{lib → lib-esm}/EnsureIsolatedDomainUrl.js +6 -6
- package/lib-esm/IComponentPosition.js +5 -0
- package/lib-esm/IComponentPropertyMetadata.js +7 -0
- package/lib-esm/ISerializedServerProcessedData.js +24 -0
- package/lib-esm/LegacyThirdPartyFabricCoreLoader.js +76 -0
- package/{lib → lib-esm}/PropertyMetadataProcessor.js +92 -127
- package/lib-esm/RenderableComponentContext.js +26 -0
- package/lib-esm/ShimmerFactory.js +74 -0
- package/{lib → lib-esm}/chunks/legacy-third-party-fabric-core/FabricLocalFont.js +3 -3
- package/{lib → lib-esm}/common/Flights.js +4 -3
- package/{lib → lib-esm}/common/KillSwitches.js +3 -2
- package/lib-esm/dataCollector/IWebPartLoadData.js +33 -0
- package/lib-esm/dataCollector/WebPartLoadDataCollector.js +125 -0
- package/{lib → lib-esm}/index.js +4 -3
- package/lib-esm/teams/DeferredTeamsAppsClient.js +32 -0
- package/lib-esm/teams/ITeamsAppCatalog.js +9 -0
- package/lib-esm/teams/TeamsAppsClient.js +395 -0
- package/lib-esm/test-api/MockComponent.js +38 -0
- package/{lib → lib-esm}/test-api/MockComponentContext.js +10 -11
- package/{lib → lib-esm}/test-api/index.js +2 -1
- package/lib-esm/themeProvider/ThemeProvider.js +79 -0
- package/lib-esm/themeProvider/themeInterfaces/IFontStyles.js +7 -0
- package/lib-esm/themeProvider/themeInterfaces/IPalette.js +7 -0
- package/lib-esm/themeProvider/themeInterfaces/ISemanticColors.js +56 -0
- package/lib-esm/themeProvider/themeInterfaces/ISemanticTextColors.js +7 -0
- package/lib-esm/themeProvider/themeInterfaces/ITheme.js +7 -0
- package/package.json +41 -14
- package/dist/chunk.teams-apps-client_none_f9872389cb6ea9ad28e2.js +0 -2
- package/dist/sp-component-base_default_5ba07be39b0dc8968f7b.js +0 -2
- package/dist/sp-component-base_en-us_eb9bebb3acce0ae83f1c.js +0 -2
- package/dist/sp-component-base_qps-ploc_45f37623d87c3d848f2a.js +0 -2
- package/dist/sp-component-base_qps-ploca_b3f3b7bf97c4185b0fd6.js +0 -2
- package/lib/BaseComponent.d.ts.map +0 -1
- package/lib/BaseComponent.js +0 -161
- package/lib/BaseComponentContext.d.ts.map +0 -1
- package/lib/BaseComponentContext.js +0 -222
- package/lib/DynamicDataProvider.d.ts.map +0 -1
- package/lib/DynamicDataProvider.js +0 -420
- package/lib/DynamicDataSourceManager.d.ts.map +0 -1
- package/lib/DynamicDataSourceManager.js +0 -382
- package/lib/DynamicProperty.d.ts.map +0 -1
- package/lib/DynamicProperty.js +0 -390
- package/lib/EnsureIsolatedDomainUrl.d.ts.map +0 -1
- package/lib/IComponentPosition.d.ts.map +0 -1
- package/lib/IComponentPosition.js +0 -2
- package/lib/IComponentPropertyMetadata.d.ts.map +0 -1
- package/lib/IComponentPropertyMetadata.js +0 -2
- package/lib/ISerializedServerProcessedData.d.ts.map +0 -1
- package/lib/ISerializedServerProcessedData.js +0 -28
- package/lib/LegacyThirdPartyFabricCoreLoader.d.ts.map +0 -1
- package/lib/LegacyThirdPartyFabricCoreLoader.js +0 -90
- package/lib/PropertyMetadataProcessor.d.ts.map +0 -1
- package/lib/ShimmerFactory.d.ts.map +0 -1
- package/lib/ShimmerFactory.js +0 -62
- package/lib/chunks/legacy-third-party-fabric-core/FabricLocalFont.d.ts.map +0 -1
- package/lib/common/Flights.d.ts.map +0 -1
- package/lib/common/KillSwitches.d.ts.map +0 -1
- package/lib/dataCollector/IWebPartLoadData.d.ts.map +0 -1
- package/lib/dataCollector/IWebPartLoadData.js +0 -40
- package/lib/dataCollector/WebPartLoadDataCollector.d.ts.map +0 -1
- package/lib/dataCollector/WebPartLoadDataCollector.js +0 -137
- package/lib/index.d.ts.map +0 -1
- package/lib/teams/DeferredTeamsAppsClient.d.ts.map +0 -1
- package/lib/teams/DeferredTeamsAppsClient.js +0 -39
- package/lib/teams/ITeamsAppCatalog.d.ts.map +0 -1
- package/lib/teams/ITeamsAppCatalog.js +0 -2
- package/lib/teams/TeamsAppsClient.d.ts.map +0 -1
- package/lib/teams/TeamsAppsClient.js +0 -440
- package/lib/test-api/MockComponent.d.ts.map +0 -1
- package/lib/test-api/MockComponent.js +0 -31
- package/lib/test-api/MockComponentContext.d.ts.map +0 -1
- package/lib/test-api/index.d.ts.map +0 -1
- package/lib/themeProvider/ThemeProvider.d.ts.map +0 -1
- package/lib/themeProvider/ThemeProvider.js +0 -99
- package/lib/themeProvider/themeInterfaces/IFontStyles.d.ts.map +0 -1
- package/lib/themeProvider/themeInterfaces/IFontStyles.js +0 -2
- package/lib/themeProvider/themeInterfaces/IPalette.d.ts.map +0 -1
- package/lib/themeProvider/themeInterfaces/IPalette.js +0 -2
- package/lib/themeProvider/themeInterfaces/ISemanticColors.d.ts.map +0 -1
- package/lib/themeProvider/themeInterfaces/ISemanticColors.js +0 -2
- package/lib/themeProvider/themeInterfaces/ISemanticTextColors.d.ts.map +0 -1
- package/lib/themeProvider/themeInterfaces/ISemanticTextColors.js +0 -2
- package/lib/themeProvider/themeInterfaces/ITheme.d.ts.map +0 -1
- package/lib/themeProvider/themeInterfaces/ITheme.js +0 -2
- /package/{lib → lib-dts}/DynamicDataProvider.d.ts +0 -0
- /package/{lib → lib-dts}/DynamicDataSourceManager.d.ts +0 -0
- /package/{lib → lib-dts}/DynamicProperty.d.ts +0 -0
- /package/{lib → lib-dts}/EnsureIsolatedDomainUrl.d.ts +0 -0
- /package/{lib → lib-dts}/IComponentPosition.d.ts +0 -0
- /package/{lib → lib-dts}/IComponentPropertyMetadata.d.ts +0 -0
- /package/{lib → lib-dts}/ISerializedServerProcessedData.d.ts +0 -0
- /package/{lib → lib-dts}/LegacyThirdPartyFabricCoreLoader.d.ts +0 -0
- /package/{lib → lib-dts}/PropertyMetadataProcessor.d.ts +0 -0
- /package/{lib → lib-dts}/ShimmerFactory.d.ts +0 -0
- /package/{lib → lib-dts}/chunks/legacy-third-party-fabric-core/FabricLocalFont.d.ts +0 -0
- /package/{lib → lib-dts}/common/Flights.d.ts +0 -0
- /package/{lib → lib-dts}/common/KillSwitches.d.ts +0 -0
- /package/{lib → lib-dts}/dataCollector/IWebPartLoadData.d.ts +0 -0
- /package/{lib → lib-dts}/dataCollector/WebPartLoadDataCollector.d.ts +0 -0
- /package/{lib → lib-dts}/loc/Strings.resx.d.ts +0 -0
- /package/{lib → lib-dts}/teams/DeferredTeamsAppsClient.d.ts +0 -0
- /package/{lib → lib-dts}/teams/ITeamsAppCatalog.d.ts +0 -0
- /package/{lib → lib-dts}/teams/TeamsAppsClient.d.ts +0 -0
- /package/{lib → lib-dts}/test-api/MockComponent.d.ts +0 -0
- /package/{lib → lib-dts}/test-api/MockComponentContext.d.ts +0 -0
- /package/{lib → lib-dts}/test-api/index.d.ts +0 -0
- /package/{lib → lib-dts}/themeProvider/ThemeProvider.d.ts +0 -0
- /package/{lib → lib-dts}/themeProvider/themeInterfaces/IFontStyles.d.ts +0 -0
- /package/{lib → lib-dts}/themeProvider/themeInterfaces/IPalette.d.ts +0 -0
- /package/{lib → lib-dts}/themeProvider/themeInterfaces/ISemanticColors.d.ts +0 -0
- /package/{lib → lib-dts}/themeProvider/themeInterfaces/ISemanticTextColors.d.ts +0 -0
- /package/{lib → lib-dts}/themeProvider/themeInterfaces/ITheme.d.ts +0 -0
- /package/{lib → lib-esm}/chunks/legacy-third-party-fabric-core/fabric-core-sass/Fabric.LocalFont.global.scss.css +0 -0
- /package/{lib → lib-esm}/chunks/legacy-third-party-fabric-core/fabric-core-sass/Fabric.LocalFontKillSwitchActivated.scss.css +0 -0
- /package/{lib → lib-esm}/chunks/legacy-third-party-fabric-core/fabric-core-shim.global.scss.css +0 -0
- /package/{lib → lib-esm}/chunks/legacy-third-party-fabric-core/fabric-core-shimKillSwitchActivated.scss.css +0 -0
- /package/{lib → lib-esm}/chunks/legacy-third-party-fabric-core/iconDefinitions.css +0 -0
- /package/{lib → lib-esm}/loc/Strings.resx.json +0 -0
- /package/{lib → lib-esm}/sp-component-base.manifest.json +0 -0
- /package/{lib → lib-esm}/styles/shimmer.module.scss.css +0 -0
|
@@ -1,73 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "TeamsAppsClient", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return TeamsAppsClient;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _spdiagnostics = require("@microsoft/sp-diagnostics");
|
|
12
|
+
const _sphttp = require("@microsoft/sp-http");
|
|
13
|
+
const _sppagecontext = require("@microsoft/sp-page-context");
|
|
14
|
+
const _Flights = require("../common/Flights");
|
|
15
|
+
const _splodashsubset = require("@microsoft/sp-lodash-subset");
|
|
9
16
|
// base teams apps endpoint
|
|
10
|
-
|
|
17
|
+
const MS_GRAPH_TEAMS_APPS_ENDPOINT = '/appCatalogs/teamsApps';
|
|
11
18
|
// QSP to fetch all teams apps with dashboard cards
|
|
12
|
-
|
|
19
|
+
const MS_GRAPH_FETCH_TEAMS_APPS_QSP = `$expand=appDefinitions($expand=outlineIcon,colorIcon,dashboardCards)&$filter=appDefinitions/any(a:a/dashboardCards/$count ne 0)`;
|
|
13
20
|
// QSP to check permissions for the list of app ids
|
|
14
|
-
|
|
15
|
-
|
|
21
|
+
const MS_GRAPH_CHECK_PERMISSIONS_QSP = `$expand=appDefinitions($expand=dashboardCards)&$filter=appDefinitions/any(a:a/dashboardCards/$count ne 0) and id in ('{appIds}')`;
|
|
22
|
+
const MS_GRAPH_API_VERSION = 'beta';
|
|
16
23
|
// the number of app ids we can process without batching the request to avoid the URL length limit
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* The client for the Teams Apps sync.
|
|
23
|
-
*
|
|
24
|
-
* @internal
|
|
25
|
-
*/
|
|
26
|
-
var TeamsAppsClient = /** @class */ (function () {
|
|
27
|
-
function TeamsAppsClient(serviceScope) {
|
|
28
|
-
/**
|
|
29
|
-
* Map[teamsAppId, Promise[Set[teamsAppId]]]
|
|
30
|
-
*
|
|
31
|
-
* We store a map where the same promise can be used for multiple entries.
|
|
32
|
-
* In that case we can avoid multiple requests to the API for the same teamsAppId as well as avoid race conditions and allow to make extra requests if needed.
|
|
33
|
-
*/
|
|
34
|
-
this._appComponentsPermissionsPromises = new Map();
|
|
35
|
-
this._serviceScope = serviceScope;
|
|
36
|
-
}
|
|
24
|
+
const MAX_IDS_WITHOUT_BATCHING = 30;
|
|
25
|
+
const MAX_REQUESTS_PER_BATCH = 10;
|
|
26
|
+
const MANIFEST_VERSION = 2;
|
|
27
|
+
const ADVANCED_TOOLBOX_GROUP_ID = '5c03119e-3074-46fd-976b-c60198311f70';
|
|
28
|
+
class TeamsAppsClient {
|
|
37
29
|
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
TeamsAppsClient.prototype.getTeamsAppComponentManifests = function () {
|
|
42
|
-
var _this = this;
|
|
30
|
+
* Gets the list of Teams App components from Teams App Catalog.
|
|
31
|
+
* @returns Promise that resolves to the list of Teams App components.
|
|
32
|
+
*/ getTeamsAppComponentManifests() {
|
|
43
33
|
if (!TeamsAppsClient._getTeamsAppComponentManifestsPromise) {
|
|
44
|
-
if (!(0,
|
|
34
|
+
if (!(0, _Flights.isBotAcesFromTeamsEnabled)()) {
|
|
45
35
|
TeamsAppsClient._getTeamsAppComponentManifestsPromise = Promise.resolve([]);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
.version(MS_GRAPH_API_VERSION)
|
|
54
|
-
.get();
|
|
55
|
-
})
|
|
56
|
-
.then(function (response) {
|
|
57
|
-
var manifestsPromises = response.value.map(function (item) {
|
|
58
|
-
return _this._teamsAppCatalogItemToAceManifests(item);
|
|
36
|
+
} else {
|
|
37
|
+
const monitor = new _spdiagnostics._QosMonitor('TeamsAppsClient.FetchTeamsApp');
|
|
38
|
+
TeamsAppsClient._getTeamsAppComponentManifestsPromise = this._msGraphClient.then((client)=>{
|
|
39
|
+
return client.api(`${MS_GRAPH_TEAMS_APPS_ENDPOINT}?${MS_GRAPH_FETCH_TEAMS_APPS_QSP}`).version(MS_GRAPH_API_VERSION).get();
|
|
40
|
+
}).then((response)=>{
|
|
41
|
+
const manifestsPromises = response.value.map((item)=>{
|
|
42
|
+
return this._teamsAppCatalogItemToAceManifests(item);
|
|
59
43
|
});
|
|
60
|
-
return Promise.all(manifestsPromises).then(
|
|
61
|
-
|
|
62
|
-
manifests.forEach(
|
|
63
|
-
flatManifests.push
|
|
44
|
+
return Promise.all(manifestsPromises).then((manifests)=>{
|
|
45
|
+
const flatManifests = [];
|
|
46
|
+
manifests.forEach((item)=>{
|
|
47
|
+
flatManifests.push(...item);
|
|
64
48
|
});
|
|
65
|
-
|
|
49
|
+
monitor.writeSuccess();
|
|
66
50
|
return flatManifests;
|
|
67
51
|
});
|
|
68
|
-
})
|
|
69
|
-
.
|
|
70
|
-
monitor_1.writeUnexpectedFailure(undefined, error);
|
|
52
|
+
}).catch((error)=>{
|
|
53
|
+
monitor.writeUnexpectedFailure(undefined, error);
|
|
71
54
|
// removing reference to the promise to allow retry
|
|
72
55
|
TeamsAppsClient._getTeamsAppComponentManifestsPromise = undefined;
|
|
73
56
|
return [];
|
|
@@ -75,43 +58,36 @@ var TeamsAppsClient = /** @class */ (function () {
|
|
|
75
58
|
}
|
|
76
59
|
}
|
|
77
60
|
return TeamsAppsClient._getTeamsAppComponentManifestsPromise;
|
|
78
|
-
}
|
|
61
|
+
}
|
|
79
62
|
/**
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
var _a;
|
|
85
|
-
var manifest = teamsAppComponentManifest;
|
|
86
|
-
if (!(0, Flights_1.isBotAcesFromTeamsEnabled)() || !manifest.isPendingTeamsAppSync) {
|
|
63
|
+
* Syncs the Teams App component into SharePoint App Catalog.
|
|
64
|
+
*/ syncComponent(teamsAppComponentManifest) {
|
|
65
|
+
const manifest = teamsAppComponentManifest;
|
|
66
|
+
if (!(0, _Flights.isBotAcesFromTeamsEnabled)() || !manifest.isPendingTeamsAppSync) {
|
|
87
67
|
return Promise.resolve(teamsAppComponentManifest);
|
|
88
68
|
}
|
|
89
|
-
|
|
90
|
-
if (!
|
|
69
|
+
const monitor = new _spdiagnostics._QosMonitor('TeamsAppsClient.SyncComponent');
|
|
70
|
+
if (!teamsAppComponentManifest.properties?.teamsAppComponent) {
|
|
91
71
|
monitor.writeExpectedFailure('TeamsAppComponentMissing');
|
|
92
|
-
return new Promise(
|
|
72
|
+
return new Promise(()=>{
|
|
93
73
|
throw new Error('Teams App component manifest is missing teamsAppComponent property');
|
|
94
74
|
});
|
|
95
75
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
76
|
+
const spHttpClient = this._serviceScope.consume(_sphttp.SPHttpClient.serviceKey);
|
|
77
|
+
const pageContext = this._serviceScope.consume(_sppagecontext.PageContext.serviceKey);
|
|
78
|
+
const baseRequestUrl = pageContext.web.absoluteUrl;
|
|
79
|
+
let monitorFailureTagNameSuffix = undefined;
|
|
80
|
+
let ensureAppCatalogPromise = TeamsAppsClient._ensureAppCatalogPromise;
|
|
101
81
|
if (!TeamsAppsClient._ensureAppCatalogPromise) {
|
|
102
82
|
// first step is to ensure app catalog
|
|
103
|
-
|
|
104
|
-
ensureAppCatalogPromise = TeamsAppsClient._ensureAppCatalogPromise = spHttpClient
|
|
105
|
-
.post(ensureAppCatalogRequestUrl, sp_http_1.SPHttpClient.configurations.v1, {})
|
|
106
|
-
.then(function (response) {
|
|
83
|
+
const ensureAppCatalogRequestUrl = `${baseRequestUrl}/_api/web/EnsureTenantAppCatalog(callerId='TeamsAppsClient')`;
|
|
84
|
+
ensureAppCatalogPromise = TeamsAppsClient._ensureAppCatalogPromise = spHttpClient.post(ensureAppCatalogRequestUrl, _sphttp.SPHttpClient.configurations.v1, {}).then((response)=>{
|
|
107
85
|
return response.json();
|
|
108
|
-
})
|
|
109
|
-
.then(function (response) {
|
|
86
|
+
}).then((response)=>{
|
|
110
87
|
if (response.error) {
|
|
111
88
|
throw new Error(response.error.message);
|
|
112
89
|
}
|
|
113
|
-
})
|
|
114
|
-
.catch(function (error) {
|
|
90
|
+
}).catch((error)=>{
|
|
115
91
|
// app catalog error
|
|
116
92
|
monitorFailureTagNameSuffix = 'EnsureAppCatalogFailed';
|
|
117
93
|
// we want to retry if needed
|
|
@@ -119,113 +95,107 @@ var TeamsAppsClient = /** @class */ (function () {
|
|
|
119
95
|
throw error;
|
|
120
96
|
});
|
|
121
97
|
}
|
|
122
|
-
return ensureAppCatalogPromise
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return spHttpClient
|
|
127
|
-
.post(syncRequestUrl, sp_http_1.SPHttpClient.configurations.v1, {
|
|
98
|
+
return ensureAppCatalogPromise.then(()=>{
|
|
99
|
+
const syncRequestUrl = `${baseRequestUrl}/_api/web/SyncTeamsComponent`;
|
|
100
|
+
const teamsAppComponent = teamsAppComponentManifest.properties.teamsAppComponent;
|
|
101
|
+
return spHttpClient.post(syncRequestUrl, _sphttp.SPHttpClient.configurations.v1, {
|
|
128
102
|
body: JSON.stringify({
|
|
129
103
|
teamsComponent: teamsAppComponent
|
|
130
104
|
})
|
|
131
|
-
})
|
|
132
|
-
.catch(function (error) {
|
|
105
|
+
}).catch((error)=>{
|
|
133
106
|
// sync error
|
|
134
107
|
monitorFailureTagNameSuffix = 'SyncComponentFailed';
|
|
135
108
|
throw error;
|
|
136
109
|
});
|
|
137
|
-
})
|
|
138
|
-
.then(function (response) {
|
|
110
|
+
}).then((response)=>{
|
|
139
111
|
return response.json();
|
|
140
|
-
})
|
|
141
|
-
.then(function (syncedManifest) {
|
|
112
|
+
}).then((syncedManifest)=>{
|
|
142
113
|
if (syncedManifest.error) {
|
|
143
114
|
monitorFailureTagNameSuffix = 'SyncComponentFailed';
|
|
144
115
|
throw new Error(syncedManifest.error.message);
|
|
145
116
|
}
|
|
146
|
-
|
|
147
|
-
|
|
117
|
+
const manifestResponse = syncedManifest;
|
|
118
|
+
const parsedManifest = JSON.parse(manifestResponse.Manifest);
|
|
148
119
|
if (manifestResponse.ManifestActivatedTime) {
|
|
149
120
|
parsedManifest.manifestActivatedTime = manifestResponse.ManifestActivatedTime;
|
|
150
121
|
}
|
|
151
122
|
monitor.writeSuccess();
|
|
152
|
-
|
|
123
|
+
const { appId } = teamsAppComponentManifest.properties.teamsAppComponent;
|
|
153
124
|
// we know for sure the component is allowed
|
|
154
|
-
|
|
125
|
+
this._appComponentsPermissionsPromises.set(appId, Promise.resolve(new Set([
|
|
126
|
+
appId
|
|
127
|
+
])));
|
|
155
128
|
return parsedManifest;
|
|
156
|
-
})
|
|
157
|
-
.catch(function (error) {
|
|
129
|
+
}).catch((error)=>{
|
|
158
130
|
monitor.writeUnexpectedFailure(monitorFailureTagNameSuffix, error);
|
|
159
131
|
throw error;
|
|
160
132
|
});
|
|
161
|
-
}
|
|
133
|
+
}
|
|
162
134
|
/**
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
if (!(0, Flights_1.isBotAcesFromTeamsEnabled)() || !teamsAppComponentIds.length) {
|
|
135
|
+
* Requests permissions for the Teams App components (apps) for the current user.
|
|
136
|
+
*/ requestPermissions(teamsAppComponentIds) {
|
|
137
|
+
if (!(0, _Flights.isBotAcesFromTeamsEnabled)() || !teamsAppComponentIds.length) {
|
|
167
138
|
return Promise.resolve();
|
|
168
139
|
}
|
|
169
|
-
return this._requestAppsPermissions(teamsAppComponentIds).then(
|
|
170
|
-
}
|
|
140
|
+
return this._requestAppsPermissions(teamsAppComponentIds).then(()=>{});
|
|
141
|
+
}
|
|
171
142
|
/**
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if (!(0, Flights_1.isBotAcesFromTeamsEnabled)()) {
|
|
143
|
+
* Checks if the component is enabled for the current user based on requested Teams permissions.
|
|
144
|
+
*/ isComponentEnabled(teamsAppId) {
|
|
145
|
+
if (!(0, _Flights.isBotAcesFromTeamsEnabled)()) {
|
|
176
146
|
return Promise.resolve(true);
|
|
177
147
|
}
|
|
178
148
|
if (this._appComponentsPermissionsPromises.has(teamsAppId)) {
|
|
179
|
-
return this._appComponentsPermissionsPromises.get(teamsAppId).then(
|
|
149
|
+
return this._appComponentsPermissionsPromises.get(teamsAppId).then((allowedApps)=>{
|
|
180
150
|
return allowedApps.has(teamsAppId) || false;
|
|
181
151
|
});
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
152
|
+
} else {
|
|
153
|
+
return this._requestAppsPermissions([
|
|
154
|
+
{
|
|
155
|
+
appId: teamsAppId,
|
|
156
|
+
componentId: ''
|
|
157
|
+
}
|
|
158
|
+
]).then((allowedComponents)=>{
|
|
185
159
|
return allowedComponents.has(teamsAppId) || false;
|
|
186
160
|
});
|
|
187
161
|
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
var _this = this;
|
|
162
|
+
}
|
|
163
|
+
_requestAppsPermissions(teamsAppComponentIds) {
|
|
191
164
|
// getting app ids for which we don't have a promise yet
|
|
192
|
-
|
|
193
|
-
|
|
165
|
+
const uniqueAppIds = (0, _splodashsubset.uniq)(teamsAppComponentIds.map((item)=>item.appId)).filter((appId)=>!this._appComponentsPermissionsPromises.has(appId));
|
|
166
|
+
let requestPermissionsPromise;
|
|
194
167
|
if (uniqueAppIds.length > MAX_IDS_WITHOUT_BATCHING) {
|
|
195
168
|
requestPermissionsPromise = this._requestAppsPermissionsBatched(uniqueAppIds);
|
|
196
169
|
}
|
|
197
170
|
if (!requestPermissionsPromise) {
|
|
198
|
-
|
|
199
|
-
requestPermissionsPromise = this._msGraphClient
|
|
200
|
-
.
|
|
201
|
-
|
|
202
|
-
})
|
|
203
|
-
.then(function (response) {
|
|
171
|
+
const monitor = new _spdiagnostics._QosMonitor('TeamsAppsClient.RequestAppsPermissions');
|
|
172
|
+
requestPermissionsPromise = this._msGraphClient.then((client)=>{
|
|
173
|
+
return client.api(this._getCheckPermissionsUrl(uniqueAppIds)).version(MS_GRAPH_API_VERSION).get();
|
|
174
|
+
}).then((response)=>{
|
|
204
175
|
if (response.error) {
|
|
205
|
-
|
|
176
|
+
monitor.writeUnexpectedFailure('RequestFailed', new Error(response.error.message));
|
|
206
177
|
return new Set();
|
|
207
178
|
}
|
|
208
|
-
|
|
209
|
-
response.value.map(
|
|
179
|
+
const allowedApps = new Set();
|
|
180
|
+
response.value.map((item)=>{
|
|
210
181
|
allowedApps.add(item.id);
|
|
211
182
|
});
|
|
212
|
-
|
|
183
|
+
monitor.writeSuccess();
|
|
213
184
|
return allowedApps;
|
|
214
|
-
})
|
|
215
|
-
.
|
|
216
|
-
monitor_2.writeUnexpectedFailure(undefined, error);
|
|
185
|
+
}).catch((error)=>{
|
|
186
|
+
monitor.writeUnexpectedFailure(undefined, error);
|
|
217
187
|
return new Set();
|
|
218
188
|
});
|
|
219
189
|
}
|
|
220
190
|
// store the promise to avoid multiple requests to the API for the same teamsAppId
|
|
221
|
-
uniqueAppIds.forEach(
|
|
222
|
-
|
|
191
|
+
uniqueAppIds.forEach((teamsAppId)=>{
|
|
192
|
+
this._appComponentsPermissionsPromises.set(teamsAppId, requestPermissionsPromise);
|
|
223
193
|
});
|
|
224
194
|
return requestPermissionsPromise;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
195
|
+
}
|
|
196
|
+
_requestAppsPermissionsBatched(appIds) {
|
|
197
|
+
const monitor = new _spdiagnostics._QosMonitor('TeamsAppsClient.RequestAppsPermissionsBatched');
|
|
198
|
+
const allowedApps = new Set();
|
|
229
199
|
//
|
|
230
200
|
// MS Graph batch body is like that:
|
|
231
201
|
// {
|
|
@@ -243,21 +213,21 @@ var TeamsAppsClient = /** @class */ (function () {
|
|
|
243
213
|
// We need to split the list of app ids to have no more than 10 requests per batch and no more than 30 ids per request
|
|
244
214
|
//
|
|
245
215
|
// we can have MAX_IDS_WITHOUT_BATCHING per one request in batch. And up to MAX_REQUESTS_PER_BATCH requests in batch.
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
216
|
+
const maxIdsPerBatch = MAX_IDS_WITHOUT_BATCHING * MAX_REQUESTS_PER_BATCH;
|
|
217
|
+
const batchesCount = Math.ceil(appIds.length / maxIdsPerBatch);
|
|
218
|
+
let batchIndex = 0;
|
|
219
|
+
const batchRequests = [];
|
|
250
220
|
try {
|
|
251
|
-
while
|
|
252
|
-
|
|
221
|
+
while(batchIndex < batchesCount){
|
|
222
|
+
const batchBody = {
|
|
253
223
|
requests: []
|
|
254
224
|
};
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
while
|
|
259
|
-
|
|
260
|
-
|
|
225
|
+
const batchStartIndex = batchIndex * maxIdsPerBatch;
|
|
226
|
+
const batchEndIndex = Math.min(batchStartIndex + maxIdsPerBatch, appIds.length);
|
|
227
|
+
let batchIdStartIndex = batchStartIndex;
|
|
228
|
+
while(batchIdStartIndex < batchEndIndex){
|
|
229
|
+
const batchIdEndIndex = batchIdStartIndex + MAX_IDS_WITHOUT_BATCHING;
|
|
230
|
+
const batchIds = appIds.slice(batchIdStartIndex, batchIdEndIndex);
|
|
261
231
|
batchBody.requests.push({
|
|
262
232
|
id: batchIdStartIndex.toString(),
|
|
263
233
|
method: 'GET',
|
|
@@ -268,38 +238,30 @@ var TeamsAppsClient = /** @class */ (function () {
|
|
|
268
238
|
batchRequests.push(batchBody);
|
|
269
239
|
batchIndex++;
|
|
270
240
|
}
|
|
271
|
-
}
|
|
272
|
-
catch (error) {
|
|
241
|
+
} catch (error) {
|
|
273
242
|
monitor.writeUnexpectedFailure('BatchSplitLogicError', error);
|
|
274
243
|
// Early return to avoid the request
|
|
275
244
|
return Promise.resolve(allowedApps);
|
|
276
245
|
}
|
|
277
|
-
|
|
278
|
-
return this._msGraphClient
|
|
279
|
-
.
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
.api('$batch')
|
|
283
|
-
.version(MS_GRAPH_API_VERSION)
|
|
284
|
-
.post(batchBody)
|
|
285
|
-
.then(function (response) {
|
|
286
|
-
response.responses.forEach(function (responseItem) {
|
|
246
|
+
const errors = [];
|
|
247
|
+
return this._msGraphClient.then((client)=>{
|
|
248
|
+
const batchPromises = batchRequests.map((batchBody)=>{
|
|
249
|
+
return client.api('$batch').version(MS_GRAPH_API_VERSION).post(batchBody).then((response)=>{
|
|
250
|
+
response.responses.forEach((responseItem)=>{
|
|
287
251
|
if (responseItem.status !== 200) {
|
|
288
252
|
errors.push(new Error(responseItem.body.error.message));
|
|
289
253
|
return;
|
|
290
254
|
}
|
|
291
|
-
responseItem.body.value.map(
|
|
255
|
+
responseItem.body.value.map((app)=>{
|
|
292
256
|
allowedApps.add(app.id);
|
|
293
257
|
});
|
|
294
258
|
});
|
|
295
|
-
})
|
|
296
|
-
.catch(function (error) {
|
|
259
|
+
}).catch((error)=>{
|
|
297
260
|
errors.push(error);
|
|
298
261
|
});
|
|
299
262
|
});
|
|
300
263
|
return Promise.all(batchPromises);
|
|
301
|
-
})
|
|
302
|
-
.then(function () {
|
|
264
|
+
}).then(()=>{
|
|
303
265
|
// some batches failed
|
|
304
266
|
if (errors.length) {
|
|
305
267
|
monitor.writeUnexpectedFailure('SomeBatchRequestsError', undefined, {
|
|
@@ -307,50 +269,42 @@ var TeamsAppsClient = /** @class */ (function () {
|
|
|
307
269
|
});
|
|
308
270
|
}
|
|
309
271
|
return allowedApps;
|
|
310
|
-
})
|
|
311
|
-
.catch(function (error) {
|
|
272
|
+
}).catch((error)=>{
|
|
312
273
|
// all batches failed
|
|
313
274
|
monitor.writeUnexpectedFailure('BatchRequestError', error);
|
|
314
275
|
return new Set();
|
|
315
276
|
});
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
return
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
enumerable: false,
|
|
331
|
-
configurable: true
|
|
332
|
-
});
|
|
333
|
-
TeamsAppsClient.prototype._teamsAppCatalogItemToAceManifests = function (item) {
|
|
334
|
-
var _this = this;
|
|
335
|
-
var _a;
|
|
277
|
+
}
|
|
278
|
+
_getCheckPermissionsUrl(appIds) {
|
|
279
|
+
return `${MS_GRAPH_TEAMS_APPS_ENDPOINT}?${MS_GRAPH_CHECK_PERMISSIONS_QSP.replace('{appIds}', appIds.join(`','`))}`;
|
|
280
|
+
}
|
|
281
|
+
get _msGraphClient() {
|
|
282
|
+
if (!this._msGraphClientFactory) {
|
|
283
|
+
this._msGraphClientFactory = this._serviceScope.consume(_sphttp.MSGraphClientFactory.serviceKey);
|
|
284
|
+
}
|
|
285
|
+
if (!this._msGraphClientDeferred) {
|
|
286
|
+
this._msGraphClientDeferred = this._msGraphClientFactory.getClientInternal('3');
|
|
287
|
+
}
|
|
288
|
+
return this._msGraphClientDeferred;
|
|
289
|
+
}
|
|
290
|
+
_teamsAppCatalogItemToAceManifests(item) {
|
|
336
291
|
//
|
|
337
292
|
// collect components that use Teams App icon instead of having its own
|
|
338
293
|
// if there are such components, we will need to fetch the app icon
|
|
339
294
|
//
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
dashboardCards.forEach(
|
|
346
|
-
|
|
347
|
-
var component = {
|
|
295
|
+
let iconPromise;
|
|
296
|
+
const colorIconWebUrl = item.appDefinitions[0].colorIcon?.webUrl;
|
|
297
|
+
const manifestsWithoutIcon = [];
|
|
298
|
+
const dashboardCards = item.appDefinitions[0].dashboardCards || [];
|
|
299
|
+
const manifests = [];
|
|
300
|
+
dashboardCards.forEach((dashboardCard)=>{
|
|
301
|
+
const component = {
|
|
348
302
|
appId: item.id,
|
|
349
303
|
externalAppId: item.externalId || undefined,
|
|
350
304
|
componentId: dashboardCard.id,
|
|
351
|
-
groupId: ADVANCED_TOOLBOX_GROUP_ID,
|
|
352
|
-
iconUrl:
|
|
353
|
-
officeUIFabricIconName:
|
|
305
|
+
groupId: ADVANCED_TOOLBOX_GROUP_ID,
|
|
306
|
+
iconUrl: dashboardCard.icon?.iconUrl,
|
|
307
|
+
officeUIFabricIconName: dashboardCard.icon?.officeUIFabricIconName,
|
|
354
308
|
description: dashboardCard.description,
|
|
355
309
|
name: dashboardCard.displayName,
|
|
356
310
|
botId: dashboardCard.contentSource.botConfiguration.botId,
|
|
@@ -358,29 +312,23 @@ var TeamsAppsClient = /** @class */ (function () {
|
|
|
358
312
|
appDescription: item.appDefinitions[0].description,
|
|
359
313
|
version: item.appDefinitions[0].version,
|
|
360
314
|
// size is lower case in the manifest
|
|
361
|
-
defaultSize:
|
|
315
|
+
defaultSize: `${dashboardCard.defaultSize.charAt(0).toUpperCase()}${dashboardCard.defaultSize.slice(1)}`
|
|
362
316
|
};
|
|
363
|
-
|
|
317
|
+
const manifest = this._teamsAppComponentToAceManifest(component);
|
|
364
318
|
manifests.push(manifest);
|
|
365
319
|
if (!component.iconUrl && !component.officeUIFabricIconName) {
|
|
366
320
|
manifestsWithoutIcon.push(manifest);
|
|
367
|
-
if (!iconPromise && colorIconWebUrl)
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
.api(colorIconWebUrl)
|
|
371
|
-
.responseType('blob')
|
|
372
|
-
.get();
|
|
373
|
-
});
|
|
321
|
+
if (!iconPromise && colorIconWebUrl) iconPromise = this._msGraphClient.then((client)=>{
|
|
322
|
+
return client.api(colorIconWebUrl).responseType('blob').get();
|
|
323
|
+
});
|
|
374
324
|
}
|
|
375
325
|
});
|
|
376
|
-
|
|
326
|
+
let resultPromise = Promise.resolve(manifests);
|
|
377
327
|
if (manifestsWithoutIcon.length && iconPromise) {
|
|
378
|
-
resultPromise = iconPromise
|
|
379
|
-
.
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
.then(function (iconUrl) {
|
|
383
|
-
manifestsWithoutIcon.forEach(function (manifest) {
|
|
328
|
+
resultPromise = iconPromise.then((response)=>{
|
|
329
|
+
return this._convertBlobToBase64(response);
|
|
330
|
+
}).then((iconUrl)=>{
|
|
331
|
+
manifestsWithoutIcon.forEach((manifest)=>{
|
|
384
332
|
manifest.preconfiguredEntries[0].iconImageUrl = iconUrl;
|
|
385
333
|
manifest.properties.teamsAppComponent.iconUrl = iconUrl;
|
|
386
334
|
});
|
|
@@ -388,13 +336,13 @@ var TeamsAppsClient = /** @class */ (function () {
|
|
|
388
336
|
});
|
|
389
337
|
}
|
|
390
338
|
return resultPromise;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
return new Promise(
|
|
394
|
-
|
|
339
|
+
}
|
|
340
|
+
_convertBlobToBase64(blob) {
|
|
341
|
+
return new Promise((resolve, reject)=>{
|
|
342
|
+
const reader = new FileReader();
|
|
395
343
|
reader.onerror = reject;
|
|
396
|
-
reader.onload =
|
|
397
|
-
|
|
344
|
+
reader.onload = ()=>{
|
|
345
|
+
const base64String = reader.result;
|
|
398
346
|
if (!base64String) {
|
|
399
347
|
reject('');
|
|
400
348
|
}
|
|
@@ -402,8 +350,8 @@ var TeamsAppsClient = /** @class */ (function () {
|
|
|
402
350
|
};
|
|
403
351
|
reader.readAsDataURL(blob);
|
|
404
352
|
});
|
|
405
|
-
}
|
|
406
|
-
|
|
353
|
+
}
|
|
354
|
+
_teamsAppComponentToAceManifest(component) {
|
|
407
355
|
return {
|
|
408
356
|
id: component.componentId,
|
|
409
357
|
manifestVersion: MANIFEST_VERSION,
|
|
@@ -415,7 +363,9 @@ var TeamsAppsClient = /** @class */ (function () {
|
|
|
415
363
|
},
|
|
416
364
|
loaderConfig: {
|
|
417
365
|
entryModuleId: component.componentId,
|
|
418
|
-
internalModuleBaseUrls: [
|
|
366
|
+
internalModuleBaseUrls: [
|
|
367
|
+
'HTTPS://CLIENTSIDEASSETSLIBRARY/'
|
|
368
|
+
],
|
|
419
369
|
scriptResources: {}
|
|
420
370
|
},
|
|
421
371
|
preconfiguredEntries: [
|
|
@@ -436,8 +386,16 @@ var TeamsAppsClient = /** @class */ (function () {
|
|
|
436
386
|
connectedTeamsAppId: component.appId,
|
|
437
387
|
isPendingTeamsAppSync: true
|
|
438
388
|
};
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
389
|
+
}
|
|
390
|
+
constructor(serviceScope){
|
|
391
|
+
/**
|
|
392
|
+
* Map[teamsAppId, Promise[Set[teamsAppId]]]
|
|
393
|
+
*
|
|
394
|
+
* We store a map where the same promise can be used for multiple entries.
|
|
395
|
+
* In that case we can avoid multiple requests to the API for the same teamsAppId as well as avoid race conditions and allow to make extra requests if needed.
|
|
396
|
+
*/ this._appComponentsPermissionsPromises = new Map();
|
|
397
|
+
this._serviceScope = serviceScope;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
//# sourceMappingURL=./TeamsAppsClient.js.map
|