microsoft-graph 3.7.2 → 3.9.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 (90) hide show
  1. package/dist/cjs/models/Address.d.ts +32 -1
  2. package/dist/cjs/models/Address.d.ts.map +1 -1
  3. package/dist/cjs/models/DriveItem.d.ts +6 -0
  4. package/dist/cjs/models/DriveItem.d.ts.map +1 -1
  5. package/dist/cjs/operations/driveItem/createDriveItem.d.ts +3 -0
  6. package/dist/cjs/operations/driveItem/createDriveItem.d.ts.map +1 -1
  7. package/dist/cjs/operations/driveItem/createDriveItem.js +3 -0
  8. package/dist/cjs/operations/driveItem/createDriveItemContent.d.ts +21 -0
  9. package/dist/cjs/operations/driveItem/createDriveItemContent.d.ts.map +1 -0
  10. package/dist/cjs/operations/driveItem/createDriveItemContent.js +122 -0
  11. package/dist/cjs/operations/driveItem/existsDriveItem.d.ts.map +1 -1
  12. package/dist/cjs/operations/driveItem/existsDriveItem.js +1 -2
  13. package/dist/cjs/operations/driveItem/getDriveItemContent.d.ts.map +1 -1
  14. package/dist/cjs/operations/driveItem/getDriveItemContent.js +2 -9
  15. package/dist/cjs/operations/driveItem/streamDriveItemContent.d.ts.map +1 -1
  16. package/dist/cjs/operations/driveItem/streamDriveItemContent.js +2 -9
  17. package/dist/cjs/services/http.d.ts +12 -2
  18. package/dist/cjs/services/http.d.ts.map +1 -1
  19. package/dist/cjs/services/http.js +207 -3
  20. package/dist/cjs/services/httpStatus.d.ts +6 -0
  21. package/dist/cjs/services/httpStatus.d.ts.map +1 -1
  22. package/dist/cjs/services/httpStatus.js +9 -0
  23. package/dist/cjs/services/iteration.d.ts +6 -6
  24. package/dist/cjs/services/iteration.d.ts.map +1 -1
  25. package/dist/cjs/services/iteration.js +7 -7
  26. package/dist/cjs/services/operationInvoker.d.ts +0 -1
  27. package/dist/cjs/services/operationInvoker.d.ts.map +1 -1
  28. package/dist/cjs/services/operationInvoker.js +8 -207
  29. package/dist/cjs/services/usedAddress.d.ts +25 -0
  30. package/dist/cjs/services/usedAddress.d.ts.map +1 -0
  31. package/dist/cjs/services/usedAddress.js +69 -0
  32. package/dist/cjs/tasks/iterateDriveItems.d.ts.map +1 -1
  33. package/dist/cjs/tasks/iterateDriveItems.js +1 -2
  34. package/dist/cjs/tasks/iterateDrives.d.ts.map +1 -1
  35. package/dist/cjs/tasks/iterateDrives.js +1 -2
  36. package/dist/cjs/tasks/iterateSiteSearch.d.ts.map +1 -1
  37. package/dist/cjs/tasks/iterateSiteSearch.js +1 -2
  38. package/dist/cjs/tasks/iterateSites.d.ts.map +1 -1
  39. package/dist/cjs/tasks/iterateSites.js +1 -2
  40. package/dist/esm/models/Address.d.ts +32 -1
  41. package/dist/esm/models/Address.d.ts.map +1 -1
  42. package/dist/esm/models/DriveItem.d.ts +6 -0
  43. package/dist/esm/models/DriveItem.d.ts.map +1 -1
  44. package/dist/esm/operations/driveItem/createDriveItem.d.ts +3 -0
  45. package/dist/esm/operations/driveItem/createDriveItem.d.ts.map +1 -1
  46. package/dist/esm/operations/driveItem/createDriveItem.js +3 -0
  47. package/dist/esm/operations/driveItem/createDriveItemContent.d.ts +21 -0
  48. package/dist/esm/operations/driveItem/createDriveItemContent.d.ts.map +1 -0
  49. package/dist/esm/operations/driveItem/createDriveItemContent.js +116 -0
  50. package/dist/esm/operations/driveItem/existsDriveItem.d.ts.map +1 -1
  51. package/dist/esm/operations/driveItem/existsDriveItem.js +2 -3
  52. package/dist/esm/operations/driveItem/getDriveItemContent.d.ts.map +1 -1
  53. package/dist/esm/operations/driveItem/getDriveItemContent.js +4 -11
  54. package/dist/esm/operations/driveItem/streamDriveItemContent.d.ts.map +1 -1
  55. package/dist/esm/operations/driveItem/streamDriveItemContent.js +4 -11
  56. package/dist/esm/services/http.d.ts +12 -2
  57. package/dist/esm/services/http.d.ts.map +1 -1
  58. package/dist/esm/services/http.js +204 -2
  59. package/dist/esm/services/httpStatus.d.ts +6 -0
  60. package/dist/esm/services/httpStatus.d.ts.map +1 -1
  61. package/dist/esm/services/httpStatus.js +8 -0
  62. package/dist/esm/services/iteration.d.ts +6 -6
  63. package/dist/esm/services/iteration.d.ts.map +1 -1
  64. package/dist/esm/services/iteration.js +5 -5
  65. package/dist/esm/services/operationInvoker.d.ts +0 -1
  66. package/dist/esm/services/operationInvoker.d.ts.map +1 -1
  67. package/dist/esm/services/operationInvoker.js +10 -208
  68. package/dist/esm/services/usedAddress.d.ts +25 -0
  69. package/dist/esm/services/usedAddress.d.ts.map +1 -0
  70. package/dist/esm/services/usedAddress.js +63 -0
  71. package/dist/esm/tasks/iterateDriveItems.d.ts.map +1 -1
  72. package/dist/esm/tasks/iterateDriveItems.js +2 -3
  73. package/dist/esm/tasks/iterateDrives.d.ts.map +1 -1
  74. package/dist/esm/tasks/iterateDrives.js +2 -3
  75. package/dist/esm/tasks/iterateSiteSearch.d.ts.map +1 -1
  76. package/dist/esm/tasks/iterateSiteSearch.js +2 -3
  77. package/dist/esm/tasks/iterateSites.d.ts.map +1 -1
  78. package/dist/esm/tasks/iterateSites.js +2 -3
  79. package/docs/api/Address.md +99 -13
  80. package/docs/api/DriveItem-1.md +16 -0
  81. package/docs/api/Iteration.md +22 -13
  82. package/docs/api/README.md +3 -2
  83. package/docs/api/createDriveItemContent.md +37 -0
  84. package/docs/api/http.md +65 -4
  85. package/docs/api/httpStatus.md +48 -26
  86. package/docs/api/operationInvoker.md +3 -22
  87. package/docs/api/services/usedAddress.md +47 -0
  88. package/docs/api/streamDriveItemContent.md +1 -1
  89. package/package.json +21 -1
  90. package/docs/api/createDriveItem.md +0 -38
@@ -1 +1 @@
1
- {"version":3,"file":"createDriveItem.d.ts","sourceRoot":"","sources":["../../../../src/operations/driveItem/createDriveItem.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAe,aAAa,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC1F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAKrE;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,SAAS,EAAE,QAAQ,GAAG,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,cAAc,CAAC,SAAS,GAAG,YAAY,CAAC,CAsBxL"}
1
+ {"version":3,"file":"createDriveItem.d.ts","sourceRoot":"","sources":["../../../../src/operations/driveItem/createDriveItem.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAe,aAAa,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC1F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAKrE;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,SAAS,EAAE,QAAQ,GAAG,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,cAAc,CAAC,SAAS,GAAG,YAAY,CAAC,CAsBxL"}
@@ -2,6 +2,7 @@
2
2
  * Creates new drive item in the specified parent drive or folder.
3
3
  * @module createDriveItem
4
4
  * @category Operations
5
+ * @hidden
5
6
  */
6
7
  import { createDriveItemRef } from "../../services/driveItem.js";
7
8
  import { operation } from "../../services/operationInvoker.js";
@@ -13,6 +14,8 @@ import { generatePath } from "../../services/templatedPaths.js";
13
14
  * @returns The newly created drive item.
14
15
  * @remarks If the file already exists, it will be replaced.
15
16
  * @see https://learn.microsoft.com/en-us/graph/api/driveitem-put-content
17
+ * @deprecated Use {@link createDriveItemContent} instead for uploading content.
18
+ * @hidden
16
19
  */
17
20
  export default function createDriveItem(parentRef, itemPath, contextType, content) {
18
21
  const pathSegment = parentRef.itemId ? "items/{item-id}" : "root";
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Creates a new drive item in the specified parent drive or folder using a stream as content.
3
+ * @module createDriveItemContent
4
+ * @category Operations
5
+ */
6
+ import type { DriveItem } from "@microsoft/microsoft-graph-types";
7
+ import type { DriveRef } from "../../models/Drive.ts";
8
+ import type { DriveItemPath, DriveItemRef } from "../../models/DriveItem.ts";
9
+ /**
10
+ * Creates a new drive item in the specified parent drive or folder using a stream as content.
11
+ * @param parentRef Reference to the parent drive or folder where the drive item will be created.
12
+ * @param itemPath Path (including the filename) for the new drive item within the given parent.
13
+ * @param contentStream A Node.js readable stream containing the file content.
14
+ * @param totalSize The total size in bytes of the content to be uploaded.
15
+ * @param conflictBehavior Optional. Specifies how to handle conflicts if the file already exists. Default is 'fail'.
16
+ * @returns The newly created drive item.
17
+ * @see https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession
18
+ * @see https://learn.microsoft.com/en-us/graph/api/resources/uploadsession
19
+ */
20
+ export default function createDriveItemContent(parentRef: DriveRef | DriveItemRef, itemPath: DriveItemPath, contentStream: NodeJS.ReadableStream, totalSize: number, conflictBehavior?: "fail" | "replace" | "rename", chunkSize?: number): Promise<DriveItem & DriveItemRef>;
21
+ //# sourceMappingURL=createDriveItemContent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createDriveItemContent.d.ts","sourceRoot":"","sources":["../../../../src/operations/driveItem/createDriveItemContent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAElE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAe,aAAa,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAkB1F;;;;;;;;;;GAUG;AACH,wBAA8B,sBAAsB,CAAC,SAAS,EAAE,QAAQ,GAAG,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,CAAC,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,gBAAgB,GAAE,MAAM,GAAG,SAAS,GAAG,QAAiB,EAAE,SAAS,SAAmB,GAAG,OAAO,CAAC,SAAS,GAAG,YAAY,CAAC,CAmGpS"}
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Creates a new drive item in the specified parent drive or folder using a stream as content.
3
+ * @module createDriveItemContent
4
+ * @category Operations
5
+ */
6
+ import ProtocolError from "../../errors/ProtocolError.js";
7
+ import { createDriveItemRef } from "../../services/driveItem.js";
8
+ import { execute } from "../../services/http.js";
9
+ import { endpoint } from "../../services/operationInvoker.js";
10
+ import { generatePath } from "../../services/templatedPaths.js";
11
+ const defaultChunkSize = 10 * 1024 * 1024;
12
+ /**
13
+ * Creates a new drive item in the specified parent drive or folder using a stream as content.
14
+ * @param parentRef Reference to the parent drive or folder where the drive item will be created.
15
+ * @param itemPath Path (including the filename) for the new drive item within the given parent.
16
+ * @param contentStream A Node.js readable stream containing the file content.
17
+ * @param totalSize The total size in bytes of the content to be uploaded.
18
+ * @param conflictBehavior Optional. Specifies how to handle conflicts if the file already exists. Default is 'fail'.
19
+ * @returns The newly created drive item.
20
+ * @see https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession
21
+ * @see https://learn.microsoft.com/en-us/graph/api/resources/uploadsession
22
+ */
23
+ export default async function createDriveItemContent(parentRef, itemPath, contentStream, totalSize, conflictBehavior = "fail", chunkSize = defaultChunkSize) {
24
+ const pathSegment = parentRef.itemId ? "items/{item-id}" : "root";
25
+ const uploadSessionUrl = `${endpoint}${generatePath(`/sites/{site-id}/drives/{drive-id}/${pathSegment}:/${itemPath}:/createUploadSession`, parentRef)}`;
26
+ const accessToken = await parentRef.context.generateAccessToken();
27
+ const fileName = itemPath.split("/").pop();
28
+ const { uploadUrl } = await execute({
29
+ url: uploadSessionUrl,
30
+ method: "POST",
31
+ headers: {
32
+ authorization: `Bearer ${accessToken}`,
33
+ "content-type": "application/json",
34
+ },
35
+ data: JSON.stringify({
36
+ item: {
37
+ "@microsoft.graph.conflictBehavior": conflictBehavior,
38
+ name: fileName,
39
+ },
40
+ }),
41
+ responseType: "json",
42
+ });
43
+ let position = 0;
44
+ let driveItem = null;
45
+ let streamEnded = false;
46
+ const chunks = [];
47
+ contentStream.on("data", (chunk) => {
48
+ chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
49
+ });
50
+ contentStream.on("end", () => {
51
+ streamEnded = true;
52
+ });
53
+ contentStream.on("error", () => {
54
+ // error will be handled in readChunk
55
+ });
56
+ let chunk = await readChunk();
57
+ while (chunk !== null) {
58
+ let currentChunk = chunk;
59
+ while (currentChunk.length > 0) {
60
+ const thisChunk = currentChunk.subarray(0, chunkSize);
61
+ const start = position;
62
+ const end = position + thisChunk.length - 1;
63
+ const contentRange = `bytes ${start}-${end}/${totalSize}`;
64
+ const res = await execute({
65
+ url: uploadUrl,
66
+ method: "PUT",
67
+ headers: {
68
+ "Content-Length": thisChunk.length.toString(),
69
+ "Content-Range": contentRange,
70
+ },
71
+ data: thisChunk,
72
+ responseType: "json",
73
+ });
74
+ position += thisChunk.length;
75
+ currentChunk = currentChunk.subarray(chunkSize);
76
+ if (isDriveItem(res)) {
77
+ driveItem = res;
78
+ break;
79
+ }
80
+ }
81
+ if (driveItem)
82
+ break;
83
+ chunk = await readChunk();
84
+ }
85
+ if (!driveItem) {
86
+ throw new ProtocolError(`Upload did not complete successfully. Last position: ${position}`);
87
+ }
88
+ const itemRef = createDriveItemRef(parentRef, driveItem.id);
89
+ return {
90
+ ...driveItem,
91
+ ...itemRef,
92
+ };
93
+ function isDriveItem(obj) {
94
+ return typeof obj === "object" && obj !== null && "id" in obj;
95
+ }
96
+ function readChunk() {
97
+ return new Promise((resolve, reject) => {
98
+ if (chunks.length > 0) {
99
+ const next = chunks.shift();
100
+ return resolve(next ?? null);
101
+ }
102
+ if (streamEnded)
103
+ return resolve(null);
104
+ contentStream.once("data", (chunk) => {
105
+ resolve(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
106
+ });
107
+ contentStream.once("end", () => {
108
+ streamEnded = true;
109
+ resolve(null);
110
+ });
111
+ contentStream.once("error", (err) => {
112
+ reject(err);
113
+ });
114
+ });
115
+ }
116
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"existsDriveItem.d.ts","sourceRoot":"","sources":["../../../../src/operations/driveItem/existsDriveItem.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAM/D;;;;GAIG;AACH,wBAA8B,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,CAuB3G"}
1
+ {"version":3,"file":"existsDriveItem.d.ts","sourceRoot":"","sources":["../../../../src/operations/driveItem/existsDriveItem.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAM/D;;;;GAIG;AACH,wBAA8B,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,CAsB3G"}
@@ -3,7 +3,7 @@
3
3
  * @module existsDriveItem
4
4
  * @category Operations
5
5
  */
6
- import { executeHttpRequest } from "../../services/http.js";
6
+ import { executeRaw } from "../../services/http.js";
7
7
  import { isHttpNotFound, isHttpOk } from "../../services/httpStatus.js";
8
8
  import { endpoint } from "../../services/operationInvoker.js";
9
9
  import { generatePath } from "../../services/templatedPaths.js";
@@ -16,13 +16,12 @@ export default async function existsDriveItem(driveRef, itemPath) {
16
16
  // Note this method doesn't match the standard pattern since the batching library doesn't support non-JSON return types.
17
17
  const url = `${endpoint}${generatePath(`/sites/{site-id}/drives/{drive-id}/root:${itemPath}`, driveRef)}`;
18
18
  const accessToken = await driveRef.context.generateAccessToken();
19
- const response = await executeHttpRequest({
19
+ const response = await executeRaw({
20
20
  url,
21
21
  method: "GET",
22
22
  headers: {
23
23
  authorization: `Bearer ${accessToken}`,
24
24
  },
25
- validateStatus: () => true,
26
25
  });
27
26
  if (isHttpOk(response.status)) {
28
27
  return true;
@@ -1 +1 @@
1
- {"version":3,"file":"getDriveItemContent.d.ts","sourceRoot":"","sources":["../../../../src/operations/driveItem/getDriveItemContent.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAM9D;;;;;;;;;GASG;AACH,wBAA8B,mBAAmB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,CA6B7F"}
1
+ {"version":3,"file":"getDriveItemContent.d.ts","sourceRoot":"","sources":["../../../../src/operations/driveItem/getDriveItemContent.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAK9D;;;;;;;;;GASG;AACH,wBAA8B,mBAAmB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,CAqB7F"}
@@ -4,9 +4,8 @@
4
4
  * @category Operations
5
5
  * @hidden
6
6
  */
7
- import { executeHttpRequest } from "../../services/http.js";
8
- import { isHttpSuccess } from "../../services/httpStatus.js";
9
- import { endpoint, throwException } from "../../services/operationInvoker.js";
7
+ import { execute } from "../../services/http.js";
8
+ import { endpoint } from "../../services/operationInvoker.js";
10
9
  import { generatePath } from "../../services/templatedPaths.js";
11
10
  /**
12
11
  * Download the content of a drive item.
@@ -22,7 +21,7 @@ export default async function getDriveItemContent(itemRef) {
22
21
  // Note this method doesn't match the standard pattern since the batching library doesn't support non-JSON return types, and there appears to be no value in adding support.
23
22
  const url = `${endpoint}${generatePath("/sites/{site-id}/drives/{drive-id}/items/{item-id}/content", itemRef)}`;
24
23
  const accessToken = await itemRef.context.generateAccessToken();
25
- const response = await executeHttpRequest({
24
+ const response = await execute({
26
25
  url,
27
26
  method: "GET",
28
27
  headers: {
@@ -30,13 +29,7 @@ export default async function getDriveItemContent(itemRef) {
30
29
  },
31
30
  responseType: "arraybuffer",
32
31
  });
33
- if (!isHttpSuccess(response.status)) {
34
- throwException(response.status, "Failed to get content");
35
- }
36
- if (!Buffer.isBuffer(response.data)) {
37
- throw new Error(`Unexpected response type: ${typeof response.data}`);
38
- }
39
- const buffer = response.data.buffer.slice(response.data.byteOffset, response.data.byteOffset + response.data.byteLength);
32
+ const buffer = response.buffer.slice(response.byteOffset, response.byteOffset + response.byteLength);
40
33
  if (!(buffer instanceof ArrayBuffer)) {
41
34
  throw new Error("Failed to convert Buffer to ArrayBuffer");
42
35
  }
@@ -1 +1 @@
1
- {"version":3,"file":"streamDriveItemContent.d.ts","sourceRoot":"","sources":["../../../../src/operations/driveItem/streamDriveItemContent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAM9D;;;;;;;GAOG;AACH,wBAA8B,sBAAsB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAuB1G"}
1
+ {"version":3,"file":"streamDriveItemContent.d.ts","sourceRoot":"","sources":["../../../../src/operations/driveItem/streamDriveItemContent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAK9D;;;;;;;GAOG;AACH,wBAA8B,sBAAsB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAe1G"}
@@ -3,9 +3,8 @@
3
3
  * @module streamDriveItemContent
4
4
  * @category Operations
5
5
  */
6
- import { executeHttpRequest } from "../../services/http.js";
7
- import { isHttpSuccess } from "../../services/httpStatus.js";
8
- import { endpoint, throwException } from "../../services/operationInvoker.js";
6
+ import { execute } from "../../services/http.js";
7
+ import { endpoint } from "../../services/operationInvoker.js";
9
8
  import { generatePath } from "../../services/templatedPaths.js";
10
9
  /**
11
10
  * Stream the content of a drive item.
@@ -19,7 +18,7 @@ export default async function streamDriveItemContent(itemRef) {
19
18
  // TODO: Rename to getDriveItemContent at next breaking update
20
19
  const url = `${endpoint}${generatePath("/sites/{site-id}/drives/{drive-id}/items/{item-id}/content", itemRef)}`;
21
20
  const accessToken = await itemRef.context.generateAccessToken();
22
- const response = await executeHttpRequest({
21
+ const response = await execute({
23
22
  url,
24
23
  method: "GET",
25
24
  headers: {
@@ -27,11 +26,5 @@ export default async function streamDriveItemContent(itemRef) {
27
26
  },
28
27
  responseType: "stream",
29
28
  });
30
- if (!isHttpSuccess(response.status)) {
31
- throwException(response.status, "Failed to stream content");
32
- }
33
- if (!response || typeof response.data?.pipe !== "function") {
34
- throw new Error("Failed to get a streamable response");
35
- }
36
- return response.data;
29
+ return response;
37
30
  }
@@ -3,6 +3,16 @@
3
3
  * @module http
4
4
  * @category Services
5
5
  */
6
- import { type AxiosRequestConfig } from "axios";
7
- export declare function executeHttpRequest(config: AxiosRequestConfig): Promise<import("axios").AxiosResponse<any, any>>;
6
+ import { type AxiosResponse, type RawAxiosRequestHeaders, type ResponseType } from "axios";
7
+ import type { HttpMethod } from "../models/Http.ts";
8
+ export type Request = {
9
+ url: string;
10
+ method: HttpMethod;
11
+ headers?: RawAxiosRequestHeaders;
12
+ data?: unknown;
13
+ responseType?: ResponseType;
14
+ };
15
+ export declare function execute<TResponse>(request: Request): Promise<TResponse>;
16
+ export declare function throwHttpException(responseCode: number, message: string): never;
17
+ export declare function executeRaw(request: Request): Promise<AxiosResponse<any, any>>;
8
18
  //# sourceMappingURL=http.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/services/http.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAc,EAAsB,KAAK,kBAAkB,EAA4B,MAAM,OAAO,CAAC;AAKrG,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,oDAMlE"}
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/services/http.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAc,EAA+C,KAAK,aAAa,EAA4B,KAAK,sBAAsB,EAAE,KAAK,YAAY,EAAE,MAAM,OAAO,CAAC;AA0BzK,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAkCpD,MAAM,MAAM,OAAO,GAAG;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,CAAC,EAAE,sBAAsB,CAAC;IACjC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,YAAY,CAAC,EAAE,YAAY,CAAC;CAC5B,CAAC;AAEF,wBAAsB,OAAO,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAkD7E;AAED,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,KAAK,CAwE/E;AAID,wBAAsB,UAAU,CAAC,OAAO,EAAE,OAAO,oCAMhD"}
@@ -5,12 +5,159 @@
5
5
  */
6
6
  import axios from "axios";
7
7
  import { HttpsProxyAgent } from "https-proxy-agent";
8
+ import BadRequestError from "../errors/BadRequestError.js";
9
+ import BandwidthLimitExceededError from "../errors/BandwidthLimitExceededError.js";
10
+ import ConflictError from "../errors/ConflictError.js";
11
+ import ForbiddenError from "../errors/ForbiddenError.js";
12
+ import GatewayTimeoutError from "../errors/GatewayTimeoutError.js";
13
+ import GoneError from "../errors/GoneError.js";
14
+ import InsufficientStorageError from "../errors/InsufficientStorageError.js";
15
+ import InternalServerError from "../errors/InternalServerError.js";
16
+ import LengthRequiredError from "../errors/LengthRequiredError.js";
17
+ import LockedError from "../errors/LockedError.js";
18
+ import MethodNotAllowedError from "../errors/MethodNotAllowedError.js";
19
+ import NeverError from "../errors/NeverError.js";
20
+ import NotAcceptableError from "../errors/NotAcceptableError.js";
21
+ import NotFoundError from "../errors/NotFoundError.js";
22
+ import NotImplementedError from "../errors/NotImplementedError.js";
23
+ import PaymentRequiredError from "../errors/PaymentRequiredError.js";
24
+ import PreconditionFailedError from "../errors/PreconditionFailedError.js";
25
+ import RequestedRangeNotSatisfiableError from "../errors/RequestedRangeNotSatisfiableError.js";
26
+ import RequestEntityTooLargeError from "../errors/RequestEntityTooLargeError.js";
27
+ import ServiceUnavailableError from "../errors/ServiceUnavailableError.js";
28
+ import TooManyRequestsError from "../errors/TooManyRequestsError.js";
29
+ import UnauthorizedError from "../errors/UnauthorizedError.js";
30
+ import UnprocessableEntityError from "../errors/UnprocessableEntityError.js";
31
+ import UnsupportedMediaTypeError from "../errors/UnsupportedMediaTypeError.js";
32
+ import { isHttpBadRequest, isHttpBandwidthLimitExceeded, isHttpConflict, isHttpForbidden, isHttpGatewayTimeout, isHttpGone, isHttpInsufficientStorage, isHttpInternalServerError, isHttpLengthRequired, isHttpLocked, isHttpMethodNotAllowed, isHttpNotAcceptable, isHttpNotFound, isHttpNotImplemented, isHttpPaymentRequired, isHttpPreconditionFailed, isHttpRequestedRangeNotSatisfiable, isHttpRequestEntityTooLarge, isHttpServiceUnavailable, isHttpSuccess, isHttpTooManyRequests, isHttpUnauthorized, isHttpUnprocessableEntity, isHttpUnsupportedMediaType, isRetryable, } from "./httpStatus.js";
33
+ import { sleep } from "./sleep.js";
34
+ const maxRetries = 3;
35
+ const defaultRetryDelayMilliseconds = 1000;
36
+ const consecutiveRetryDelayMultiplier = 2;
37
+ export async function execute(request) {
38
+ let retryAfterMilliseconds = defaultRetryDelayMilliseconds;
39
+ let response = null;
40
+ let attempts = 0;
41
+ let errorLog = "";
42
+ while (true) {
43
+ try {
44
+ response = await executeRaw(request);
45
+ }
46
+ catch (error) {
47
+ const message = error instanceof Error ? error.message : error?.toString() || "Unknown error";
48
+ response = {
49
+ status: -1,
50
+ statusText: message,
51
+ headers: {},
52
+ data: null,
53
+ config: request,
54
+ request: null,
55
+ };
56
+ errorLog += message;
57
+ }
58
+ errorLog += requestToString(request);
59
+ errorLog += responseToString(response);
60
+ attempts++;
61
+ if (isHttpSuccess(response.status) || !isRetryable(response.status) || attempts === maxRetries) {
62
+ break;
63
+ }
64
+ const requestedRetryAfterSeconds = Number.parseInt(response.headers["retry-after"] ?? "0", 10);
65
+ if (requestedRetryAfterSeconds) {
66
+ retryAfterMilliseconds = requestedRetryAfterSeconds * 1000;
67
+ }
68
+ else {
69
+ retryAfterMilliseconds += Math.random() * 1000; // Add some randomness to the retry delay to avoid thundering herd problem
70
+ }
71
+ errorLog += waitToString(retryAfterMilliseconds);
72
+ await sleep(retryAfterMilliseconds);
73
+ retryAfterMilliseconds *= consecutiveRetryDelayMultiplier;
74
+ }
75
+ if (!response) {
76
+ throw new NeverError("Response is empty.");
77
+ }
78
+ if (!isHttpSuccess(response.status)) {
79
+ handleResponseError(response, errorLog, attempts);
80
+ }
81
+ return response.data;
82
+ }
83
+ export function throwHttpException(responseCode, message) {
84
+ if (isHttpBadRequest(responseCode)) {
85
+ throw new BadRequestError(message);
86
+ }
87
+ if (isHttpUnauthorized(responseCode)) {
88
+ throw new UnauthorizedError(message);
89
+ }
90
+ if (isHttpPaymentRequired(responseCode)) {
91
+ throw new PaymentRequiredError(message);
92
+ }
93
+ if (isHttpForbidden(responseCode)) {
94
+ throw new ForbiddenError(message);
95
+ }
96
+ if (isHttpNotFound(responseCode)) {
97
+ throw new NotFoundError(message);
98
+ }
99
+ if (isHttpMethodNotAllowed(responseCode)) {
100
+ throw new MethodNotAllowedError(message);
101
+ }
102
+ if (isHttpNotAcceptable(responseCode)) {
103
+ throw new NotAcceptableError(message);
104
+ }
105
+ if (isHttpConflict(responseCode)) {
106
+ throw new ConflictError(message);
107
+ }
108
+ if (isHttpGone(responseCode)) {
109
+ throw new GoneError(message);
110
+ }
111
+ if (isHttpLengthRequired(responseCode)) {
112
+ throw new LengthRequiredError(message);
113
+ }
114
+ if (isHttpPreconditionFailed(responseCode)) {
115
+ throw new PreconditionFailedError(message);
116
+ }
117
+ if (isHttpRequestEntityTooLarge(responseCode)) {
118
+ throw new RequestEntityTooLargeError(message);
119
+ }
120
+ if (isHttpUnsupportedMediaType(responseCode)) {
121
+ throw new UnsupportedMediaTypeError(message);
122
+ }
123
+ if (isHttpRequestedRangeNotSatisfiable(responseCode)) {
124
+ throw new RequestedRangeNotSatisfiableError(message);
125
+ }
126
+ if (isHttpUnprocessableEntity(responseCode)) {
127
+ throw new UnprocessableEntityError(message);
128
+ }
129
+ if (isHttpLocked(responseCode)) {
130
+ throw new LockedError(message);
131
+ }
132
+ if (isHttpTooManyRequests(responseCode)) {
133
+ throw new TooManyRequestsError(message);
134
+ }
135
+ if (isHttpInternalServerError(responseCode)) {
136
+ throw new InternalServerError(message);
137
+ }
138
+ if (isHttpNotImplemented(responseCode)) {
139
+ throw new NotImplementedError(message);
140
+ }
141
+ if (isHttpServiceUnavailable(responseCode)) {
142
+ throw new ServiceUnavailableError(message);
143
+ }
144
+ if (isHttpGatewayTimeout(responseCode)) {
145
+ throw new GatewayTimeoutError(message);
146
+ }
147
+ if (isHttpInsufficientStorage(responseCode)) {
148
+ throw new InsufficientStorageError(message);
149
+ }
150
+ if (isHttpBandwidthLimitExceeded(responseCode)) {
151
+ throw new BandwidthLimitExceededError(message);
152
+ }
153
+ throw new Error(message);
154
+ }
8
155
  let instance = null;
9
- export async function executeHttpRequest(config) {
156
+ export async function executeRaw(request) {
10
157
  if (!instance) {
11
158
  instance = createAxiosInstance();
12
159
  }
13
- return await instance(config);
160
+ return await instance(request);
14
161
  }
15
162
  function createAxiosInstance() {
16
163
  const config = {
@@ -24,3 +171,58 @@ function createAxiosInstance() {
24
171
  }
25
172
  return axios.create(config);
26
173
  }
174
+ function requestToString(request) {
175
+ const url = request.url || "";
176
+ let message = ` 📤 ${request.method} ${url}\n`;
177
+ if (request.data) {
178
+ message += errorObjectToString(request.data);
179
+ }
180
+ return message;
181
+ }
182
+ function responseToString(response) {
183
+ const message = ` 📥 ${response.status} ${response.statusText}\n`;
184
+ // TODO: Is there any case where we care about the response body?
185
+ // if (response.data) {
186
+ // message += errorObjectToString(response.data);
187
+ // }
188
+ return message;
189
+ }
190
+ function waitToString(milliseconds) {
191
+ return ` ⏳ Wait ${milliseconds}ms for retry.\n`;
192
+ }
193
+ function errorObjectToString(obj) {
194
+ const maxLength = 1024;
195
+ const ellipses = "...";
196
+ let str = JSON.stringify(obj, null, 2)
197
+ .split("\n")
198
+ .map((line) => ` ${line}`)
199
+ .join("\n");
200
+ if (str.length > maxLength) {
201
+ str = `${str.substring(0, maxLength - ellipses.length)}${ellipses}`;
202
+ }
203
+ return `${str}\n`;
204
+ }
205
+ function handleResponseError(response, errorLog, attempts, operationIndex = null) {
206
+ const error = response.data;
207
+ let message = error?.error?.message;
208
+ if (message && !message.endsWith(".")) {
209
+ message += ".";
210
+ }
211
+ if (error?.error?.innerError?.message) {
212
+ message += ` ${error.error.innerError.message}`;
213
+ }
214
+ if (message && !message.endsWith(".")) {
215
+ message += ".";
216
+ }
217
+ if (!message) {
218
+ message = response.statusText;
219
+ }
220
+ if (attempts > 1) {
221
+ message += ` Operation attempted ${attempts} time(s).`;
222
+ }
223
+ if (operationIndex !== null) {
224
+ message += ` (op #${operationIndex})`;
225
+ }
226
+ message += `\n${errorLog}`;
227
+ throwHttpException(response.status, message);
228
+ }
@@ -15,6 +15,12 @@ export declare function isHttpSuccess(status: number): boolean;
15
15
  * @returns True if the status code is 200, otherwise false.
16
16
  */
17
17
  export declare function isHttpOk(status: number): boolean;
18
+ /**
19
+ * Checks if the HTTP status code is created
20
+ * @param status - The HTTP status code.
21
+ * @returns True if the status code is 201, otherwise false.
22
+ */
23
+ export declare function isHttpCreated(status: number): boolean;
18
24
  /**
19
25
  * Checks if the HTTP status code indicates not found.
20
26
  * @param status - The HTTP status code.
@@ -1 +1 @@
1
- {"version":3,"file":"httpStatus.d.ts","sourceRoot":"","sources":["../../../src/services/httpStatus.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEhE;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAE5D;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAExD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,C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status) {
20
20
  return status === 200;
21
21
  }
22
+ /**
23
+ * Checks if the HTTP status code is created
24
+ * @param status - The HTTP status code.
25
+ * @returns True if the status code is 201, otherwise false.
26
+ */
27
+ export function isHttpCreated(status) {
28
+ return status === 201;
29
+ }
22
30
  /**
23
31
  * Checks if the HTTP status code indicates not found.
24
32
  * @param status - The HTTP status code.
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * Utilities for iterating over AsyncIterables.
3
+ * Collects all items from an Iterable or AsyncIterable into an array, optionally converting each item.
3
4
  * @module Iteration
4
5
  * @category Services
6
+ * @template TIn The type of items in the input iterable.
7
+ * @template TOut The type of items in the resulting array (after conversion).
8
+ * @param {Iterable<TIn> | AsyncIterable<TIn>} iterable - The iterable or async iterable to collect items from.
9
+ * @returns {Promise<TOut[]>} A promise that resolves to an array of collected (and possibly converted) items.
5
10
  */
6
- /**
7
- * Iterate over an AsyncIterable and collect all items into an array.
8
- * @param iterable
9
- * @returns Array of items collected from the iterable.
10
- */
11
- export declare function iterateToArray<T, U = T>(iterable: AsyncIterable<T>, converter?: (item: T) => U): Promise<U[]>;
11
+ export declare function iterateToArray<TIn, TOut = TIn>(iterable: Iterable<TIn> | AsyncIterable<TIn>, converter?: (item: TIn) => TOut): Promise<TOut[]>;
12
12
  //# sourceMappingURL=iteration.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"iteration.d.ts","sourceRoot":"","sources":["../../../src/services/iteration.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAMnH"}
1
+ {"version":3,"file":"iteration.d.ts","sourceRoot":"","sources":["../../../src/services/iteration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAsB,cAAc,CAAC,GAAG,EAAE,IAAI,GAAG,GAAG,EAAE,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,EAAE,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAMpJ"}
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * Utilities for iterating over AsyncIterables.
3
+ * Collects all items from an Iterable or AsyncIterable into an array, optionally converting each item.
3
4
  * @module Iteration
4
5
  * @category Services
5
- */
6
- /**
7
- * Iterate over an AsyncIterable and collect all items into an array.
8
- * @param iterable
9
- * @returns Array of items collected from the iterable.
6
+ * @template TIn The type of items in the input iterable.
7
+ * @template TOut The type of items in the resulting array (after conversion).
8
+ * @param {Iterable<TIn> | AsyncIterable<TIn>} iterable - The iterable or async iterable to collect items from.
9
+ * @returns {Promise<TOut[]>} A promise that resolves to an array of collected (and possibly converted) items.
10
10
  */
11
11
  export async function iterateToArray(iterable, converter) {
12
12
  const result = [];
@@ -39,5 +39,4 @@ export declare function parallel<T extends GraphOperation<unknown>[]>(...operati
39
39
  * @returns The responses for each operation, in the same order.
40
40
  */
41
41
  export declare function sequential<T extends GraphOperation<unknown>[]>(...operations: T): Promise<OperationResponse<T>>;
42
- export declare function throwException(responseCode: number, message: string): never;
43
42
  //# sourceMappingURL=operationInvoker.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"operationInvoker.d.ts","sourceRoot":"","sources":["../../../src/services/operationInvoker.ts"],"names":[],"mappings":"AAmCA,OAAO,KAAK,EAAE,cAAc,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAiC/G;;;GAGG;AACH,eAAO,MAAM,QAAQ,qCAAqC,CAAC;AAE3D;;;GAGG;AACH,eAAO,MAAM,aAAa,4CAAuB,CAAC;AAElD;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAA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