@microsoft/sp-http-msgraph 1.23.2 → 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/aec2bbfd-a968-4d5b-a279-12e570f378e6.manifest.json +132 -142
- package/dist/chunk.sp-http-msgraphclient_none_c219d50ed0c3718eb04c.js +2 -0
- package/dist/chunk.sp-http-msgraphclientv3_none_f69d5240fbc396e22113.js +2 -0
- package/dist/sp-http-msgraph_default_b1a01d6b4cff75fbeb8b.js +2 -0
- package/dist/sp-http-msgraph_en-us_c25b4ebcf02eb1bfeda7.js +2 -0
- package/dist/sp-http-msgraph_qps-ploc_e3ac749f677a1d25e5d1.js +2 -0
- package/dist/sp-http-msgraph_qps-ploca_1b3894e46de77590c544.js +2 -0
- package/dist/tsdoc-metadata.json +1 -1
- package/lib-commonjs/KillSwitches.js +16 -0
- package/lib-commonjs/MSGraphAuthenticationProvider.js +39 -33
- package/lib-commonjs/MSGraphClient.js +71 -82
- package/lib-commonjs/MSGraphClientFactory.js +73 -79
- package/lib-commonjs/MSGraphClientV3.js +135 -156
- package/lib-commonjs/common/Killswitches.js +26 -16
- package/lib-commonjs/index.js +23 -12
- package/lib-dts/KillSwitches.d.ts +2 -0
- package/lib-esm/KillSwitches.js +6 -0
- package/lib-esm/MSGraphAuthenticationProvider.js +49 -0
- package/lib-esm/MSGraphClient.js +97 -0
- package/lib-esm/MSGraphClientFactory.js +94 -0
- package/lib-esm/MSGraphClientV3.js +190 -0
- package/{lib → lib-esm}/common/Killswitches.js +5 -10
- package/{lib → lib-esm}/index.js +3 -3
- package/package.json +39 -8
- package/dist/chunk.sp-http-msgraphclient_none_99a41fce9bf3925a21e2.js +0 -2
- package/dist/chunk.sp-http-msgraphclientv3_none_c34e76d04711b268a3cd.js +0 -2
- package/dist/sp-http-msgraph_default_6e69c31eaaed44b5aab3.js +0 -1
- package/dist/sp-http-msgraph_en-us_26c6c90f8da57ad234d5.js +0 -1
- package/dist/sp-http-msgraph_qps-ploc_db5eb720e90b9545bca7.js +0 -1
- package/dist/sp-http-msgraph_qps-ploca_cb2655427d0c64681f92.js +0 -1
- package/lib/MSGraphAuthenticationProvider.d.ts.map +0 -1
- package/lib/MSGraphAuthenticationProvider.js +0 -50
- package/lib/MSGraphClient.d.ts.map +0 -1
- package/lib/MSGraphClient.js +0 -104
- package/lib/MSGraphClientFactory.d.ts.map +0 -1
- package/lib/MSGraphClientFactory.js +0 -106
- package/lib/MSGraphClientV3.d.ts.map +0 -1
- package/lib/MSGraphClientV3.js +0 -206
- package/lib/common/Killswitches.d.ts.map +0 -1
- package/lib/index.d.ts.map +0 -1
- /package/{lib → lib-dts}/MSGraphAuthenticationProvider.d.ts +0 -0
- /package/{lib → lib-dts}/MSGraphClient.d.ts +0 -0
- /package/{lib → lib-dts}/MSGraphClientFactory.d.ts +0 -0
- /package/{lib → lib-dts}/MSGraphClientV3.d.ts +0 -0
- /package/{lib → lib-dts}/SPHttpMsGraphStrings.resx.d.ts +0 -0
- /package/{lib → lib-dts}/common/Killswitches.d.ts +0 -0
- /package/{lib → lib-dts}/index.d.ts +0 -0
- /package/{lib → lib-esm}/SPHttpMsGraphStrings.resx.json +0 -0
- /package/{lib → lib-esm}/sp-http-msgraph.manifest.json +0 -0
|
@@ -1,208 +1,187 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var MSGraphAuthenticationProvider_1 = require("./MSGraphAuthenticationProvider");
|
|
10
|
-
/**
|
|
11
|
-
* MSGraphClient is used to perform REST calls against Microsoft Graph.
|
|
12
|
-
*
|
|
13
|
-
* @remarks The Microsoft Graph JavaScript client library is a lightweight wrapper around the
|
|
14
|
-
* Microsoft Graph API. This class allows developers to start making REST calls to MSGraph without
|
|
15
|
-
* needing to initialize the the MSGraph client library. If a custom configuration is desired,
|
|
16
|
-
* the MSGraphClient api function needs to be provided with that custom configuration for
|
|
17
|
-
* every request.
|
|
18
|
-
*
|
|
19
|
-
* For more information: {@link https://github.com/microsoftgraph/msgraph-sdk-javascript}
|
|
20
|
-
*
|
|
21
|
-
* @public
|
|
22
|
-
*/
|
|
23
|
-
var MSGraphClientV3 = /** @class */ (function () {
|
|
24
|
-
/**
|
|
25
|
-
* @param serviceScope - Provides services for the MSGraphClient to consume.
|
|
26
|
-
*
|
|
27
|
-
* @internal
|
|
28
|
-
*/
|
|
29
|
-
function MSGraphClientV3(serviceScope, options, clientOptions, internalClient) {
|
|
30
|
-
var _this = this;
|
|
31
|
-
this._isInternal = false;
|
|
32
|
-
serviceScope.whenFinished(function () {
|
|
33
|
-
if (!MSGraphClientV3._graphBaseUrl) {
|
|
34
|
-
MSGraphClientV3._graphBaseUrl = serviceScope
|
|
35
|
-
.consume(sp_http_base_1._GraphHttpClientContext.serviceKey)
|
|
36
|
-
.getGraphEndpointUrl();
|
|
37
|
-
}
|
|
38
|
-
if (!(0, Killswitches_1.isPassSdkVersionKSActivated)()) {
|
|
39
|
-
var clientManifestData = serviceScope.consume(sp_core_library_1._ClientManifestData.serviceKey);
|
|
40
|
-
_this._consumerComponentManifest = clientManifestData.manifest;
|
|
41
|
-
}
|
|
42
|
-
if (!(0, Killswitches_1.isRequestRateMonitorKSActivated)()) {
|
|
43
|
-
_this._requestRateMonitor = serviceScope.consume(sp_http_base_1._SPRequestRateMonitor.serviceKey);
|
|
44
|
-
}
|
|
45
|
-
if (internalClient) {
|
|
46
|
-
_this._isInternal = true;
|
|
47
|
-
if (!MSGraphClientV3._internalInstance) {
|
|
48
|
-
MSGraphClientV3._internalInstance = _this._createInternalGraphClientInstance(sp_http_base_1._AadTokenProviders.configurable, options);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
else if (!MSGraphClientV3._instance) {
|
|
52
|
-
if (clientOptions !== undefined) {
|
|
53
|
-
MSGraphClientV3._instance = _this._createGraphClientInstanceWithMiddleware(sp_http_base_1._AadTokenProviders.configurable, clientOptions);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
MSGraphClientV3._instance = _this._createGraphClientInstance(sp_http_base_1._AadTokenProviders.configurable, options);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
});
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return MSGraphClientV3;
|
|
60
9
|
}
|
|
10
|
+
});
|
|
11
|
+
const _spcorelibrary = require("@microsoft/sp-core-library");
|
|
12
|
+
const _spdiagnostics = require("@microsoft/sp-diagnostics");
|
|
13
|
+
const _msgraphv3bundle = require("@msinternal/ms-graph-v3-bundle");
|
|
14
|
+
const _sphttpbase = require("@microsoft/sp-http-base");
|
|
15
|
+
const _Killswitches = require("./common/Killswitches");
|
|
16
|
+
const _MSGraphAuthenticationProvider = require("./MSGraphAuthenticationProvider");
|
|
17
|
+
class MSGraphClientV3 {
|
|
61
18
|
/**
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
var _a = this._consumerComponentManifest, componentType = _a.componentType, alias = _a.alias, id = _a.id;
|
|
19
|
+
* All calls to Microsoft Graph are chained together starting with the api function.
|
|
20
|
+
*
|
|
21
|
+
* @remarks Path supports the following formats:
|
|
22
|
+
* * me
|
|
23
|
+
* * /me
|
|
24
|
+
* * https://graph.microsoft.com/v1.0/me
|
|
25
|
+
* * https://graph.microsoft.com/beta/me
|
|
26
|
+
* * me/events?$filter=startswith(subject, 'ship')
|
|
27
|
+
*
|
|
28
|
+
* The authProvider and baseUrl option should not be used, as they have already been
|
|
29
|
+
* provided by the framework. See the official documentation here:
|
|
30
|
+
* https://github.com/microsoftgraph/msgraph-sdk-javascript
|
|
31
|
+
*
|
|
32
|
+
* @param path - The path for the request to MSGraph.
|
|
33
|
+
*/ api(path) {
|
|
34
|
+
_spcorelibrary.Validate.isNonemptyString(path, 'path');
|
|
35
|
+
if (!(0, _Killswitches.isRequestRateMonitorKSActivated)() && this._requestRateMonitor && this._consumerComponentManifest) {
|
|
36
|
+
const { componentType, alias, id } = this._consumerComponentManifest;
|
|
81
37
|
if (componentType === 'WebPart' || componentType === 'AdaptiveCardExtension') {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
: new URL(path.replace(/^\//, ''), MSGraphClientV3._graphBaseUrl).href;
|
|
85
|
-
this._requestRateMonitor.trackRequest(trackingUrl, "".concat(componentType, ".").concat(alias, ".").concat(id));
|
|
38
|
+
const trackingUrl = path.startsWith('http') ? path : new URL(path.replace(/^\//, ''), MSGraphClientV3._graphBaseUrl).href;
|
|
39
|
+
this._requestRateMonitor.trackRequest(trackingUrl, `${componentType}.${alias}.${id}`);
|
|
86
40
|
}
|
|
87
41
|
}
|
|
88
42
|
if (this._isInternal) {
|
|
89
43
|
return MSGraphClientV3._internalInstance.api(path);
|
|
90
44
|
}
|
|
91
45
|
return MSGraphClientV3._instance.api(path);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (this._isInternal) {
|
|
99
|
-
return MSGraphClientV3._internalInstance;
|
|
100
|
-
}
|
|
101
|
-
return MSGraphClientV3._instance;
|
|
102
|
-
},
|
|
103
|
-
enumerable: false,
|
|
104
|
-
configurable: true
|
|
105
|
-
});
|
|
106
|
-
MSGraphClientV3.prototype._createGraphClientInstance = function (tokenProvider, options) {
|
|
107
|
-
var qosMonitor = new sp_diagnostics_1._QosMonitor('MSGraphClientV3.CreateGraphClientInstance');
|
|
108
|
-
var graphClient;
|
|
109
|
-
try {
|
|
110
|
-
graphClient = this._createClientInstance(tslib_1.__assign(tslib_1.__assign({}, options), { authProvider: undefined }), tokenProvider, false);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Gets the instance of the instantiated Client object from Microsoft Graph SDK.
|
|
49
|
+
*/ get client() {
|
|
50
|
+
if (this._isInternal) {
|
|
51
|
+
return MSGraphClientV3._internalInstance;
|
|
111
52
|
}
|
|
112
|
-
|
|
53
|
+
return MSGraphClientV3._instance;
|
|
54
|
+
}
|
|
55
|
+
_createGraphClientInstance(tokenProvider, options) {
|
|
56
|
+
const qosMonitor = new _spdiagnostics._QosMonitor('MSGraphClientV3.CreateGraphClientInstance');
|
|
57
|
+
let graphClient;
|
|
58
|
+
try {
|
|
59
|
+
graphClient = this._createClientInstance({
|
|
60
|
+
...options,
|
|
61
|
+
authProvider: undefined
|
|
62
|
+
}, tokenProvider, false);
|
|
63
|
+
} catch (e) {
|
|
113
64
|
qosMonitor.writeUnexpectedFailure(e.message, e);
|
|
114
65
|
throw e;
|
|
115
66
|
}
|
|
116
67
|
return graphClient;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
68
|
+
}
|
|
69
|
+
_createGraphClientInstanceWithMiddleware(tokenProvider, options) {
|
|
70
|
+
const qosMonitor = new _spdiagnostics._QosMonitor('MSGraphClientV3.CreateGraphClientInstanceWithMiddleware');
|
|
71
|
+
let graphClient;
|
|
121
72
|
try {
|
|
122
73
|
graphClient = this._createClientInstance(options, tokenProvider, false);
|
|
123
74
|
qosMonitor.writeSuccess();
|
|
124
75
|
return graphClient;
|
|
125
|
-
}
|
|
126
|
-
catch (e) {
|
|
76
|
+
} catch (e) {
|
|
127
77
|
qosMonitor.writeUnexpectedFailure(e.message, e);
|
|
128
78
|
throw e;
|
|
129
79
|
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
80
|
+
}
|
|
81
|
+
_createInternalGraphClientInstance(tokenProvider, options) {
|
|
82
|
+
const qosMonitor = new _spdiagnostics._QosMonitor('MSGraphClientV3.CreateInternalGraphClientInstance');
|
|
83
|
+
let graphClient;
|
|
134
84
|
try {
|
|
135
|
-
graphClient = this._createClientInstance(
|
|
136
|
-
|
|
137
|
-
|
|
85
|
+
graphClient = this._createClientInstance({
|
|
86
|
+
...options,
|
|
87
|
+
authProvider: undefined
|
|
88
|
+
}, tokenProvider, true);
|
|
89
|
+
} catch (e) {
|
|
138
90
|
qosMonitor.writeUnexpectedFailure(e.message, e);
|
|
139
91
|
throw e;
|
|
140
92
|
}
|
|
141
93
|
return graphClient;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
94
|
+
}
|
|
95
|
+
_createClientInstance(options, tokenProvider, isInternal) {
|
|
96
|
+
const clientOptions = options || {};
|
|
145
97
|
clientOptions.baseUrl = MSGraphClientV3._graphBaseUrl;
|
|
146
|
-
|
|
98
|
+
let middlewareChain;
|
|
147
99
|
if (!clientOptions.middleware) {
|
|
148
100
|
// creating default chain
|
|
149
|
-
middlewareChain =
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
101
|
+
middlewareChain = _msgraphv3bundle.MiddlewareFactory.getDefaultMiddlewareChain(new _MSGraphAuthenticationProvider.MSGraphAuthenticationProvider(tokenProvider, MSGraphClientV3._graphBaseUrl, isInternal));
|
|
102
|
+
} else {
|
|
152
103
|
// a developer has provided middleware(s)
|
|
153
|
-
|
|
154
|
-
middlewareChain = [
|
|
104
|
+
const authMiddleware = new _msgraphv3bundle.AuthenticationHandler(new _MSGraphAuthenticationProvider.MSGraphAuthenticationProvider(tokenProvider, MSGraphClientV3._graphBaseUrl, isInternal));
|
|
105
|
+
middlewareChain = [
|
|
106
|
+
authMiddleware
|
|
107
|
+
];
|
|
155
108
|
if (Array.isArray(clientOptions.middleware)) {
|
|
156
|
-
middlewareChain.push
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
109
|
+
middlewareChain.push(...clientOptions.middleware);
|
|
110
|
+
} else {
|
|
159
111
|
middlewareChain.push(clientOptions.middleware);
|
|
160
112
|
}
|
|
161
113
|
}
|
|
162
|
-
if (!(0,
|
|
114
|
+
if (!(0, _Killswitches.isPassSdkVersionKSActivated)() && this._consumerComponentManifest) {
|
|
163
115
|
if (!clientOptions.fetchOptions) {
|
|
164
116
|
clientOptions.fetchOptions = {};
|
|
165
117
|
}
|
|
166
118
|
if (!clientOptions.fetchOptions.headers) {
|
|
167
119
|
clientOptions.fetchOptions.headers = {};
|
|
168
120
|
}
|
|
169
|
-
|
|
170
|
-
|
|
121
|
+
const sdkVersionValue = `SPFx/${this._consumerComponentManifest.alias}/${this._consumerComponentManifest.id}/Is3PRequest:${this._consumerComponentManifest.isInternal ? '0' : '1'}`;
|
|
122
|
+
const { headers } = clientOptions.fetchOptions;
|
|
171
123
|
if (Array.isArray(headers)) {
|
|
172
|
-
|
|
124
|
+
const sdkVersionHeaderIndex = headers.findIndex((header)=>header[0] === 'SdkVersion');
|
|
173
125
|
if (sdkVersionHeaderIndex === -1) {
|
|
174
|
-
headers.push([
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
126
|
+
headers.push([
|
|
127
|
+
'SdkVersion',
|
|
128
|
+
sdkVersionValue
|
|
129
|
+
]);
|
|
130
|
+
} else {
|
|
131
|
+
headers[sdkVersionHeaderIndex][1] += `, ${sdkVersionValue}`;
|
|
178
132
|
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
: headers.set('SdkVersion', sdkVersionValue);
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
headers.SdkVersion = headers.SdkVersions
|
|
187
|
-
? "".concat(headers.SdkVersion, ", ").concat(sdkVersionValue)
|
|
188
|
-
: sdkVersionValue;
|
|
133
|
+
} else if (headers instanceof Headers) {
|
|
134
|
+
headers.has('SdkVersion') ? headers.set('SdkVersion', `${headers.get('SdkVersion')}, ${sdkVersionValue}`) : headers.set('SdkVersion', sdkVersionValue);
|
|
135
|
+
} else {
|
|
136
|
+
headers.SdkVersion = headers.SdkVersions ? `${headers.SdkVersion}, ${sdkVersionValue}` : sdkVersionValue;
|
|
189
137
|
}
|
|
190
138
|
}
|
|
191
139
|
// we can add more middleware to the end of the chain here
|
|
192
140
|
clientOptions.middleware = middlewareChain;
|
|
193
|
-
if (!(0,
|
|
141
|
+
if (!(0, _Killswitches.isCustomHostsKSActivated)()) {
|
|
194
142
|
try {
|
|
195
|
-
|
|
196
|
-
clientOptions.customHosts = new Set([
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
143
|
+
const url = new URL(MSGraphClientV3._graphBaseUrl);
|
|
144
|
+
clientOptions.customHosts = new Set([
|
|
145
|
+
url.host
|
|
146
|
+
]);
|
|
147
|
+
} catch (e) {
|
|
148
|
+
const qosMonitor = new _spdiagnostics._QosMonitor('MSGraphClientV3.CustomHostsAdditionsFailed');
|
|
200
149
|
qosMonitor.writeUnexpectedFailure(e.message, e);
|
|
201
150
|
}
|
|
202
151
|
}
|
|
203
|
-
return
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
152
|
+
return _msgraphv3bundle.Client.initWithMiddleware(clientOptions);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* @param serviceScope - Provides services for the MSGraphClient to consume.
|
|
156
|
+
*
|
|
157
|
+
* @internal
|
|
158
|
+
*/ constructor(serviceScope, options, clientOptions, internalClient){
|
|
159
|
+
this._isInternal = false;
|
|
160
|
+
serviceScope.whenFinished(()=>{
|
|
161
|
+
if (!MSGraphClientV3._graphBaseUrl) {
|
|
162
|
+
MSGraphClientV3._graphBaseUrl = serviceScope.consume(_sphttpbase._GraphHttpClientContext.serviceKey).getGraphEndpointUrl();
|
|
163
|
+
}
|
|
164
|
+
if (!(0, _Killswitches.isPassSdkVersionKSActivated)()) {
|
|
165
|
+
const clientManifestData = serviceScope.consume(_spcorelibrary._ClientManifestData.serviceKey);
|
|
166
|
+
this._consumerComponentManifest = clientManifestData.manifest;
|
|
167
|
+
}
|
|
168
|
+
if (!(0, _Killswitches.isRequestRateMonitorKSActivated)()) {
|
|
169
|
+
this._requestRateMonitor = serviceScope.consume(_sphttpbase._SPRequestRateMonitor.serviceKey);
|
|
170
|
+
}
|
|
171
|
+
if (internalClient) {
|
|
172
|
+
this._isInternal = true;
|
|
173
|
+
if (!MSGraphClientV3._internalInstance) {
|
|
174
|
+
MSGraphClientV3._internalInstance = this._createInternalGraphClientInstance(_sphttpbase._AadTokenProviders.configurable, options);
|
|
175
|
+
}
|
|
176
|
+
} else if (!MSGraphClientV3._instance) {
|
|
177
|
+
if (clientOptions !== undefined) {
|
|
178
|
+
MSGraphClientV3._instance = this._createGraphClientInstanceWithMiddleware(_sphttpbase._AadTokenProviders.configurable, clientOptions);
|
|
179
|
+
} else {
|
|
180
|
+
MSGraphClientV3._instance = this._createGraphClientInstance(_sphttpbase._AadTokenProviders.configurable, options);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
//# sourceMappingURL=./MSGraphClientV3.js.map
|
|
@@ -1,23 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
isCustomHostsKSActivated: function() {
|
|
13
|
+
return isCustomHostsKSActivated;
|
|
14
|
+
},
|
|
15
|
+
isPassSdkVersionKSActivated: function() {
|
|
16
|
+
return isPassSdkVersionKSActivated;
|
|
17
|
+
},
|
|
18
|
+
isRequestRateMonitorKSActivated: function() {
|
|
19
|
+
return isRequestRateMonitorKSActivated;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const _spcorelibrary = require("@microsoft/sp-core-library");
|
|
5
23
|
function isPassSdkVersionKSActivated() {
|
|
6
|
-
return
|
|
7
|
-
/* '04/10/2023', 'aterentiev - Pass SdkVersion header to MS Graph requests'*/
|
|
8
|
-
);
|
|
24
|
+
return _spcorelibrary._SPKillSwitch.isActivated('cf20bd1c-8f94-466b-b394-382640c75c23');
|
|
9
25
|
}
|
|
10
|
-
exports.isPassSdkVersionKSActivated = isPassSdkVersionKSActivated;
|
|
11
26
|
function isCustomHostsKSActivated() {
|
|
12
|
-
return
|
|
13
|
-
/* '09/06/2024', 'grahamc - Add currrent graph endpoint to custom hosts'*/
|
|
14
|
-
);
|
|
27
|
+
return _spcorelibrary._SPKillSwitch.isActivated('249a915b-2c26-4fe0-a2da-19f8a7b2b56e');
|
|
15
28
|
}
|
|
16
|
-
exports.isCustomHostsKSActivated = isCustomHostsKSActivated;
|
|
17
29
|
function isRequestRateMonitorKSActivated() {
|
|
18
|
-
return
|
|
19
|
-
/* '2/25/2026', 'tianbli - Disable request rate monitoring for web parts' */
|
|
20
|
-
);
|
|
30
|
+
return _spcorelibrary._SPKillSwitch.isActivated('c76f25a9-9d5a-4860-8883-fcacc64a0b19');
|
|
21
31
|
}
|
|
22
|
-
|
|
23
|
-
//# sourceMappingURL
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=./Killswitches.js.map
|
package/lib-commonjs/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Microsoft Graph communication layer for the SharePoint Framework
|
|
4
3
|
*
|
|
@@ -7,14 +6,26 @@
|
|
|
7
6
|
* the SharePoint Framework.
|
|
8
7
|
*
|
|
9
8
|
* @packagedocumentation
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
*/ "use strict";
|
|
10
|
+
Object.defineProperty(exports, "__esModule", {
|
|
11
|
+
value: true
|
|
12
|
+
});
|
|
13
|
+
function _export(target, all) {
|
|
14
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: all[name]
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
_export(exports, {
|
|
20
|
+
MSGraphClient: function() {
|
|
21
|
+
return _MSGraphClient.default;
|
|
22
|
+
},
|
|
23
|
+
MSGraphClientFactory: function() {
|
|
24
|
+
return _MSGraphClientFactory.default;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
28
|
+
const _MSGraphClient = /*#__PURE__*/ _interop_require_default._(require("./MSGraphClient"));
|
|
29
|
+
const _MSGraphClientFactory = /*#__PURE__*/ _interop_require_default._(require("./MSGraphClientFactory"));
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=./index.js.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { _QosMonitor } from '@microsoft/sp-diagnostics';
|
|
2
|
+
import { _AadTokenProviders } from '@microsoft/sp-http-base';
|
|
3
|
+
import { isGraphWellKnownResourceKSActive } from './KillSwitches';
|
|
4
|
+
export class MSGraphAuthenticationProvider {
|
|
5
|
+
getAccessToken() {
|
|
6
|
+
//
|
|
7
|
+
// theoretically, we could check if ('_getTokenInternal' in this._tokenProvider).
|
|
8
|
+
// But it could potentially lead to issues if someone adds this method to IAadTokenProvider interface.
|
|
9
|
+
//
|
|
10
|
+
if (this._isInternal) {
|
|
11
|
+
return this._getInternalToken(this._tokenProvider);
|
|
12
|
+
} else {
|
|
13
|
+
return this._getOAuthToken(this._tokenProvider);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
_getOAuthToken(tokenProvider) {
|
|
17
|
+
const qosMonitor = new _QosMonitor('MSGraphClient.FetchGraphToken');
|
|
18
|
+
const tokenPromise = !isGraphWellKnownResourceKSActive() ? tokenProvider.getToken(this._graphBaseUrl, {
|
|
19
|
+
wellKnownResource: 'ms-graph'
|
|
20
|
+
}) : tokenProvider.getToken(this._graphBaseUrl);
|
|
21
|
+
return tokenPromise.then((response)=>{
|
|
22
|
+
qosMonitor.writeSuccess();
|
|
23
|
+
return response;
|
|
24
|
+
}).catch((error)=>{
|
|
25
|
+
qosMonitor.writeUnexpectedFailure(error.message, error);
|
|
26
|
+
throw error;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
_getInternalToken(tokenProvider) {
|
|
30
|
+
const qosMonitor = new _QosMonitor('MSGraphClient.FetchInternalGraphToken');
|
|
31
|
+
const tokenPromise = !isGraphWellKnownResourceKSActive() ? tokenProvider._getTokenInternal(this._graphBaseUrl, _AadTokenProviders.preAuthorizedConfiguration, {
|
|
32
|
+
wellKnownResource: 'ms-graph'
|
|
33
|
+
}) : tokenProvider._getTokenInternal(this._graphBaseUrl, _AadTokenProviders.preAuthorizedConfiguration);
|
|
34
|
+
return tokenPromise.then((response)=>{
|
|
35
|
+
qosMonitor.writeSuccess();
|
|
36
|
+
return response;
|
|
37
|
+
}).catch((error)=>{
|
|
38
|
+
qosMonitor.writeUnexpectedFailure(error.message, error);
|
|
39
|
+
throw error;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
constructor(tokenProvider, graphBaseUrl, isInternal){
|
|
43
|
+
this._tokenProvider = tokenProvider;
|
|
44
|
+
this._graphBaseUrl = graphBaseUrl;
|
|
45
|
+
this._isInternal = isInternal;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=./MSGraphAuthenticationProvider.js.map
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Validate } from '@microsoft/sp-core-library';
|
|
2
|
+
import { _QosMonitor } from '@microsoft/sp-diagnostics';
|
|
3
|
+
import { _GraphHttpClientContext, _AadTokenProviders } from '@microsoft/sp-http-base';
|
|
4
|
+
import strings from './SPHttpMsGraphStrings.resx';
|
|
5
|
+
import { isGraphWellKnownResourceKSActive } from './KillSwitches';
|
|
6
|
+
class MSGraphClient {
|
|
7
|
+
/**
|
|
8
|
+
* All calls to Microsoft Graph are chained together starting with the api function.
|
|
9
|
+
*
|
|
10
|
+
* @remarks Path supports the following formats:
|
|
11
|
+
* * me
|
|
12
|
+
* * /me
|
|
13
|
+
* * https://graph.microsoft.com/v1.0/me
|
|
14
|
+
* * https://graph.microsoft.com/beta/me
|
|
15
|
+
* * me/events?$filter=startswith(subject, 'ship')
|
|
16
|
+
*
|
|
17
|
+
* The authProvider and baseUrl option should not be used, as they have already been
|
|
18
|
+
* provided by the framework. See the official documentation here:
|
|
19
|
+
* https://github.com/microsoftgraph/msgraph-sdk-javascript
|
|
20
|
+
*
|
|
21
|
+
* @param path - The path for the request to MSGraph.
|
|
22
|
+
* @param config - Sets the configuration for this request.
|
|
23
|
+
*/ api(path, config) {
|
|
24
|
+
Validate.isNonemptyString(path, 'path');
|
|
25
|
+
MSGraphClient._instance.config = {
|
|
26
|
+
...MSGraphClient._originalConfig,
|
|
27
|
+
...config || {}
|
|
28
|
+
};
|
|
29
|
+
return MSGraphClient._instance.api(path);
|
|
30
|
+
}
|
|
31
|
+
_createGraphClientInstance(tokenProvider) {
|
|
32
|
+
let graphClientModule;
|
|
33
|
+
if (!(MSGraphClient._window.MicrosoftGraph && MSGraphClient._window.MicrosoftGraph.Client)) {
|
|
34
|
+
throw new Error(strings.graphClientInitializationError);
|
|
35
|
+
} else {
|
|
36
|
+
// Workaround needed to interact with the Client object.
|
|
37
|
+
// See https://github.com/microsoftgraph/msgraph-sdk-javascript/issues/47 for more details
|
|
38
|
+
graphClientModule = MSGraphClient._window.MicrosoftGraph.Client;
|
|
39
|
+
// Removing window variable reference to MSGraphJsSdk object
|
|
40
|
+
MSGraphClient._window.MicrosoftGraph = undefined;
|
|
41
|
+
}
|
|
42
|
+
const graphClient = graphClientModule.init({
|
|
43
|
+
authProvider: (done)=>{
|
|
44
|
+
this._getOAuthToken(tokenProvider).then((token)=>{
|
|
45
|
+
done(undefined /** error object */ , token);
|
|
46
|
+
}).catch((e)=>{
|
|
47
|
+
// The IGraphRequest functions will return a rejected promise if it fails to get an OAuth2Token.
|
|
48
|
+
done(e, '');
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
baseUrl: MSGraphClient._graphBaseUrl
|
|
52
|
+
});
|
|
53
|
+
MSGraphClient._originalConfig = graphClient.config;
|
|
54
|
+
return graphClient;
|
|
55
|
+
}
|
|
56
|
+
_getOAuthToken(tokenProvider) {
|
|
57
|
+
const qosMonitor = new _QosMonitor('MSGraphClient.FetchGraphToken');
|
|
58
|
+
const tokenPromise = !isGraphWellKnownResourceKSActive() ? tokenProvider.getToken(MSGraphClient._graphBaseUrl, {
|
|
59
|
+
wellKnownResource: 'ms-graph'
|
|
60
|
+
}) : tokenProvider.getToken(MSGraphClient._graphBaseUrl);
|
|
61
|
+
return tokenPromise.then((response)=>{
|
|
62
|
+
qosMonitor.writeSuccess();
|
|
63
|
+
return response;
|
|
64
|
+
}).catch((error)=>{
|
|
65
|
+
qosMonitor.writeUnexpectedFailure(error.message, error);
|
|
66
|
+
throw error;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @param serviceScope - Provides services for the MSGraphClient to consume.
|
|
71
|
+
*
|
|
72
|
+
* @internal
|
|
73
|
+
*/ constructor(serviceScope){
|
|
74
|
+
serviceScope.whenFinished(()=>{
|
|
75
|
+
MSGraphClient._graphBaseUrl = serviceScope.consume(_GraphHttpClientContext.serviceKey).getGraphEndpointUrl();
|
|
76
|
+
if (!MSGraphClient._instance) {
|
|
77
|
+
MSGraphClient._instance = this._createGraphClientInstance(_AadTokenProviders.configurable);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
MSGraphClient._window = window;
|
|
83
|
+
/**
|
|
84
|
+
* MSGraphClient is used to perform REST calls against Microsoft Graph.
|
|
85
|
+
*
|
|
86
|
+
* @remarks The Microsoft Graph JavaScript client library is a lightweight wrapper around the
|
|
87
|
+
* Microsoft Graph API. This class allows developers to start making REST calls to MSGraph without
|
|
88
|
+
* needing to initialize the the MSGraph client library. If a custom configuration is desired,
|
|
89
|
+
* the MSGraphClient api function needs to be provided with that custom configuration for
|
|
90
|
+
* every request.
|
|
91
|
+
*
|
|
92
|
+
* For more information: {@link https://github.com/microsoftgraph/msgraph-sdk-javascript}
|
|
93
|
+
*
|
|
94
|
+
* @public
|
|
95
|
+
*/ export { MSGraphClient as default };
|
|
96
|
+
|
|
97
|
+
//# sourceMappingURL=./MSGraphClient.js.map
|