@pnp/graph 2.7.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 (165) hide show
  1. package/LICENSE +25 -25
  2. package/attachments/conversations.d.ts +9 -9
  3. package/attachments/conversations.js +4 -4
  4. package/attachments/index.d.ts +2 -2
  5. package/attachments/index.js +2 -2
  6. package/attachments/types.d.ts +26 -26
  7. package/attachments/types.js +46 -46
  8. package/batch.d.ts +17 -17
  9. package/batch.js +176 -176
  10. package/calendars/funcs.d.ts +36 -24
  11. package/calendars/funcs.d.ts.map +1 -1
  12. package/calendars/funcs.js +43 -29
  13. package/calendars/funcs.js.map +1 -1
  14. package/calendars/groups.d.ts +13 -13
  15. package/calendars/groups.js +5 -5
  16. package/calendars/index.d.ts +4 -4
  17. package/calendars/index.js +3 -3
  18. package/calendars/types.d.ts +52 -51
  19. package/calendars/types.d.ts.map +1 -1
  20. package/calendars/types.js +98 -96
  21. package/calendars/types.js.map +1 -1
  22. package/calendars/users.d.ts +22 -22
  23. package/calendars/users.js +9 -9
  24. package/cloud-communications/index.d.ts +8 -8
  25. package/cloud-communications/index.js +14 -14
  26. package/cloud-communications/types.d.ts +21 -21
  27. package/cloud-communications/types.js +46 -46
  28. package/cloud-communications/users.d.ts +9 -9
  29. package/cloud-communications/users.js +4 -4
  30. package/contacts/index.d.ts +2 -2
  31. package/contacts/index.js +2 -2
  32. package/contacts/types.d.ts +75 -75
  33. package/contacts/types.js +145 -145
  34. package/contacts/users.d.ts +11 -11
  35. package/contacts/users.js +5 -5
  36. package/conversations/groups.d.ts +13 -13
  37. package/conversations/groups.js +6 -6
  38. package/conversations/index.d.ts +2 -2
  39. package/conversations/index.js +2 -2
  40. package/conversations/types.d.ts +103 -103
  41. package/conversations/types.js +173 -173
  42. package/decorators.d.ts +103 -103
  43. package/decorators.js +138 -138
  44. package/directory-objects/index.d.ts +7 -7
  45. package/directory-objects/index.js +13 -13
  46. package/directory-objects/types.d.ts +67 -67
  47. package/directory-objects/types.js +96 -96
  48. package/graphhttpclient.d.ts +13 -13
  49. package/graphhttpclient.js +95 -95
  50. package/graphlibconfig.d.ts +21 -21
  51. package/graphlibconfig.js +19 -19
  52. package/graphqueryable.d.ts +156 -156
  53. package/graphqueryable.d.ts.map +1 -1
  54. package/graphqueryable.js +247 -237
  55. package/graphqueryable.js.map +1 -1
  56. package/groups/index.d.ts +7 -7
  57. package/groups/index.js +13 -13
  58. package/groups/types.d.ts +81 -81
  59. package/groups/types.d.ts.map +1 -1
  60. package/groups/types.js +137 -137
  61. package/groups/types.js.map +1 -1
  62. package/index.d.ts +8 -8
  63. package/index.js +7 -7
  64. package/insights/index.d.ts +2 -2
  65. package/insights/index.js +2 -2
  66. package/insights/types.d.ts +76 -76
  67. package/insights/types.js +162 -162
  68. package/insights/users.d.ts +9 -9
  69. package/insights/users.js +4 -4
  70. package/invitations/index.d.ts +7 -7
  71. package/invitations/index.js +13 -13
  72. package/invitations/types.d.ts +25 -25
  73. package/invitations/types.js +44 -44
  74. package/members/groups.d.ts +11 -11
  75. package/members/groups.js +5 -5
  76. package/members/index.d.ts +2 -2
  77. package/members/index.js +2 -2
  78. package/members/types.d.ts +31 -31
  79. package/members/types.js +49 -49
  80. package/messages/index.d.ts +2 -2
  81. package/messages/index.js +2 -2
  82. package/messages/types.d.ts +43 -43
  83. package/messages/types.d.ts.map +1 -1
  84. package/messages/types.js +77 -77
  85. package/messages/types.js.map +1 -1
  86. package/messages/users.d.ts +15 -15
  87. package/messages/users.js +10 -10
  88. package/onedrive/index.d.ts +2 -2
  89. package/onedrive/index.js +2 -2
  90. package/onedrive/types.d.ts +95 -87
  91. package/onedrive/types.d.ts.map +1 -1
  92. package/onedrive/types.js +241 -192
  93. package/onedrive/types.js.map +1 -1
  94. package/onedrive/users.d.ts +11 -11
  95. package/onedrive/users.js +5 -5
  96. package/onenote/index.d.ts +2 -2
  97. package/onenote/index.js +2 -2
  98. package/onenote/types.d.ts +76 -76
  99. package/onenote/types.js +149 -149
  100. package/onenote/users.d.ts +9 -9
  101. package/onenote/users.js +4 -4
  102. package/operations.d.ts +8 -8
  103. package/operations.js +41 -41
  104. package/outlook/index.d.ts +2 -2
  105. package/outlook/index.js +2 -2
  106. package/outlook/types.d.ts +40 -40
  107. package/outlook/types.js +76 -76
  108. package/outlook/users.d.ts +9 -9
  109. package/outlook/users.js +4 -4
  110. package/package.json +5 -5
  111. package/photos/groups.d.ts +9 -9
  112. package/photos/groups.js +4 -4
  113. package/photos/index.d.ts +3 -3
  114. package/photos/index.js +3 -3
  115. package/photos/types.d.ts +21 -21
  116. package/photos/types.js +37 -37
  117. package/photos/users.d.ts +9 -9
  118. package/photos/users.js +4 -4
  119. package/planner/groups.d.ts +9 -9
  120. package/planner/groups.js +4 -4
  121. package/planner/index.d.ts +9 -9
  122. package/planner/index.js +15 -15
  123. package/planner/types.d.ts +117 -117
  124. package/planner/types.js +291 -291
  125. package/planner/users.d.ts +9 -9
  126. package/planner/users.js +4 -4
  127. package/presets/all.d.ts +38 -38
  128. package/presets/all.js +38 -38
  129. package/readme.md +21 -21
  130. package/rest.d.ts +30 -30
  131. package/rest.js +57 -57
  132. package/search/index.d.ts +7 -7
  133. package/search/index.js +18 -18
  134. package/search/types.d.ts +16 -16
  135. package/search/types.js +23 -23
  136. package/sites/group.d.ts +9 -9
  137. package/sites/group.js +4 -4
  138. package/sites/index.d.ts +2 -2
  139. package/sites/index.js +2 -2
  140. package/sites/types.d.ts +23 -23
  141. package/sites/types.js +47 -47
  142. package/subscriptions/index.d.ts +7 -7
  143. package/subscriptions/index.js +13 -13
  144. package/subscriptions/types.d.ts +37 -37
  145. package/subscriptions/types.js +72 -72
  146. package/teams/index.d.ts +19 -19
  147. package/teams/index.js +35 -35
  148. package/teams/types.d.ts +112 -111
  149. package/teams/types.d.ts.map +1 -1
  150. package/teams/types.js +261 -254
  151. package/teams/types.js.map +1 -1
  152. package/teams/users.d.ts +9 -9
  153. package/teams/users.js +4 -4
  154. package/types.d.ts +9 -9
  155. package/types.js +19 -19
  156. package/users/index.d.ts +8 -8
  157. package/users/index.js +23 -23
  158. package/users/types.d.ts +35 -35
  159. package/users/types.d.ts.map +1 -1
  160. package/users/types.js +82 -82
  161. package/users/types.js.map +1 -1
  162. package/utils/toabsoluteurl.d.ts +7 -7
  163. package/utils/toabsoluteurl.js +48 -48
  164. package/utils/type.d.ts +3 -3
  165. package/utils/type.js +3 -3
package/LICENSE CHANGED
@@ -1,25 +1,25 @@
1
- SharePoint Patterns and Practices (PnP)
2
-
3
- The MIT License (MIT)
4
-
5
- Copyright (c) Microsoft Corporation
6
-
7
- All rights reserved.
8
-
9
- Permission is hereby granted, free of charge, to any person obtaining a copy
10
- of this software and associated documentation files (the "Software"), to deal
11
- in the Software without restriction, including without limitation the rights
12
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
- copies of the Software, and to permit persons to whom the Software is
14
- furnished to do so, subject to the following conditions:
15
-
16
- The above copyright notice and this permission notice shall be included in all
17
- copies or substantial portions of the Software.
18
-
19
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
- SOFTWARE.
1
+ SharePoint Patterns and Practices (PnP)
2
+
3
+ The MIT License (MIT)
4
+
5
+ Copyright (c) Microsoft Corporation
6
+
7
+ All rights reserved.
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
@@ -1,10 +1,10 @@
1
- import { IAttachments } from "./types.js";
2
- declare module "../conversations/types" {
3
- interface _Post {
4
- readonly attachments: IAttachments;
5
- }
6
- interface IPost {
7
- readonly attachments: IAttachments;
8
- }
9
- }
1
+ import { IAttachments } from "./types.js";
2
+ declare module "../conversations/types" {
3
+ interface _Post {
4
+ readonly attachments: IAttachments;
5
+ }
6
+ interface IPost {
7
+ readonly attachments: IAttachments;
8
+ }
9
+ }
10
10
  //# sourceMappingURL=conversations.d.ts.map
@@ -1,5 +1,5 @@
1
- import { _Post } from "../conversations/types.js";
2
- import { addProp } from "@pnp/odata";
3
- import { Attachments } from "./types.js";
4
- addProp(_Post, "attachments", Attachments);
1
+ import { _Post } from "../conversations/types.js";
2
+ import { addProp } from "@pnp/odata";
3
+ import { Attachments } from "./types.js";
4
+ addProp(_Post, "attachments", Attachments);
5
5
  //# sourceMappingURL=conversations.js.map
@@ -1,3 +1,3 @@
1
- import "./conversations.js";
2
- export { Attachment, Attachments, IAttachment, IAttachments, } from "./types.js";
1
+ import "./conversations.js";
2
+ export { Attachment, Attachments, IAttachment, IAttachments, } from "./types.js";
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1,3 +1,3 @@
1
- import "./conversations.js";
2
- export { Attachment, Attachments, } from "./types.js";
1
+ import "./conversations.js";
2
+ export { Attachment, Attachments, } from "./types.js";
3
3
  //# sourceMappingURL=index.js.map
@@ -1,27 +1,27 @@
1
- import { Attachment as IAttachmentType } from "@microsoft/microsoft-graph-types";
2
- import { _GraphQueryableCollection, _GraphQueryableInstance } from "../graphqueryable.js";
3
- import { IGetById } from "../decorators.js";
4
- /**
5
- * Attachment
6
- */
7
- export declare class _Attachment extends _GraphQueryableInstance<IAttachmentType> {
8
- }
9
- export interface IAttachment extends _Attachment {
10
- }
11
- export declare const Attachment: (baseUrl: string | import("../graphqueryable.js").IGraphQueryable<any>, path?: string) => IAttachment & import("@pnp/odata").IInvokable<any>;
12
- /**
13
- * Attachments
14
- */
15
- export declare class _Attachments extends _GraphQueryableCollection<IAttachmentType[]> {
16
- /**
17
- * Add attachment to this collection
18
- *
19
- * @param name Name given to the attachment file
20
- * @param bytes File content
21
- */
22
- addFile(name: string, bytes: string | Blob): Promise<IAttachmentType>;
23
- }
24
- export interface IAttachments extends _Attachments, IGetById<IAttachment> {
25
- }
26
- export declare const Attachments: (baseUrl: string | import("../graphqueryable.js").IGraphQueryable<any>, path?: string) => IAttachments & import("@pnp/odata").IInvokable<any>;
1
+ import { Attachment as IAttachmentType } from "@microsoft/microsoft-graph-types";
2
+ import { _GraphQueryableCollection, _GraphQueryableInstance } from "../graphqueryable.js";
3
+ import { IGetById } from "../decorators.js";
4
+ /**
5
+ * Attachment
6
+ */
7
+ export declare class _Attachment extends _GraphQueryableInstance<IAttachmentType> {
8
+ }
9
+ export interface IAttachment extends _Attachment {
10
+ }
11
+ export declare const Attachment: (baseUrl: string | import("../graphqueryable.js").IGraphQueryable<any>, path?: string) => IAttachment & import("@pnp/odata").IInvokable<any>;
12
+ /**
13
+ * Attachments
14
+ */
15
+ export declare class _Attachments extends _GraphQueryableCollection<IAttachmentType[]> {
16
+ /**
17
+ * Add attachment to this collection
18
+ *
19
+ * @param name Name given to the attachment file
20
+ * @param bytes File content
21
+ */
22
+ addFile(name: string, bytes: string | Blob): Promise<IAttachmentType>;
23
+ }
24
+ export interface IAttachments extends _Attachments, IGetById<IAttachment> {
25
+ }
26
+ export declare const Attachments: (baseUrl: string | import("../graphqueryable.js").IGraphQueryable<any>, path?: string) => IAttachments & import("@pnp/odata").IInvokable<any>;
27
27
  //# sourceMappingURL=types.d.ts.map
@@ -1,47 +1,47 @@
1
- import { __decorate, __extends } from "tslib";
2
- import { body } from "@pnp/odata";
3
- import { _GraphQueryableCollection, _GraphQueryableInstance, graphInvokableFactory } from "../graphqueryable.js";
4
- import { graphPost } from "../operations.js";
5
- import { defaultPath, getById } from "../decorators.js";
6
- import { type } from "../utils/type.js";
7
- /**
8
- * Attachment
9
- */
10
- var _Attachment = /** @class */ (function (_super) {
11
- __extends(_Attachment, _super);
12
- function _Attachment() {
13
- return _super !== null && _super.apply(this, arguments) || this;
14
- }
15
- return _Attachment;
16
- }(_GraphQueryableInstance));
17
- export { _Attachment };
18
- export var Attachment = graphInvokableFactory(_Attachment);
19
- /**
20
- * Attachments
21
- */
22
- var _Attachments = /** @class */ (function (_super) {
23
- __extends(_Attachments, _super);
24
- function _Attachments() {
25
- return _super !== null && _super.apply(this, arguments) || this;
26
- }
27
- /**
28
- * Add attachment to this collection
29
- *
30
- * @param name Name given to the attachment file
31
- * @param bytes File content
32
- */
33
- _Attachments.prototype.addFile = function (name, bytes) {
34
- return graphPost(this, body(type("#microsoft.graph.fileAttachment", {
35
- contentBytes: bytes,
36
- name: name,
37
- })));
38
- };
39
- _Attachments = __decorate([
40
- defaultPath("attachments"),
41
- getById(Attachment)
42
- ], _Attachments);
43
- return _Attachments;
44
- }(_GraphQueryableCollection));
45
- export { _Attachments };
46
- export var Attachments = graphInvokableFactory(_Attachments);
1
+ import { __decorate, __extends } from "tslib";
2
+ import { body } from "@pnp/odata";
3
+ import { _GraphQueryableCollection, _GraphQueryableInstance, graphInvokableFactory } from "../graphqueryable.js";
4
+ import { graphPost } from "../operations.js";
5
+ import { defaultPath, getById } from "../decorators.js";
6
+ import { type } from "../utils/type.js";
7
+ /**
8
+ * Attachment
9
+ */
10
+ var _Attachment = /** @class */ (function (_super) {
11
+ __extends(_Attachment, _super);
12
+ function _Attachment() {
13
+ return _super !== null && _super.apply(this, arguments) || this;
14
+ }
15
+ return _Attachment;
16
+ }(_GraphQueryableInstance));
17
+ export { _Attachment };
18
+ export var Attachment = graphInvokableFactory(_Attachment);
19
+ /**
20
+ * Attachments
21
+ */
22
+ var _Attachments = /** @class */ (function (_super) {
23
+ __extends(_Attachments, _super);
24
+ function _Attachments() {
25
+ return _super !== null && _super.apply(this, arguments) || this;
26
+ }
27
+ /**
28
+ * Add attachment to this collection
29
+ *
30
+ * @param name Name given to the attachment file
31
+ * @param bytes File content
32
+ */
33
+ _Attachments.prototype.addFile = function (name, bytes) {
34
+ return graphPost(this, body(type("#microsoft.graph.fileAttachment", {
35
+ contentBytes: bytes,
36
+ name: name,
37
+ })));
38
+ };
39
+ _Attachments = __decorate([
40
+ defaultPath("attachments"),
41
+ getById(Attachment)
42
+ ], _Attachments);
43
+ return _Attachments;
44
+ }(_GraphQueryableCollection));
45
+ export { _Attachments };
46
+ export var Attachments = graphInvokableFactory(_Attachments);
47
47
  //# sourceMappingURL=types.js.map
package/batch.d.ts CHANGED
@@ -1,18 +1,18 @@
1
- import { Batch } from "@pnp/odata";
2
- import { Runtime } from "@pnp/common";
3
- export declare class GraphBatch extends Batch {
4
- private batchUrl;
5
- private maxRequests;
6
- private runtime;
7
- constructor(batchUrl?: string, maxRequests?: number, runtime?: Runtime);
8
- setRuntime(runtime: Runtime): this;
9
- protected executeImpl(): Promise<void>;
10
- /**
11
- * Urls come to the batch absolute, but the processor expects relative
12
- * @param url Url to ensure is relative
13
- */
14
- private makeUrlRelative;
15
- private formatRequests;
16
- private parseResponse;
17
- }
1
+ import { Batch } from "@pnp/odata";
2
+ import { Runtime } from "@pnp/common";
3
+ export declare class GraphBatch extends Batch {
4
+ private batchUrl;
5
+ private maxRequests;
6
+ private runtime;
7
+ constructor(batchUrl?: string, maxRequests?: number, runtime?: Runtime);
8
+ setRuntime(runtime: Runtime): this;
9
+ protected executeImpl(): Promise<void>;
10
+ /**
11
+ * Urls come to the batch absolute, but the processor expects relative
12
+ * @param url Url to ensure is relative
13
+ */
14
+ private makeUrlRelative;
15
+ private formatRequests;
16
+ private parseResponse;
17
+ }
18
18
  //# sourceMappingURL=batch.d.ts.map
package/batch.js CHANGED
@@ -1,177 +1,177 @@
1
- import { __awaiter, __extends, __generator } from "tslib";
2
- import { Batch } from "@pnp/odata";
3
- import { Logger } from "@pnp/logging";
4
- import { assign, jsS, isUrlAbsolute, hOP, DefaultRuntime } from "@pnp/common";
5
- import { GraphHttpClient } from "./graphhttpclient.js";
6
- import { toAbsoluteUrl } from "./utils/toabsoluteurl.js";
7
- var GraphBatch = /** @class */ (function (_super) {
8
- __extends(GraphBatch, _super);
9
- function GraphBatch(batchUrl, maxRequests, runtime) {
10
- if (batchUrl === void 0) { batchUrl = "v1.0/$batch"; }
11
- if (maxRequests === void 0) { maxRequests = 20; }
12
- if (runtime === void 0) { runtime = DefaultRuntime; }
13
- var _this = _super.call(this) || this;
14
- _this.batchUrl = batchUrl;
15
- _this.maxRequests = maxRequests;
16
- _this.runtime = runtime;
17
- return _this;
18
- }
19
- GraphBatch.prototype.setRuntime = function (runtime) {
20
- this.runtime = runtime;
21
- return this;
22
- };
23
- GraphBatch.prototype.executeImpl = function () {
24
- return __awaiter(this, void 0, void 0, function () {
25
- var client, requests, _loop_1, this_1;
26
- var _this = this;
27
- return __generator(this, function (_a) {
28
- switch (_a.label) {
29
- case 0:
30
- Logger.write("[" + this.batchId + "] (" + (new Date()).getTime() + ") Executing batch with " + this.requests.length + " requests.", 1 /* Info */);
31
- if (this.requests.length < 1) {
32
- Logger.write("Resolving empty batch.", 1 /* Info */);
33
- return [2 /*return*/, Promise.resolve()];
34
- }
35
- client = new GraphHttpClient(this.runtime);
36
- requests = this.requests.slice();
37
- _loop_1 = function () {
38
- var requestsChunk, batchRequest, batchOptions, queryUrl;
39
- return __generator(this, function (_b) {
40
- switch (_b.label) {
41
- case 0:
42
- requestsChunk = requests.splice(0, this_1.maxRequests);
43
- batchRequest = {
44
- requests: this_1.formatRequests(requestsChunk),
45
- };
46
- batchOptions = {
47
- body: jsS(batchRequest),
48
- headers: {
49
- "Accept": "application/json",
50
- "Content-Type": "application/json",
51
- },
52
- method: "POST",
53
- };
54
- Logger.write("[" + this_1.batchId + "] (" + (new Date()).getTime() + ") Sending batch request.", 1 /* Info */);
55
- return [4 /*yield*/, toAbsoluteUrl(this_1.batchUrl, this_1.runtime)];
56
- case 1:
57
- queryUrl = _b.sent();
58
- return [4 /*yield*/, client.fetch(queryUrl, batchOptions)
59
- .then(function (r) { return r.json(); })
60
- .then(function (j) { return _this.parseResponse(requestsChunk, j); })
61
- .then(function (parsedResponse) {
62
- Logger.write("[" + _this.batchId + "] (" + (new Date()).getTime() + ") Resolving batched requests.", 1 /* Info */);
63
- parsedResponse.responses.reduce(function (chain, response, index) {
64
- var request = requestsChunk[index];
65
- Logger.write("[" + _this.batchId + "] (" + (new Date()).getTime() + ") Resolving batched request " + request.method + " " + request.url + ".", 0 /* Verbose */);
66
- return chain.then(function () { return request.parser.parse(response).then(request.resolve).catch(request.reject); });
67
- }, Promise.resolve());
68
- }).catch(function (e) {
69
- throw e;
70
- })];
71
- case 2:
72
- _b.sent();
73
- return [2 /*return*/];
74
- }
75
- });
76
- };
77
- this_1 = this;
78
- _a.label = 1;
79
- case 1:
80
- if (!(requests.length > 0)) return [3 /*break*/, 3];
81
- return [5 /*yield**/, _loop_1()];
82
- case 2:
83
- _a.sent();
84
- return [3 /*break*/, 1];
85
- case 3: return [2 /*return*/];
86
- }
87
- });
88
- });
89
- };
90
- /**
91
- * Urls come to the batch absolute, but the processor expects relative
92
- * @param url Url to ensure is relative
93
- */
94
- GraphBatch.prototype.makeUrlRelative = function (url) {
95
- if (!isUrlAbsolute(url)) {
96
- // already not absolute, just give it back
97
- return url;
98
- }
99
- var index = url.indexOf("/v1.0/");
100
- if (index < 0) {
101
- index = url.indexOf("/beta/");
102
- if (index > -1) {
103
- // beta url
104
- return url.substr(index + 6);
105
- }
106
- }
107
- else {
108
- // v1.0 url
109
- return url.substr(index + 5);
110
- }
111
- // no idea
112
- return url;
113
- };
114
- GraphBatch.prototype.formatRequests = function (requests) {
115
- var _this = this;
116
- return requests.map(function (reqInfo, index) {
117
- var _a;
118
- var requestFragment = {
119
- id: "" + ++index,
120
- method: reqInfo.method,
121
- url: _this.makeUrlRelative(reqInfo.url),
122
- };
123
- var headers = {};
124
- // merge runtime headers
125
- headers = assign(headers, (_a = _this.runtime.get("graph")) === null || _a === void 0 ? void 0 : _a.headers);
126
- if (reqInfo.options !== undefined) {
127
- // merge per request headers
128
- if (reqInfo.options.headers !== undefined && reqInfo.options.headers !== null) {
129
- headers = assign(headers, reqInfo.options.headers);
130
- }
131
- // all non-get requests need their own content-type header
132
- if (reqInfo.method !== "GET") {
133
- headers["Content-Type"] = "application/json";
134
- }
135
- // add a request body
136
- if (reqInfo.options.body !== undefined && reqInfo.options.body !== null) {
137
- // we need to parse the body which was previously turned into a string
138
- requestFragment = assign(requestFragment, {
139
- body: JSON.parse(reqInfo.options.body),
140
- });
141
- }
142
- }
143
- requestFragment = assign(requestFragment, {
144
- headers: headers,
145
- });
146
- return requestFragment;
147
- });
148
- };
149
- GraphBatch.prototype.parseResponse = function (requests, graphResponse) {
150
- return new Promise(function (resolve, reject) {
151
- // we need to see if we have an error and report that
152
- if (hOP(graphResponse, "error")) {
153
- return reject(Error("Error Porcessing Batch: (" + graphResponse.error.code + ") " + graphResponse.error.message));
154
- }
155
- var parsedResponses = new Array(requests.length).fill(null);
156
- for (var i = 0; i < graphResponse.responses.length; ++i) {
157
- var response = graphResponse.responses[i];
158
- // we create the request id by adding 1 to the index, so we place the response by subtracting one to match
159
- // the array of requests and make it easier to map them by index
160
- var responseId = parseInt(response.id, 10) - 1;
161
- if (response.status === 204) {
162
- parsedResponses[responseId] = new Response();
163
- }
164
- else {
165
- parsedResponses[responseId] = new Response(JSON.stringify(response.body), response);
166
- }
167
- }
168
- resolve({
169
- nextLink: graphResponse.nextLink,
170
- responses: parsedResponses,
171
- });
172
- });
173
- };
174
- return GraphBatch;
175
- }(Batch));
176
- export { GraphBatch };
1
+ import { __awaiter, __extends, __generator } from "tslib";
2
+ import { Batch } from "@pnp/odata";
3
+ import { Logger } from "@pnp/logging";
4
+ import { assign, jsS, isUrlAbsolute, hOP, DefaultRuntime } from "@pnp/common";
5
+ import { GraphHttpClient } from "./graphhttpclient.js";
6
+ import { toAbsoluteUrl } from "./utils/toabsoluteurl.js";
7
+ var GraphBatch = /** @class */ (function (_super) {
8
+ __extends(GraphBatch, _super);
9
+ function GraphBatch(batchUrl, maxRequests, runtime) {
10
+ if (batchUrl === void 0) { batchUrl = "v1.0/$batch"; }
11
+ if (maxRequests === void 0) { maxRequests = 20; }
12
+ if (runtime === void 0) { runtime = DefaultRuntime; }
13
+ var _this = _super.call(this) || this;
14
+ _this.batchUrl = batchUrl;
15
+ _this.maxRequests = maxRequests;
16
+ _this.runtime = runtime;
17
+ return _this;
18
+ }
19
+ GraphBatch.prototype.setRuntime = function (runtime) {
20
+ this.runtime = runtime;
21
+ return this;
22
+ };
23
+ GraphBatch.prototype.executeImpl = function () {
24
+ return __awaiter(this, void 0, void 0, function () {
25
+ var client, requests, _loop_1, this_1;
26
+ var _this = this;
27
+ return __generator(this, function (_a) {
28
+ switch (_a.label) {
29
+ case 0:
30
+ Logger.write("[" + this.batchId + "] (" + (new Date()).getTime() + ") Executing batch with " + this.requests.length + " requests.", 1 /* Info */);
31
+ if (this.requests.length < 1) {
32
+ Logger.write("Resolving empty batch.", 1 /* Info */);
33
+ return [2 /*return*/, Promise.resolve()];
34
+ }
35
+ client = new GraphHttpClient(this.runtime);
36
+ requests = this.requests.slice();
37
+ _loop_1 = function () {
38
+ var requestsChunk, batchRequest, batchOptions, queryUrl;
39
+ return __generator(this, function (_b) {
40
+ switch (_b.label) {
41
+ case 0:
42
+ requestsChunk = requests.splice(0, this_1.maxRequests);
43
+ batchRequest = {
44
+ requests: this_1.formatRequests(requestsChunk),
45
+ };
46
+ batchOptions = {
47
+ body: jsS(batchRequest),
48
+ headers: {
49
+ "Accept": "application/json",
50
+ "Content-Type": "application/json",
51
+ },
52
+ method: "POST",
53
+ };
54
+ Logger.write("[" + this_1.batchId + "] (" + (new Date()).getTime() + ") Sending batch request.", 1 /* Info */);
55
+ return [4 /*yield*/, toAbsoluteUrl(this_1.batchUrl, this_1.runtime)];
56
+ case 1:
57
+ queryUrl = _b.sent();
58
+ return [4 /*yield*/, client.fetch(queryUrl, batchOptions)
59
+ .then(function (r) { return r.json(); })
60
+ .then(function (j) { return _this.parseResponse(requestsChunk, j); })
61
+ .then(function (parsedResponse) {
62
+ Logger.write("[" + _this.batchId + "] (" + (new Date()).getTime() + ") Resolving batched requests.", 1 /* Info */);
63
+ parsedResponse.responses.reduce(function (chain, response, index) {
64
+ var request = requestsChunk[index];
65
+ Logger.write("[" + _this.batchId + "] (" + (new Date()).getTime() + ") Resolving batched request " + request.method + " " + request.url + ".", 0 /* Verbose */);
66
+ return chain.then(function () { return request.parser.parse(response).then(request.resolve).catch(request.reject); });
67
+ }, Promise.resolve());
68
+ }).catch(function (e) {
69
+ throw e;
70
+ })];
71
+ case 2:
72
+ _b.sent();
73
+ return [2 /*return*/];
74
+ }
75
+ });
76
+ };
77
+ this_1 = this;
78
+ _a.label = 1;
79
+ case 1:
80
+ if (!(requests.length > 0)) return [3 /*break*/, 3];
81
+ return [5 /*yield**/, _loop_1()];
82
+ case 2:
83
+ _a.sent();
84
+ return [3 /*break*/, 1];
85
+ case 3: return [2 /*return*/];
86
+ }
87
+ });
88
+ });
89
+ };
90
+ /**
91
+ * Urls come to the batch absolute, but the processor expects relative
92
+ * @param url Url to ensure is relative
93
+ */
94
+ GraphBatch.prototype.makeUrlRelative = function (url) {
95
+ if (!isUrlAbsolute(url)) {
96
+ // already not absolute, just give it back
97
+ return url;
98
+ }
99
+ var index = url.indexOf("/v1.0/");
100
+ if (index < 0) {
101
+ index = url.indexOf("/beta/");
102
+ if (index > -1) {
103
+ // beta url
104
+ return url.substr(index + 6);
105
+ }
106
+ }
107
+ else {
108
+ // v1.0 url
109
+ return url.substr(index + 5);
110
+ }
111
+ // no idea
112
+ return url;
113
+ };
114
+ GraphBatch.prototype.formatRequests = function (requests) {
115
+ var _this = this;
116
+ return requests.map(function (reqInfo, index) {
117
+ var _a;
118
+ var requestFragment = {
119
+ id: "" + ++index,
120
+ method: reqInfo.method,
121
+ url: _this.makeUrlRelative(reqInfo.url),
122
+ };
123
+ var headers = {};
124
+ // merge runtime headers
125
+ headers = assign(headers, (_a = _this.runtime.get("graph")) === null || _a === void 0 ? void 0 : _a.headers);
126
+ if (reqInfo.options !== undefined) {
127
+ // merge per request headers
128
+ if (reqInfo.options.headers !== undefined && reqInfo.options.headers !== null) {
129
+ headers = assign(headers, reqInfo.options.headers);
130
+ }
131
+ // all non-get requests need their own content-type header
132
+ if (reqInfo.method !== "GET") {
133
+ headers["Content-Type"] = "application/json";
134
+ }
135
+ // add a request body
136
+ if (reqInfo.options.body !== undefined && reqInfo.options.body !== null) {
137
+ // we need to parse the body which was previously turned into a string
138
+ requestFragment = assign(requestFragment, {
139
+ body: JSON.parse(reqInfo.options.body),
140
+ });
141
+ }
142
+ }
143
+ requestFragment = assign(requestFragment, {
144
+ headers: headers,
145
+ });
146
+ return requestFragment;
147
+ });
148
+ };
149
+ GraphBatch.prototype.parseResponse = function (requests, graphResponse) {
150
+ return new Promise(function (resolve, reject) {
151
+ // we need to see if we have an error and report that
152
+ if (hOP(graphResponse, "error")) {
153
+ return reject(Error("Error Porcessing Batch: (" + graphResponse.error.code + ") " + graphResponse.error.message));
154
+ }
155
+ var parsedResponses = new Array(requests.length).fill(null);
156
+ for (var i = 0; i < graphResponse.responses.length; ++i) {
157
+ var response = graphResponse.responses[i];
158
+ // we create the request id by adding 1 to the index, so we place the response by subtracting one to match
159
+ // the array of requests and make it easier to map them by index
160
+ var responseId = parseInt(response.id, 10) - 1;
161
+ if (response.status === 204) {
162
+ parsedResponses[responseId] = new Response();
163
+ }
164
+ else {
165
+ parsedResponses[responseId] = new Response(JSON.stringify(response.body), response);
166
+ }
167
+ }
168
+ resolve({
169
+ nextLink: graphResponse.nextLink,
170
+ responses: parsedResponses,
171
+ });
172
+ });
173
+ };
174
+ return GraphBatch;
175
+ }(Batch));
176
+ export { GraphBatch };
177
177
  //# sourceMappingURL=batch.js.map