@microsoft/sp-http-msgraph 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.
Files changed (49) hide show
  1. package/dist/aec2bbfd-a968-4d5b-a279-12e570f378e6.manifest.json +132 -142
  2. package/dist/chunk.sp-http-msgraphclient_none_c219d50ed0c3718eb04c.js +2 -0
  3. package/dist/chunk.sp-http-msgraphclientv3_none_f69d5240fbc396e22113.js +2 -0
  4. package/dist/sp-http-msgraph_default_b1a01d6b4cff75fbeb8b.js +2 -0
  5. package/dist/sp-http-msgraph_en-us_c25b4ebcf02eb1bfeda7.js +2 -0
  6. package/dist/sp-http-msgraph_qps-ploc_e3ac749f677a1d25e5d1.js +2 -0
  7. package/dist/sp-http-msgraph_qps-ploca_1b3894e46de77590c544.js +2 -0
  8. package/dist/tsdoc-metadata.json +1 -1
  9. package/lib-commonjs/KillSwitches.js +16 -0
  10. package/lib-commonjs/MSGraphAuthenticationProvider.js +39 -33
  11. package/lib-commonjs/MSGraphClient.js +71 -82
  12. package/lib-commonjs/MSGraphClientFactory.js +73 -79
  13. package/lib-commonjs/MSGraphClientV3.js +135 -156
  14. package/lib-commonjs/common/Killswitches.js +26 -16
  15. package/lib-commonjs/index.js +23 -12
  16. package/lib-dts/KillSwitches.d.ts +2 -0
  17. package/lib-esm/KillSwitches.js +6 -0
  18. package/lib-esm/MSGraphAuthenticationProvider.js +49 -0
  19. package/lib-esm/MSGraphClient.js +97 -0
  20. package/lib-esm/MSGraphClientFactory.js +94 -0
  21. package/lib-esm/MSGraphClientV3.js +190 -0
  22. package/{lib → lib-esm}/common/Killswitches.js +5 -10
  23. package/{lib → lib-esm}/index.js +3 -3
  24. package/package.json +41 -10
  25. package/dist/chunk.sp-http-msgraphclient_none_480d82d37e0f32d71f13.js +0 -2
  26. package/dist/chunk.sp-http-msgraphclientv3_none_2f92cf18b28fcffe75bf.js +0 -2
  27. package/dist/sp-http-msgraph_default_984fa6f1d4c9bf26a529.js +0 -1
  28. package/dist/sp-http-msgraph_en-us_cd6999e137b942d4dcb2.js +0 -1
  29. package/dist/sp-http-msgraph_qps-ploc_7350436220b69245f0ce.js +0 -1
  30. package/dist/sp-http-msgraph_qps-ploca_a7714aa16fc1a1bf917d.js +0 -1
  31. package/lib/MSGraphAuthenticationProvider.d.ts.map +0 -1
  32. package/lib/MSGraphAuthenticationProvider.js +0 -50
  33. package/lib/MSGraphClient.d.ts.map +0 -1
  34. package/lib/MSGraphClient.js +0 -104
  35. package/lib/MSGraphClientFactory.d.ts.map +0 -1
  36. package/lib/MSGraphClientFactory.js +0 -106
  37. package/lib/MSGraphClientV3.d.ts.map +0 -1
  38. package/lib/MSGraphClientV3.js +0 -206
  39. package/lib/common/Killswitches.d.ts.map +0 -1
  40. package/lib/index.d.ts.map +0 -1
  41. /package/{lib → lib-dts}/MSGraphAuthenticationProvider.d.ts +0 -0
  42. /package/{lib → lib-dts}/MSGraphClient.d.ts +0 -0
  43. /package/{lib → lib-dts}/MSGraphClientFactory.d.ts +0 -0
  44. /package/{lib → lib-dts}/MSGraphClientV3.d.ts +0 -0
  45. /package/{lib → lib-dts}/SPHttpMsGraphStrings.resx.d.ts +0 -0
  46. /package/{lib → lib-dts}/common/Killswitches.d.ts +0 -0
  47. /package/{lib → lib-dts}/index.d.ts +0 -0
  48. /package/{lib → lib-esm}/SPHttpMsGraphStrings.resx.json +0 -0
  49. /package/{lib → lib-esm}/sp-http-msgraph.manifest.json +0 -0
@@ -1,208 +1,187 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
4
- var sp_core_library_1 = require("@microsoft/sp-core-library");
5
- var sp_diagnostics_1 = require("@microsoft/sp-diagnostics");
6
- var ms_graph_v3_bundle_1 = require("@msinternal/ms-graph-v3-bundle");
7
- var sp_http_base_1 = require("@microsoft/sp-http-base");
8
- var Killswitches_1 = require("./common/Killswitches");
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
- * All calls to Microsoft Graph are chained together starting with the api function.
63
- *
64
- * @remarks Path supports the following formats:
65
- * * me
66
- * * /me
67
- * * https://graph.microsoft.com/v1.0/me
68
- * * https://graph.microsoft.com/beta/me
69
- * * me/events?$filter=startswith(subject, 'ship')
70
- *
71
- * The authProvider and baseUrl option should not be used, as they have already been
72
- * provided by the framework. See the official documentation here:
73
- * https://github.com/microsoftgraph/msgraph-sdk-javascript
74
- *
75
- * @param path - The path for the request to MSGraph.
76
- */
77
- MSGraphClientV3.prototype.api = function (path) {
78
- sp_core_library_1.Validate.isNonemptyString(path, 'path');
79
- if (!(0, Killswitches_1.isRequestRateMonitorKSActivated)() && this._requestRateMonitor && this._consumerComponentManifest) {
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
- var trackingUrl = path.startsWith('http')
83
- ? path
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
- Object.defineProperty(MSGraphClientV3.prototype, "client", {
94
- /**
95
- * Gets the instance of the instantiated Client object from Microsoft Graph SDK.
96
- */
97
- get: function () {
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
- catch (e) {
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
- MSGraphClientV3.prototype._createGraphClientInstanceWithMiddleware = function (tokenProvider, options) {
119
- var qosMonitor = new sp_diagnostics_1._QosMonitor('MSGraphClientV3.CreateGraphClientInstanceWithMiddleware');
120
- var graphClient;
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
- MSGraphClientV3.prototype._createInternalGraphClientInstance = function (tokenProvider, options) {
132
- var qosMonitor = new sp_diagnostics_1._QosMonitor('MSGraphClientV3.CreateInternalGraphClientInstance');
133
- var graphClient;
80
+ }
81
+ _createInternalGraphClientInstance(tokenProvider, options) {
82
+ const qosMonitor = new _spdiagnostics._QosMonitor('MSGraphClientV3.CreateInternalGraphClientInstance');
83
+ let graphClient;
134
84
  try {
135
- graphClient = this._createClientInstance(tslib_1.__assign(tslib_1.__assign({}, options), { authProvider: undefined }), tokenProvider, true);
136
- }
137
- catch (e) {
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
- MSGraphClientV3.prototype._createClientInstance = function (options, tokenProvider, isInternal) {
144
- var clientOptions = options || {};
94
+ }
95
+ _createClientInstance(options, tokenProvider, isInternal) {
96
+ const clientOptions = options || {};
145
97
  clientOptions.baseUrl = MSGraphClientV3._graphBaseUrl;
146
- var middlewareChain;
98
+ let middlewareChain;
147
99
  if (!clientOptions.middleware) {
148
100
  // creating default chain
149
- middlewareChain = ms_graph_v3_bundle_1.MiddlewareFactory.getDefaultMiddlewareChain(new MSGraphAuthenticationProvider_1.MSGraphAuthenticationProvider(tokenProvider, MSGraphClientV3._graphBaseUrl, isInternal));
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
- var authMiddleware = new ms_graph_v3_bundle_1.AuthenticationHandler(new MSGraphAuthenticationProvider_1.MSGraphAuthenticationProvider(tokenProvider, MSGraphClientV3._graphBaseUrl, isInternal));
154
- middlewareChain = [authMiddleware];
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.apply(middlewareChain, clientOptions.middleware);
157
- }
158
- else {
109
+ middlewareChain.push(...clientOptions.middleware);
110
+ } else {
159
111
  middlewareChain.push(clientOptions.middleware);
160
112
  }
161
113
  }
162
- if (!(0, Killswitches_1.isPassSdkVersionKSActivated)() && this._consumerComponentManifest) {
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
- var sdkVersionValue = "SPFx/".concat(this._consumerComponentManifest.alias, "/").concat(this._consumerComponentManifest.id, "/Is3PRequest:").concat(this._consumerComponentManifest.isInternal ? '0' : '1');
170
- var headers = clientOptions.fetchOptions.headers;
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
- var sdkVersionHeaderIndex = headers.findIndex(function (header) { return header[0] === 'SdkVersion'; });
124
+ const sdkVersionHeaderIndex = headers.findIndex((header)=>header[0] === 'SdkVersion');
173
125
  if (sdkVersionHeaderIndex === -1) {
174
- headers.push(['SdkVersion', sdkVersionValue]);
175
- }
176
- else {
177
- headers[sdkVersionHeaderIndex][1] += ", ".concat(sdkVersionValue);
126
+ headers.push([
127
+ 'SdkVersion',
128
+ sdkVersionValue
129
+ ]);
130
+ } else {
131
+ headers[sdkVersionHeaderIndex][1] += `, ${sdkVersionValue}`;
178
132
  }
179
- }
180
- else if (headers instanceof Headers) {
181
- headers.has('SdkVersion')
182
- ? headers.set('SdkVersion', "".concat(headers.get('SdkVersion'), ", ").concat(sdkVersionValue))
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, Killswitches_1.isCustomHostsKSActivated)()) {
141
+ if (!(0, _Killswitches.isCustomHostsKSActivated)()) {
194
142
  try {
195
- var url = new URL(MSGraphClientV3._graphBaseUrl);
196
- clientOptions.customHosts = new Set([url.host]);
197
- }
198
- catch (e) {
199
- var qosMonitor = new sp_diagnostics_1._QosMonitor('MSGraphClientV3.CustomHostsAdditionsFailed');
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 ms_graph_v3_bundle_1.Client.initWithMiddleware(clientOptions);
204
- };
205
- return MSGraphClientV3;
206
- }());
207
- exports.default = MSGraphClientV3;
208
- //# sourceMappingURL=MSGraphClientV3.js.map
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", { value: true });
3
- exports.isRequestRateMonitorKSActivated = exports.isCustomHostsKSActivated = exports.isPassSdkVersionKSActivated = void 0;
4
- var sp_core_library_1 = require("@microsoft/sp-core-library");
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 sp_core_library_1._SPKillSwitch.isActivated('cf20bd1c-8f94-466b-b394-382640c75c23'
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 sp_core_library_1._SPKillSwitch.isActivated('249a915b-2c26-4fe0-a2da-19f8a7b2b56e'
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 sp_core_library_1._SPKillSwitch.isActivated('c76f25a9-9d5a-4860-8883-fcacc64a0b19'
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
- exports.isRequestRateMonitorKSActivated = isRequestRateMonitorKSActivated;
23
- //# sourceMappingURL=Killswitches.js.map
32
+
33
+ //# sourceMappingURL=./Killswitches.js.map
@@ -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
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.MSGraphClientFactory = exports.MSGraphClient = void 0;
16
- var MSGraphClient_1 = require("./MSGraphClient");
17
- Object.defineProperty(exports, "MSGraphClient", { enumerable: true, get: function () { return __importDefault(MSGraphClient_1).default; } });
18
- var MSGraphClientFactory_1 = require("./MSGraphClientFactory");
19
- Object.defineProperty(exports, "MSGraphClientFactory", { enumerable: true, get: function () { return __importDefault(MSGraphClientFactory_1).default; } });
20
- //# sourceMappingURL=index.js.map
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,2 @@
1
+ export declare function isGraphWellKnownResourceKSActive(): boolean;
2
+ //# sourceMappingURL=KillSwitches.d.ts.map
@@ -0,0 +1,6 @@
1
+ import { _SPKillSwitch } from '@microsoft/sp-core-library';
2
+ export function isGraphWellKnownResourceKSActive() {
3
+ return _SPKillSwitch.isActivated('a7659ada-5442-4d25-9f21-3be655f51cda');
4
+ }
5
+
6
+ //# sourceMappingURL=./KillSwitches.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