@pnp/sp 2.10.0 → 2.11.0

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 (294) hide show
  1. package/LICENSE +25 -25
  2. package/appcatalog/index.d.ts +8 -8
  3. package/appcatalog/index.js +30 -30
  4. package/appcatalog/types.d.ts +81 -81
  5. package/appcatalog/types.js +177 -177
  6. package/appcatalog/web.d.ts +16 -16
  7. package/appcatalog/web.js +6 -6
  8. package/attachments/index.d.ts +2 -2
  9. package/attachments/index.js +2 -2
  10. package/attachments/item.d.ts +12 -12
  11. package/attachments/item.js +4 -4
  12. package/attachments/types.d.ts +92 -92
  13. package/attachments/types.js +240 -240
  14. package/batch.d.ts +17 -17
  15. package/batch.js +223 -223
  16. package/clientside-pages/funcs.d.ts +22 -22
  17. package/clientside-pages/funcs.js +25 -25
  18. package/clientside-pages/index.d.ts +2 -2
  19. package/clientside-pages/index.js +2 -2
  20. package/clientside-pages/types.d.ts +496 -496
  21. package/clientside-pages/types.js +1496 -1496
  22. package/clientside-pages/web.d.ts +41 -41
  23. package/clientside-pages/web.js +57 -57
  24. package/column-defaults/folder.d.ts +27 -27
  25. package/column-defaults/folder.js +82 -82
  26. package/column-defaults/index.d.ts +3 -3
  27. package/column-defaults/index.js +2 -2
  28. package/column-defaults/list.d.ts +19 -19
  29. package/column-defaults/list.js +198 -198
  30. package/column-defaults/types.d.ts +21 -21
  31. package/column-defaults/types.js +1 -1
  32. package/comments/clientside-page.d.ts +57 -57
  33. package/comments/clientside-page.d.ts.map +1 -1
  34. package/comments/clientside-page.js +136 -136
  35. package/comments/index.d.ts +2 -2
  36. package/comments/index.js +2 -2
  37. package/comments/item.d.ts +29 -29
  38. package/comments/item.js +47 -47
  39. package/comments/types.d.ts +107 -107
  40. package/comments/types.d.ts.map +1 -1
  41. package/comments/types.js +145 -145
  42. package/comments/types.js.map +1 -1
  43. package/content-types/index.d.ts +4 -4
  44. package/content-types/index.js +4 -4
  45. package/content-types/item.d.ts +12 -12
  46. package/content-types/item.js +4 -4
  47. package/content-types/list.d.ts +12 -12
  48. package/content-types/list.js +4 -4
  49. package/content-types/types.d.ts +107 -107
  50. package/content-types/types.js +166 -166
  51. package/content-types/web.d.ts +12 -12
  52. package/content-types/web.js +4 -4
  53. package/decorators.d.ts +11 -11
  54. package/decorators.js +28 -28
  55. package/features/index.d.ts +3 -3
  56. package/features/index.js +3 -3
  57. package/features/site.d.ts +12 -12
  58. package/features/site.js +4 -4
  59. package/features/types.d.ts +47 -47
  60. package/features/types.js +109 -109
  61. package/features/web.d.ts +12 -12
  62. package/features/web.js +4 -4
  63. package/fields/index.d.ts +4 -4
  64. package/fields/index.js +4 -4
  65. package/fields/list.d.ts +12 -12
  66. package/fields/list.js +4 -4
  67. package/fields/types.d.ts +368 -368
  68. package/fields/types.js +624 -624
  69. package/fields/web.d.ts +17 -17
  70. package/fields/web.js +5 -5
  71. package/files/folder.d.ts +12 -12
  72. package/files/folder.js +4 -4
  73. package/files/index.d.ts +4 -4
  74. package/files/index.js +4 -4
  75. package/files/item.d.ts +12 -12
  76. package/files/item.js +4 -4
  77. package/files/types.d.ts +421 -421
  78. package/files/types.js +853 -853
  79. package/files/web.d.ts +35 -35
  80. package/files/web.js +15 -15
  81. package/folders/index.d.ts +4 -4
  82. package/folders/index.js +4 -4
  83. package/folders/item.d.ts +9 -9
  84. package/folders/item.js +4 -4
  85. package/folders/list.d.ts +12 -12
  86. package/folders/list.js +4 -4
  87. package/folders/types.d.ts +207 -207
  88. package/folders/types.js +433 -433
  89. package/folders/web.d.ts +39 -39
  90. package/folders/web.js +15 -15
  91. package/forms/index.d.ts +2 -2
  92. package/forms/index.js +2 -2
  93. package/forms/list.d.ts +9 -9
  94. package/forms/list.js +4 -4
  95. package/forms/types.d.ts +35 -35
  96. package/forms/types.js +41 -41
  97. package/hubsites/index.d.ts +12 -12
  98. package/hubsites/index.js +15 -15
  99. package/hubsites/site.d.ts +26 -26
  100. package/hubsites/site.js +39 -39
  101. package/hubsites/types.d.ts +55 -55
  102. package/hubsites/types.js +53 -53
  103. package/hubsites/web.d.ts +21 -21
  104. package/hubsites/web.js +23 -23
  105. package/index.d.ts +14 -14
  106. package/index.js +13 -13
  107. package/items/index.d.ts +2 -2
  108. package/items/index.js +2 -2
  109. package/items/list.d.ts +9 -9
  110. package/items/list.js +4 -4
  111. package/items/types.d.ts +226 -226
  112. package/items/types.js +549 -549
  113. package/lists/index.d.ts +2 -2
  114. package/lists/index.js +2 -2
  115. package/lists/types.d.ts +495 -495
  116. package/lists/types.js +522 -522
  117. package/lists/web.d.ts +43 -43
  118. package/lists/web.js +27 -27
  119. package/navigation/index.d.ts +8 -8
  120. package/navigation/index.js +14 -14
  121. package/navigation/types.d.ts +154 -154
  122. package/navigation/types.js +219 -219
  123. package/navigation/web.d.ts +13 -13
  124. package/navigation/web.js +4 -4
  125. package/odata.d.ts +5 -5
  126. package/odata.js +90 -90
  127. package/operations.d.ts +9 -9
  128. package/operations.js +63 -63
  129. package/package.json +4 -4
  130. package/presets/all.d.ts +72 -72
  131. package/presets/all.js +72 -72
  132. package/presets/core.d.ts +11 -11
  133. package/presets/core.js +11 -11
  134. package/profiles/index.d.ts +7 -7
  135. package/profiles/index.js +13 -13
  136. package/profiles/types.d.ts +357 -357
  137. package/profiles/types.js +454 -454
  138. package/readme.md +21 -21
  139. package/regional-settings/content-type.d.ts +7 -7
  140. package/regional-settings/content-type.js +4 -4
  141. package/regional-settings/field.d.ts +7 -7
  142. package/regional-settings/field.js +4 -4
  143. package/regional-settings/funcs.d.ts +2 -2
  144. package/regional-settings/funcs.js +8 -8
  145. package/regional-settings/index.d.ts +6 -6
  146. package/regional-settings/index.js +6 -6
  147. package/regional-settings/list.d.ts +7 -7
  148. package/regional-settings/list.js +4 -4
  149. package/regional-settings/types.d.ts +111 -111
  150. package/regional-settings/types.js +159 -159
  151. package/regional-settings/user-custom-actions.d.ts +7 -7
  152. package/regional-settings/user-custom-actions.js +4 -4
  153. package/regional-settings/web.d.ts +12 -12
  154. package/regional-settings/web.js +7 -7
  155. package/related-items/index.d.ts +1 -1
  156. package/related-items/index.js +1 -1
  157. package/related-items/types.d.ts +76 -76
  158. package/related-items/types.js +103 -103
  159. package/related-items/web.d.ts +12 -12
  160. package/related-items/web.js +9 -9
  161. package/rest.d.ts +44 -44
  162. package/rest.js +72 -72
  163. package/search/index.d.ts +30 -30
  164. package/search/index.js +25 -25
  165. package/search/query.d.ts +62 -62
  166. package/search/query.js +302 -302
  167. package/search/suggest.d.ts +76 -76
  168. package/search/suggest.js +66 -66
  169. package/search/types.d.ts +426 -426
  170. package/search/types.js +57 -57
  171. package/security/funcs.d.ts +43 -43
  172. package/security/funcs.js +142 -142
  173. package/security/index.d.ts +4 -4
  174. package/security/index.js +4 -4
  175. package/security/item.d.ts +7 -7
  176. package/security/item.js +14 -14
  177. package/security/list.d.ts +7 -7
  178. package/security/list.js +14 -14
  179. package/security/types.d.ts +318 -318
  180. package/security/types.js +399 -399
  181. package/security/web.d.ts +9 -9
  182. package/security/web.js +15 -15
  183. package/sharepointqueryable.d.ts +135 -135
  184. package/sharepointqueryable.js +265 -265
  185. package/sharing/file.d.ts +18 -18
  186. package/sharing/file.js +116 -116
  187. package/sharing/folder.d.ts +9 -9
  188. package/sharing/folder.js +136 -136
  189. package/sharing/funcs.d.ts +62 -62
  190. package/sharing/funcs.js +239 -239
  191. package/sharing/index.d.ts +5 -5
  192. package/sharing/index.js +5 -5
  193. package/sharing/item.d.ts +16 -16
  194. package/sharing/item.js +15 -15
  195. package/sharing/types.d.ts +583 -583
  196. package/sharing/types.js +113 -113
  197. package/sharing/web.d.ts +19 -19
  198. package/sharing/web.js +76 -76
  199. package/site-designs/index.d.ts +8 -8
  200. package/site-designs/index.js +14 -14
  201. package/site-designs/types.d.ts +319 -319
  202. package/site-designs/types.js +203 -203
  203. package/site-designs/web.d.ts +25 -25
  204. package/site-designs/web.js +11 -11
  205. package/site-groups/index.d.ts +2 -2
  206. package/site-groups/index.js +2 -2
  207. package/site-groups/types.d.ts +89 -89
  208. package/site-groups/types.js +125 -125
  209. package/site-groups/web.d.ts +40 -40
  210. package/site-groups/web.js +30 -30
  211. package/site-scripts/index.d.ts +9 -9
  212. package/site-scripts/index.js +15 -15
  213. package/site-scripts/list.d.ts +12 -12
  214. package/site-scripts/list.js +24 -24
  215. package/site-scripts/types.d.ts +183 -183
  216. package/site-scripts/types.js +141 -141
  217. package/site-scripts/web.d.ts +13 -13
  218. package/site-scripts/web.js +5 -5
  219. package/site-users/index.d.ts +2 -2
  220. package/site-users/index.js +2 -2
  221. package/site-users/types.d.ts +138 -138
  222. package/site-users/types.js +122 -122
  223. package/site-users/web.d.ts +31 -31
  224. package/site-users/web.js +27 -27
  225. package/sites/index.d.ts +7 -7
  226. package/sites/index.js +13 -13
  227. package/sites/types.d.ts +147 -147
  228. package/sites/types.js +321 -321
  229. package/social/index.d.ts +10 -10
  230. package/social/index.js +13 -13
  231. package/social/types.d.ts +309 -309
  232. package/social/types.js +322 -322
  233. package/sphttpclient.d.ts +18 -18
  234. package/sphttpclient.js +189 -189
  235. package/splibconfig.d.ts +22 -22
  236. package/splibconfig.js +13 -13
  237. package/sputilities/index.d.ts +7 -7
  238. package/sputilities/index.js +13 -13
  239. package/sputilities/types.d.ts +130 -130
  240. package/sputilities/types.js +118 -118
  241. package/subscriptions/index.d.ts +2 -2
  242. package/subscriptions/index.js +2 -2
  243. package/subscriptions/list.d.ts +13 -13
  244. package/subscriptions/list.js +4 -4
  245. package/subscriptions/types.d.ts +54 -54
  246. package/subscriptions/types.js +111 -111
  247. package/taxonomy/index.d.ts +7 -7
  248. package/taxonomy/index.js +13 -13
  249. package/taxonomy/types.d.ts +200 -200
  250. package/taxonomy/types.js +347 -347
  251. package/telemetry.d.ts +12 -12
  252. package/telemetry.js +48 -48
  253. package/types.d.ts +218 -218
  254. package/types.js +79 -79
  255. package/user-custom-actions/index.d.ts +4 -4
  256. package/user-custom-actions/index.js +4 -4
  257. package/user-custom-actions/list.d.ts +12 -12
  258. package/user-custom-actions/list.js +4 -4
  259. package/user-custom-actions/site.d.ts +12 -12
  260. package/user-custom-actions/site.js +4 -4
  261. package/user-custom-actions/types.d.ts +82 -82
  262. package/user-custom-actions/types.js +93 -93
  263. package/user-custom-actions/web.d.ts +15 -15
  264. package/user-custom-actions/web.js +4 -4
  265. package/utils/escapeQueryStrValue.d.ts +1 -1
  266. package/utils/escapeQueryStrValue.js +19 -19
  267. package/utils/extractweburl.d.ts +1 -1
  268. package/utils/extractweburl.js +15 -15
  269. package/utils/file-names.d.ts +17 -17
  270. package/utils/file-names.js +38 -38
  271. package/utils/metadata.d.ts +5 -5
  272. package/utils/metadata.js +5 -5
  273. package/utils/objectToSPKeyValueCollection.d.ts +20 -20
  274. package/utils/objectToSPKeyValueCollection.js +16 -16
  275. package/utils/toResourcePath.d.ts +7 -7
  276. package/utils/toResourcePath.js +6 -6
  277. package/utils/toabsoluteurl.d.ts +7 -7
  278. package/utils/toabsoluteurl.js +61 -61
  279. package/views/index.d.ts +2 -2
  280. package/views/index.js +2 -2
  281. package/views/list.d.ts +23 -23
  282. package/views/list.js +8 -8
  283. package/views/types.d.ts +140 -140
  284. package/views/types.js +184 -184
  285. package/webparts/file.d.ts +15 -15
  286. package/webparts/file.js +6 -6
  287. package/webparts/index.d.ts +2 -2
  288. package/webparts/index.js +2 -2
  289. package/webparts/types.d.ts +83 -83
  290. package/webparts/types.js +117 -117
  291. package/webs/index.d.ts +16 -16
  292. package/webs/index.js +16 -16
  293. package/webs/types.d.ts +210 -210
  294. package/webs/types.js +295 -295
package/sphttpclient.d.ts CHANGED
@@ -1,19 +1,19 @@
1
- import { IFetchOptions, IRequestClient, IHttpClientImpl, Runtime } from "@pnp/common";
2
- export declare class SPHttpClient implements IRequestClient {
3
- protected _runtime: Runtime;
4
- protected _impl: IHttpClientImpl;
5
- protected _digestCache: IGetDigest;
6
- constructor(runtime?: Runtime);
7
- constructor(runtime?: Runtime, impl?: IHttpClientImpl);
8
- fetch(url: string, options?: IFetchOptions): Promise<Response>;
9
- fetchRaw(url: string, options?: IFetchOptions): Promise<Response>;
10
- get(url: string, options?: IFetchOptions): Promise<Response>;
11
- post(url: string, options?: IFetchOptions): Promise<Response>;
12
- patch(url: string, options?: IFetchOptions): Promise<Response>;
13
- delete(url: string, options?: IFetchOptions): Promise<Response>;
14
- }
15
- interface IGetDigest {
16
- (webUrl: string): Promise<string>;
17
- }
18
- export {};
1
+ import { IFetchOptions, IRequestClient, IHttpClientImpl, Runtime } from "@pnp/common";
2
+ export declare class SPHttpClient implements IRequestClient {
3
+ protected _runtime: Runtime;
4
+ protected _impl: IHttpClientImpl;
5
+ protected _digestCache: IGetDigest;
6
+ constructor(runtime?: Runtime);
7
+ constructor(runtime?: Runtime, impl?: IHttpClientImpl);
8
+ fetch(url: string, options?: IFetchOptions): Promise<Response>;
9
+ fetchRaw(url: string, options?: IFetchOptions): Promise<Response>;
10
+ get(url: string, options?: IFetchOptions): Promise<Response>;
11
+ post(url: string, options?: IFetchOptions): Promise<Response>;
12
+ patch(url: string, options?: IFetchOptions): Promise<Response>;
13
+ delete(url: string, options?: IFetchOptions): Promise<Response>;
14
+ }
15
+ interface IGetDigest {
16
+ (webUrl: string): Promise<string>;
17
+ }
18
+ export {};
19
19
  //# sourceMappingURL=sphttpclient.d.ts.map
package/sphttpclient.js CHANGED
@@ -1,190 +1,190 @@
1
- import { __awaiter, __generator } from "tslib";
2
- import { assign, mergeHeaders, getCtxCallback, combine, dateAdd, DefaultRuntime, Runtime, objectDefinedNotNull, } from "@pnp/common";
3
- import { extractWebUrl } from "./utils/extractweburl.js";
4
- import { tag } from "./telemetry.js";
5
- import { ODataParser, HttpRequestError } from "@pnp/odata";
6
- var SPHttpClient = /** @class */ (function () {
7
- function SPHttpClient() {
8
- // constructor(...args: [runtime: Runtime] | [impl: IHttpClientImpl, runtime?: Runtime]) {
9
- var args = [];
10
- for (var _i = 0; _i < arguments.length; _i++) {
11
- args[_i] = arguments[_i];
12
- }
13
- var _a;
14
- this._runtime = args.length > 0 && args[0] instanceof Runtime ? args[0] : DefaultRuntime;
15
- this._impl = args.length > 1 && objectDefinedNotNull(args[1]) ?
16
- args[1] : ((_a = this._runtime.get("sp")) === null || _a === void 0 ? void 0 : _a.fetchClientFactory()) || null;
17
- if (this._impl === null) {
18
- throw Error("Could not generate fetchClientFactory in SPHttpClient.");
19
- }
20
- this._digestCache = getDigestFactory(this);
21
- }
22
- SPHttpClient.prototype.fetch = function (url, options) {
23
- var _a;
24
- if (options === void 0) { options = {}; }
25
- return __awaiter(this, void 0, void 0, function () {
26
- var opts, headers, methodName, clientTag, digest;
27
- return __generator(this, function (_b) {
28
- switch (_b.label) {
29
- case 0:
30
- opts = assign(options, { cache: "no-cache", credentials: "same-origin" }, true);
31
- headers = new Headers();
32
- // first we add the global headers so they can be overwritten by any passed in locally to this call
33
- mergeHeaders(headers, (_a = this._runtime.get("sp")) === null || _a === void 0 ? void 0 : _a.headers);
34
- // second we add the local options so we can overwrite the globals
35
- mergeHeaders(headers, options.headers);
36
- // lastly we apply any default headers we need that may not exist
37
- if (!headers.has("Accept")) {
38
- headers.append("Accept", "application/json");
39
- }
40
- if (!headers.has("Content-Type")) {
41
- headers.append("Content-Type", "application/json;odata=verbose;charset=utf-8");
42
- }
43
- if (!headers.has("X-ClientService-ClientTag")) {
44
- methodName = tag.getClientTag(headers);
45
- clientTag = "PnPCoreJS:2.10.0:" + methodName;
46
- if (clientTag.length > 32) {
47
- clientTag = clientTag.substr(0, 32);
48
- }
49
- headers.append("X-ClientService-ClientTag", clientTag);
50
- }
51
- opts = assign(opts, { headers: headers });
52
- if (!(opts.method && opts.method.toUpperCase() !== "GET" && !headers.has("X-RequestDigest") && !headers.has("Authorization"))) return [3 /*break*/, 2];
53
- return [4 /*yield*/, this._digestCache(extractWebUrl(url))];
54
- case 1:
55
- digest = _b.sent();
56
- headers.append("X-RequestDigest", digest);
57
- _b.label = 2;
58
- case 2: return [2 /*return*/, this.fetchRaw(url, opts)];
59
- }
60
- });
61
- });
62
- };
63
- SPHttpClient.prototype.fetchRaw = function (url, options) {
64
- var _this = this;
65
- if (options === void 0) { options = {}; }
66
- // here we need to normalize the headers
67
- var rawHeaders = new Headers();
68
- mergeHeaders(rawHeaders, options.headers);
69
- options = assign(options, { headers: rawHeaders });
70
- var retry = function (ctx) {
71
- // handles setting the proper timeout for a retry
72
- var setRetry = function (response) {
73
- var delay;
74
- if (response.headers.has("Retry-After")) {
75
- // if we have gotten a header, use that value as the delay value in seconds
76
- delay = parseInt(response.headers.get("Retry-After"), 10) * 1000;
77
- }
78
- else {
79
- // grab our current delay
80
- delay = ctx.delay;
81
- // Increment our counters.
82
- ctx.delay *= 2;
83
- }
84
- ctx.attempts++;
85
- // If we have exceeded the retry count, reject.
86
- if (ctx.retryCount <= ctx.attempts) {
87
- // eslint-disable-next-line max-len
88
- ctx.reject(new HttpRequestError("Retry count exceeded (" + ctx.retryCount + ") for request. Response status: [" + response.status + "] " + response.statusText, response));
89
- }
90
- else {
91
- // Set our retry timeout for {delay} milliseconds.
92
- setTimeout(getCtxCallback(_this, retry, ctx), delay);
93
- }
94
- };
95
- // send the actual request
96
- _this._impl.fetch(url, options).then(function (response) {
97
- if (response.status === 429) {
98
- // we have been throttled
99
- setRetry(response);
100
- }
101
- else {
102
- ctx.resolve(response);
103
- }
104
- }).catch(function (response) {
105
- if (response.status === 503 || response.status === 504) {
106
- // http status code 503 or 504, we can retry this
107
- setRetry(response);
108
- }
109
- else {
110
- ctx.reject(response);
111
- }
112
- });
113
- };
114
- return new Promise(function (resolve, reject) {
115
- retry.call(_this, {
116
- attempts: 0,
117
- delay: 100,
118
- reject: reject,
119
- resolve: resolve,
120
- retryCount: 7,
121
- });
122
- });
123
- };
124
- SPHttpClient.prototype.get = function (url, options) {
125
- if (options === void 0) { options = {}; }
126
- var opts = assign(options, { method: "GET" });
127
- return this.fetch(url, opts);
128
- };
129
- SPHttpClient.prototype.post = function (url, options) {
130
- if (options === void 0) { options = {}; }
131
- var opts = assign(options, { method: "POST" });
132
- return this.fetch(url, opts);
133
- };
134
- SPHttpClient.prototype.patch = function (url, options) {
135
- if (options === void 0) { options = {}; }
136
- var opts = assign(options, { method: "PATCH" });
137
- return this.fetch(url, opts);
138
- };
139
- SPHttpClient.prototype.delete = function (url, options) {
140
- if (options === void 0) { options = {}; }
141
- var opts = assign(options, { method: "DELETE" });
142
- return this.fetch(url, opts);
143
- };
144
- return SPHttpClient;
145
- }());
146
- export { SPHttpClient };
147
- // allows for the caching of digests across all HttpClient's which each have their own DigestCache wrapper.
148
- var digests = new Map();
149
- function getDigestFactory(client) {
150
- var _this = this;
151
- return function (webUrl) { return __awaiter(_this, void 0, void 0, function () {
152
- var cachedDigest, now, url, headers, resp, parsed, newCachedDigest;
153
- var _a, _b;
154
- return __generator(this, function (_c) {
155
- switch (_c.label) {
156
- case 0:
157
- cachedDigest = digests.get(webUrl);
158
- if (cachedDigest !== undefined) {
159
- now = new Date();
160
- if (now < cachedDigest.expiration) {
161
- return [2 /*return*/, cachedDigest.value];
162
- }
163
- }
164
- url = combine(webUrl, "/_api/contextinfo");
165
- headers = {
166
- "Accept": "application/json;odata=verbose",
167
- "Content-Type": "application/json;odata=verbose;charset=utf-8",
168
- };
169
- return [4 /*yield*/, client.fetchRaw(url, {
170
- cache: "no-cache",
171
- credentials: "same-origin",
172
- headers: assign(headers, (_b = (_a = client._runtime.get("sp")) === null || _a === void 0 ? void 0 : _a.sp) === null || _b === void 0 ? void 0 : _b.headers, true),
173
- method: "POST",
174
- })];
175
- case 1:
176
- resp = _c.sent();
177
- return [4 /*yield*/, (new ODataParser()).parse(resp).then(function (r) { return r.GetContextWebInformation; })];
178
- case 2:
179
- parsed = _c.sent();
180
- newCachedDigest = {
181
- expiration: dateAdd(new Date(), "second", parsed.FormDigestTimeoutSeconds),
182
- value: parsed.FormDigestValue,
183
- };
184
- digests.set(webUrl, newCachedDigest);
185
- return [2 /*return*/, newCachedDigest.value];
186
- }
187
- });
188
- }); };
189
- }
1
+ import { __awaiter, __generator } from "tslib";
2
+ import { assign, mergeHeaders, getCtxCallback, combine, dateAdd, DefaultRuntime, Runtime, objectDefinedNotNull, } from "@pnp/common";
3
+ import { extractWebUrl } from "./utils/extractweburl.js";
4
+ import { tag } from "./telemetry.js";
5
+ import { ODataParser, HttpRequestError } from "@pnp/odata";
6
+ var SPHttpClient = /** @class */ (function () {
7
+ function SPHttpClient() {
8
+ // constructor(...args: [runtime: Runtime] | [impl: IHttpClientImpl, runtime?: Runtime]) {
9
+ var args = [];
10
+ for (var _i = 0; _i < arguments.length; _i++) {
11
+ args[_i] = arguments[_i];
12
+ }
13
+ var _a;
14
+ this._runtime = args.length > 0 && args[0] instanceof Runtime ? args[0] : DefaultRuntime;
15
+ this._impl = args.length > 1 && objectDefinedNotNull(args[1]) ?
16
+ args[1] : ((_a = this._runtime.get("sp")) === null || _a === void 0 ? void 0 : _a.fetchClientFactory()) || null;
17
+ if (this._impl === null) {
18
+ throw Error("Could not generate fetchClientFactory in SPHttpClient.");
19
+ }
20
+ this._digestCache = getDigestFactory(this);
21
+ }
22
+ SPHttpClient.prototype.fetch = function (url, options) {
23
+ var _a;
24
+ if (options === void 0) { options = {}; }
25
+ return __awaiter(this, void 0, void 0, function () {
26
+ var opts, headers, methodName, clientTag, digest;
27
+ return __generator(this, function (_b) {
28
+ switch (_b.label) {
29
+ case 0:
30
+ opts = assign(options, { cache: "no-cache", credentials: "same-origin" }, true);
31
+ headers = new Headers();
32
+ // first we add the global headers so they can be overwritten by any passed in locally to this call
33
+ mergeHeaders(headers, (_a = this._runtime.get("sp")) === null || _a === void 0 ? void 0 : _a.headers);
34
+ // second we add the local options so we can overwrite the globals
35
+ mergeHeaders(headers, options.headers);
36
+ // lastly we apply any default headers we need that may not exist
37
+ if (!headers.has("Accept")) {
38
+ headers.append("Accept", "application/json");
39
+ }
40
+ if (!headers.has("Content-Type")) {
41
+ headers.append("Content-Type", "application/json;odata=verbose;charset=utf-8");
42
+ }
43
+ if (!headers.has("X-ClientService-ClientTag")) {
44
+ methodName = tag.getClientTag(headers);
45
+ clientTag = "PnPCoreJS:2.11.0:" + methodName;
46
+ if (clientTag.length > 32) {
47
+ clientTag = clientTag.substr(0, 32);
48
+ }
49
+ headers.append("X-ClientService-ClientTag", clientTag);
50
+ }
51
+ opts = assign(opts, { headers: headers });
52
+ if (!(opts.method && opts.method.toUpperCase() !== "GET" && !headers.has("X-RequestDigest") && !headers.has("Authorization"))) return [3 /*break*/, 2];
53
+ return [4 /*yield*/, this._digestCache(extractWebUrl(url))];
54
+ case 1:
55
+ digest = _b.sent();
56
+ headers.append("X-RequestDigest", digest);
57
+ _b.label = 2;
58
+ case 2: return [2 /*return*/, this.fetchRaw(url, opts)];
59
+ }
60
+ });
61
+ });
62
+ };
63
+ SPHttpClient.prototype.fetchRaw = function (url, options) {
64
+ var _this = this;
65
+ if (options === void 0) { options = {}; }
66
+ // here we need to normalize the headers
67
+ var rawHeaders = new Headers();
68
+ mergeHeaders(rawHeaders, options.headers);
69
+ options = assign(options, { headers: rawHeaders });
70
+ var retry = function (ctx) {
71
+ // handles setting the proper timeout for a retry
72
+ var setRetry = function (response) {
73
+ var delay;
74
+ if (response.headers.has("Retry-After")) {
75
+ // if we have gotten a header, use that value as the delay value in seconds
76
+ delay = parseInt(response.headers.get("Retry-After"), 10) * 1000;
77
+ }
78
+ else {
79
+ // grab our current delay
80
+ delay = ctx.delay;
81
+ // Increment our counters.
82
+ ctx.delay *= 2;
83
+ }
84
+ ctx.attempts++;
85
+ // If we have exceeded the retry count, reject.
86
+ if (ctx.retryCount <= ctx.attempts) {
87
+ // eslint-disable-next-line max-len
88
+ ctx.reject(new HttpRequestError("Retry count exceeded (" + ctx.retryCount + ") for request. Response status: [" + response.status + "] " + response.statusText, response));
89
+ }
90
+ else {
91
+ // Set our retry timeout for {delay} milliseconds.
92
+ setTimeout(getCtxCallback(_this, retry, ctx), delay);
93
+ }
94
+ };
95
+ // send the actual request
96
+ _this._impl.fetch(url, options).then(function (response) {
97
+ if (response.status === 429) {
98
+ // we have been throttled
99
+ setRetry(response);
100
+ }
101
+ else {
102
+ ctx.resolve(response);
103
+ }
104
+ }).catch(function (response) {
105
+ if (response.status === 503 || response.status === 504) {
106
+ // http status code 503 or 504, we can retry this
107
+ setRetry(response);
108
+ }
109
+ else {
110
+ ctx.reject(response);
111
+ }
112
+ });
113
+ };
114
+ return new Promise(function (resolve, reject) {
115
+ retry.call(_this, {
116
+ attempts: 0,
117
+ delay: 100,
118
+ reject: reject,
119
+ resolve: resolve,
120
+ retryCount: 7,
121
+ });
122
+ });
123
+ };
124
+ SPHttpClient.prototype.get = function (url, options) {
125
+ if (options === void 0) { options = {}; }
126
+ var opts = assign(options, { method: "GET" });
127
+ return this.fetch(url, opts);
128
+ };
129
+ SPHttpClient.prototype.post = function (url, options) {
130
+ if (options === void 0) { options = {}; }
131
+ var opts = assign(options, { method: "POST" });
132
+ return this.fetch(url, opts);
133
+ };
134
+ SPHttpClient.prototype.patch = function (url, options) {
135
+ if (options === void 0) { options = {}; }
136
+ var opts = assign(options, { method: "PATCH" });
137
+ return this.fetch(url, opts);
138
+ };
139
+ SPHttpClient.prototype.delete = function (url, options) {
140
+ if (options === void 0) { options = {}; }
141
+ var opts = assign(options, { method: "DELETE" });
142
+ return this.fetch(url, opts);
143
+ };
144
+ return SPHttpClient;
145
+ }());
146
+ export { SPHttpClient };
147
+ // allows for the caching of digests across all HttpClient's which each have their own DigestCache wrapper.
148
+ var digests = new Map();
149
+ function getDigestFactory(client) {
150
+ var _this = this;
151
+ return function (webUrl) { return __awaiter(_this, void 0, void 0, function () {
152
+ var cachedDigest, now, url, headers, resp, parsed, newCachedDigest;
153
+ var _a, _b;
154
+ return __generator(this, function (_c) {
155
+ switch (_c.label) {
156
+ case 0:
157
+ cachedDigest = digests.get(webUrl);
158
+ if (cachedDigest !== undefined) {
159
+ now = new Date();
160
+ if (now < cachedDigest.expiration) {
161
+ return [2 /*return*/, cachedDigest.value];
162
+ }
163
+ }
164
+ url = combine(webUrl, "/_api/contextinfo");
165
+ headers = {
166
+ "Accept": "application/json;odata=verbose",
167
+ "Content-Type": "application/json;odata=verbose;charset=utf-8",
168
+ };
169
+ return [4 /*yield*/, client.fetchRaw(url, {
170
+ cache: "no-cache",
171
+ credentials: "same-origin",
172
+ headers: assign(headers, (_b = (_a = client._runtime.get("sp")) === null || _a === void 0 ? void 0 : _a.sp) === null || _b === void 0 ? void 0 : _b.headers, true),
173
+ method: "POST",
174
+ })];
175
+ case 1:
176
+ resp = _c.sent();
177
+ return [4 /*yield*/, (new ODataParser()).parse(resp).then(function (r) { return r.GetContextWebInformation; })];
178
+ case 2:
179
+ parsed = _c.sent();
180
+ newCachedDigest = {
181
+ expiration: dateAdd(new Date(), "second", parsed.FormDigestTimeoutSeconds),
182
+ value: parsed.FormDigestValue,
183
+ };
184
+ digests.set(webUrl, newCachedDigest);
185
+ return [2 /*return*/, newCachedDigest.value];
186
+ }
187
+ });
188
+ }); };
189
+ }
190
190
  //# sourceMappingURL=sphttpclient.js.map
package/splibconfig.d.ts CHANGED
@@ -1,23 +1,23 @@
1
- import { ILibraryConfiguration, ITypedHash, IHttpClientImpl, Runtime } from "@pnp/common";
2
- export declare const emptyGuid = "00000000-0000-0000-0000-000000000000";
3
- export interface ISPConfigurationPart {
4
- sp?: ISPConfigurationProps;
5
- }
6
- export interface ISPConfigurationProps {
7
- /**
8
- * Any headers to apply to all requests
9
- */
10
- headers?: ITypedHash<string>;
11
- /**
12
- * The base url used for all requests
13
- */
14
- baseUrl?: string;
15
- /**
16
- * Defines a factory method used to create fetch clients
17
- */
18
- fetchClientFactory?: () => IHttpClientImpl;
19
- }
20
- export interface ISPConfiguration extends ILibraryConfiguration, ISPConfigurationPart {
21
- }
22
- export declare function setup(config: ISPConfiguration, runtime?: Runtime): void;
1
+ import { ILibraryConfiguration, ITypedHash, IHttpClientImpl, Runtime } from "@pnp/common";
2
+ export declare const emptyGuid = "00000000-0000-0000-0000-000000000000";
3
+ export interface ISPConfigurationPart {
4
+ sp?: ISPConfigurationProps;
5
+ }
6
+ export interface ISPConfigurationProps {
7
+ /**
8
+ * Any headers to apply to all requests
9
+ */
10
+ headers?: ITypedHash<string>;
11
+ /**
12
+ * The base url used for all requests
13
+ */
14
+ baseUrl?: string;
15
+ /**
16
+ * Defines a factory method used to create fetch clients
17
+ */
18
+ fetchClientFactory?: () => IHttpClientImpl;
19
+ }
20
+ export interface ISPConfiguration extends ILibraryConfiguration, ISPConfigurationPart {
21
+ }
22
+ export declare function setup(config: ISPConfiguration, runtime?: Runtime): void;
23
23
  //# sourceMappingURL=splibconfig.d.ts.map
package/splibconfig.js CHANGED
@@ -1,14 +1,14 @@
1
- import { FetchClient, DefaultRuntime, onRuntimeCreate, } from "@pnp/common";
2
- export var emptyGuid = "00000000-0000-0000-0000-000000000000";
3
- onRuntimeCreate(function (runtime) {
4
- var existing = runtime.get("sp");
5
- var spPart = Object.assign({}, {
6
- fetchClientFactory: function () { return new FetchClient(); },
7
- }, existing);
8
- runtime.assign({ sp: spPart });
9
- });
10
- export function setup(config, runtime) {
11
- if (runtime === void 0) { runtime = DefaultRuntime; }
12
- runtime.assign(config);
13
- }
1
+ import { FetchClient, DefaultRuntime, onRuntimeCreate, } from "@pnp/common";
2
+ export var emptyGuid = "00000000-0000-0000-0000-000000000000";
3
+ onRuntimeCreate(function (runtime) {
4
+ var existing = runtime.get("sp");
5
+ var spPart = Object.assign({}, {
6
+ fetchClientFactory: function () { return new FetchClient(); },
7
+ }, existing);
8
+ runtime.assign({ sp: spPart });
9
+ });
10
+ export function setup(config, runtime) {
11
+ if (runtime === void 0) { runtime = DefaultRuntime; }
12
+ runtime.assign(config);
13
+ }
14
14
  //# sourceMappingURL=splibconfig.js.map
@@ -1,8 +1,8 @@
1
- import { IUtilities } from "./types.js";
2
- export { ICreateWikiPageResult, IEmailProperties, IUtilities, IWikiPageCreationInfo, Utilities, } from "./types.js";
3
- declare module "../rest" {
4
- interface SPRest {
5
- readonly utility: IUtilities;
6
- }
7
- }
1
+ import { IUtilities } from "./types.js";
2
+ export { ICreateWikiPageResult, IEmailProperties, IUtilities, IWikiPageCreationInfo, Utilities, } from "./types.js";
3
+ declare module "../rest" {
4
+ interface SPRest {
5
+ readonly utility: IUtilities;
6
+ }
7
+ }
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1,14 +1,14 @@
1
- import { SPRest } from "../rest.js";
2
- import { Utilities } from "./types.js";
3
- export { Utilities, } from "./types.js";
4
- Reflect.defineProperty(SPRest.prototype, "utility", {
5
- configurable: true,
6
- enumerable: true,
7
- get: function () {
8
- return this.childConfigHook(function (_a) {
9
- var options = _a.options, baseUrl = _a.baseUrl, runtime = _a.runtime;
10
- return Utilities(baseUrl, "").configure(options).setRuntime(runtime);
11
- });
12
- },
13
- });
1
+ import { SPRest } from "../rest.js";
2
+ import { Utilities } from "./types.js";
3
+ export { Utilities, } from "./types.js";
4
+ Reflect.defineProperty(SPRest.prototype, "utility", {
5
+ configurable: true,
6
+ enumerable: true,
7
+ get: function () {
8
+ return this.childConfigHook(function (_a) {
9
+ var options = _a.options, baseUrl = _a.baseUrl, runtime = _a.runtime;
10
+ return Utilities(baseUrl, "").configure(options).setRuntime(runtime);
11
+ });
12
+ },
13
+ });
14
14
  //# sourceMappingURL=index.js.map