gd-sprest 9.7.8 → 9.7.9

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.
@@ -1,4 +1,4 @@
1
- import { IBaseExecution } from "gd-sprest-def/lib/base";
1
+ import { IBaseExecution, IRateLimit } from "gd-sprest-def/lib/base";
2
2
  import { BasePermissions, ContextWebInformation } from "gd-sprest-def/lib/SP/complextypes";
3
3
 
4
4
  /**
@@ -284,6 +284,9 @@ export interface IContextInformation {
284
284
  /** Publishing Feature On */
285
285
  PublishingFeatureOn: boolean;
286
286
 
287
+ /** The last rate limit information for a request. */
288
+ rateLimit?: IRateLimit & { requestTime: number; }
289
+
287
290
  /** Recycle Bin Item Count */
288
291
  RecycleBinItemCount: number;
289
292
 
@@ -464,6 +467,11 @@ export interface IContextInformation {
464
467
  * Methods
465
468
  */
466
469
 
470
+ /**
471
+ * Clears the callback events for the rate limit.
472
+ */
473
+ clearRateLimitCallbacks();
474
+
467
475
  /**
468
476
  * Runs a loop to ensure the digest value doesn't expire.
469
477
  */
@@ -483,6 +491,12 @@ export interface IContextInformation {
483
491
  */
484
492
  getWeb(url: string): IBaseExecution<{ GetContextWebInformation: ContextWebInformation }>;
485
493
 
494
+ /**
495
+ * Event triggered when the rate limit information is set.
496
+ * @param callback The method to execute when the rate limit value is set.
497
+ */
498
+ onRateLimitDetected(callback: (rateLimit: IRateLimit) => void);
499
+
486
500
  /**
487
501
  * Value in minutes, to refresh the token prior to it expiring
488
502
  */
@@ -493,6 +507,12 @@ export interface IContextInformation {
493
507
  * @param spfxPageContext - The page context information variable from a SPFx project.
494
508
  */
495
509
  setPageContext(spfxPageContext: any);
510
+
511
+ /**
512
+ * Sets the rate limit information from the last request containing it.
513
+ * @param rateLimit The rate limit information from the request.
514
+ */
515
+ setRateLimit(rateLimit: IRateLimit);
496
516
  }
497
517
 
498
518
  // Theme State
@@ -1,3 +1,4 @@
1
+ import { IRateLimit } from "gd-sprest-def/base";
1
2
  import { ITargetInfo } from "./targetInfo";
2
3
 
3
4
  /**
@@ -18,6 +19,9 @@ export interface IXHRRequest {
18
19
  // Flag indicating if this is a graph request
19
20
  isGraph: boolean;
20
21
 
22
+ // The rate limit information
23
+ rateLimit?: IRateLimit;
24
+
21
25
  // The response
22
26
  response: string;
23
27
 
@@ -191,6 +191,11 @@ class _ContextInfo {
191
191
  url
192
192
  });
193
193
  }
194
+ static clearRateLimitCallbacks() { this._onRateLimitCallbacks = []; }
195
+ static onRateLimitDetected(callback) {
196
+ // Add the event
197
+ this._onRateLimitCallbacks.push(callback);
198
+ }
194
199
  static enableRefreshToken(callback) {
195
200
  let isRunning = false;
196
201
  // Set the refresh event
@@ -308,6 +313,8 @@ class _ContextInfo {
308
313
  _a = _ContextInfo;
309
314
  // The page context information from an spfx project
310
315
  _ContextInfo._spfxPageContext = null;
316
+ // Method to add an event
317
+ _ContextInfo._onRateLimitCallbacks = [];
311
318
  // Method to set the page context information from an SPFX project
312
319
  _ContextInfo.setPageContext = (spfxPageContext) => {
313
320
  // Set the page context information
@@ -315,6 +322,17 @@ _ContextInfo.setPageContext = (spfxPageContext) => {
315
322
  // Enable the refresh token
316
323
  _a.enableRefreshToken();
317
324
  };
325
+ // Method to set the rate limit value
326
+ _ContextInfo.setRateLimit = (rateLimit) => {
327
+ // Ensure a value exists
328
+ if (rateLimit) {
329
+ // Set the rate limit information
330
+ ContextInfo.rateLimit = rateLimit;
331
+ ContextInfo.rateLimit.requestTime = Date.now();
332
+ // Call the events
333
+ _a._onRateLimitCallbacks.forEach(callback => { callback(rateLimit); });
334
+ }
335
+ };
318
336
  _ContextInfo._worker = null;
319
337
  _ContextInfo._onRefresh = [];
320
338
  // Value in minutes to refresh the token
package/build/rest.js CHANGED
@@ -6,7 +6,7 @@ import { GraphTypes, SPTypes } from "./sptypes";
6
6
  * SharePoint REST Library
7
7
  */
8
8
  export const $REST = {
9
- __ver: 9.78,
9
+ __ver: 9.79,
10
10
  AppContext: (siteUrl) => { return Lib.Site.getAppContext(siteUrl); },
11
11
  Apps: Lib.Apps,
12
12
  ContextInfo: Lib.ContextInfo,
@@ -347,10 +347,16 @@ export const Request = {
347
347
  else {
348
348
  // Create the request
349
349
  base.xhr = new XHRRequest(asyncFl, targetInfo, () => {
350
- // Update the response and status
350
+ // Update the base properties
351
+ base.rateLimit = base.xhr.rateLimit;
351
352
  base.response = base.xhr.response;
352
353
  base.status = base.xhr.status;
353
354
  let errorFl = !(base.status >= 200 && base.status < 300);
355
+ // See if a rate limit exists
356
+ if (base.rateLimit) {
357
+ // Set the context information
358
+ ContextInfo.setRateLimit(base.rateLimit);
359
+ }
354
360
  // See if we are returning a file buffer
355
361
  if (base.requestType == RequestType.GetBuffer) {
356
362
  // Execute the callback
@@ -395,9 +401,15 @@ export const Request = {
395
401
  else {
396
402
  // Create the request
397
403
  base.xhr = new XHRRequest(asyncFl, targetInfo);
398
- // Update the response and status
404
+ // Update the base properties
405
+ base.rateLimit = base.xhr.rateLimit;
399
406
  base.response = base.xhr.response;
400
407
  base.status = base.xhr.status;
408
+ // See if a rate limit exists
409
+ if (base.rateLimit) {
410
+ // Set the context information
411
+ ContextInfo.setRateLimit(base.rateLimit);
412
+ }
401
413
  // See if we are returning a file buffer
402
414
  if (base.requestType == RequestType.GetBuffer) {
403
415
  // Return the response
@@ -2838,7 +2838,7 @@ declare module 'gd-sprest/lib/apps' {
2838
2838
  }
2839
2839
 
2840
2840
  declare module 'gd-sprest/lib/contextInfo' {
2841
- import { IBaseExecution } from "gd-sprest-def/lib/base";
2841
+ import { IBaseExecution, IRateLimit } from "gd-sprest-def/lib/base";
2842
2842
  import { BasePermissions, ContextWebInformation } from "gd-sprest-def/lib/SP/complextypes";
2843
2843
 
2844
2844
  /**
@@ -3121,6 +3121,9 @@ declare module 'gd-sprest/lib/contextInfo' {
3121
3121
  /** Publishing Feature On */
3122
3122
  PublishingFeatureOn: boolean;
3123
3123
 
3124
+ /** The last rate limit information for a request. */
3125
+ rateLimit?: IRateLimit & { requestTime: number; }
3126
+
3124
3127
  /** Recycle Bin Item Count */
3125
3128
  RecycleBinItemCount: number;
3126
3129
 
@@ -3298,6 +3301,11 @@ declare module 'gd-sprest/lib/contextInfo' {
3298
3301
  };
3299
3302
 
3300
3303
 
3304
+ /**
3305
+ * Clears the callback events for the rate limit.
3306
+ */
3307
+ clearRateLimitCallbacks();
3308
+
3301
3309
  /**
3302
3310
  * Runs a loop to ensure the digest value doesn't expire.
3303
3311
  */
@@ -3317,6 +3325,12 @@ declare module 'gd-sprest/lib/contextInfo' {
3317
3325
  */
3318
3326
  getWeb(url: string): IBaseExecution<{ GetContextWebInformation: ContextWebInformation }>;
3319
3327
 
3328
+ /**
3329
+ * Event triggered when the rate limit information is set.
3330
+ * @param callback The method to execute when the rate limit value is set.
3331
+ */
3332
+ onRateLimitDetected(callback: (rateLimit: IRateLimit) => void);
3333
+
3320
3334
  /**
3321
3335
  * Value in minutes, to refresh the token prior to it expiring
3322
3336
  */
@@ -3327,6 +3341,12 @@ declare module 'gd-sprest/lib/contextInfo' {
3327
3341
  * @param spfxPageContext - The page context information variable from a SPFx project.
3328
3342
  */
3329
3343
  setPageContext(spfxPageContext: any);
3344
+
3345
+ /**
3346
+ * Sets the rate limit information from the last request containing it.
3347
+ * @param rateLimit The rate limit information from the request.
3348
+ */
3349
+ setRateLimit(rateLimit: IRateLimit);
3330
3350
  }
3331
3351
 
3332
3352
  export interface IThemeState {
@@ -7722,6 +7742,7 @@ declare module 'gd-sprest/utils/targetInfo' {
7722
7742
  }
7723
7743
 
7724
7744
  declare module 'gd-sprest/utils/xhrRequest' {
7745
+ import { IRateLimit } from "gd-sprest-def/base";
7725
7746
  import { ITargetInfo } from "gd-sprest/utils/targetInfo";
7726
7747
 
7727
7748
  /**
@@ -7742,6 +7763,9 @@ declare module 'gd-sprest/utils/xhrRequest' {
7742
7763
  // Flag indicating if this is a graph request
7743
7764
  isGraph: boolean;
7744
7765
 
7766
+ // The rate limit information
7767
+ rateLimit?: IRateLimit;
7768
+
7745
7769
  // The response
7746
7770
  response: string;
7747
7771