microsoft-graph 2.11.3 → 2.12.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.
@@ -0,0 +1,4 @@
1
+ export default class TimeoutError extends Error {
2
+ constructor(message: string);
3
+ }
4
+ //# sourceMappingURL=TimeoutError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TimeoutError.d.ts","sourceRoot":"","sources":["../../../src/errors/TimeoutError.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM;CAIlC"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class TimeoutError extends Error {
4
+ constructor(message) {
5
+ super(message);
6
+ this.name = "TimeoutError";
7
+ }
8
+ }
9
+ exports.default = TimeoutError;
@@ -15,10 +15,10 @@ const ProtocolError_ts_1 = __importDefault(require("./errors/ProtocolError.js"))
15
15
  const RequestFailedError_ts_1 = __importDefault(require("./errors/RequestFailedError.js"));
16
16
  const accessToken_ts_1 = require("./services/accessToken.js");
17
17
  const context_ts_1 = require("./services/context.js");
18
+ const http_ts_1 = require("./services/http.js");
18
19
  const httpStatus_ts_1 = require("./services/httpStatus.js");
19
20
  const operationId_ts_1 = require("./services/operationId.js");
20
21
  const sleep_ts_1 = require("./services/sleep.js");
21
- const http_ts_1 = require("./services/http.js");
22
22
  exports.authenticationScope = "https://graph.microsoft.com/.default";
23
23
  exports.endpoint = "https://graph.microsoft.com/v1.0";
24
24
  exports.batchEndpoint = `${exports.endpoint}/$batch`;
@@ -127,20 +127,20 @@ async function innerFetch(args) {
127
127
  }
128
128
  let retryAfterMilliseconds = defaultRetryDelayMilliseconds;
129
129
  let response = null;
130
- let attempts = 0; // Track the number of attempts
131
- while (attempts < maxRetries) {
130
+ let retry = 0;
131
+ while (retry < maxRetries) {
132
132
  try {
133
133
  response = await (0, http_ts_1.executeHttpRequest)({
134
134
  url,
135
135
  ...options,
136
136
  });
137
- break; // If successful, exit the loop
137
+ break;
138
138
  }
139
139
  catch (error) {
140
140
  if (axios_1.default.isAxiosError(error) && error.response) {
141
141
  response = error.response;
142
142
  if (!((0, httpStatus_ts_1.isHttpTooManyRequests)(response.status) || (0, httpStatus_ts_1.isServiceUnavailable)(response.status) || (0, httpStatus_ts_1.isGatewayTimeout)(response.status))) {
143
- throw error; // Don't retry for other error codes
143
+ throw error;
144
144
  }
145
145
  const requestedRetryAfterSeconds = Number.parseInt(response.headers["retry-after"] ?? "0", 10);
146
146
  if (requestedRetryAfterSeconds) {
@@ -148,13 +148,12 @@ async function innerFetch(args) {
148
148
  }
149
149
  await (0, sleep_ts_1.sleep)(retryAfterMilliseconds);
150
150
  retryAfterMilliseconds *= consecutiveRetryDelayMultiplier;
151
- attempts++; // Increment the attempt counter
152
- if (attempts >= maxRetries) {
151
+ retry++;
152
+ if (retry >= maxRetries) {
153
153
  RequestFailedError_ts_1.default.throw(`GraphAPI fetch exceed retry limit of ${maxRetries} attempts.`, args);
154
154
  }
155
155
  }
156
156
  else {
157
- // For non-Axios errors or errors without response, just throw
158
157
  throw error;
159
158
  }
160
159
  }
@@ -1,13 +1,14 @@
1
1
  import type { DriveItemRef } from "../../models/DriveItemRef.ts";
2
+ import type { DriveRef } from "../../models/DriveRef.ts";
2
3
  import type { GraphOperation } from "../../models/GraphOperation.ts";
3
4
  /**
4
5
  * Initiate an asynchronous copy of an item. NOTE: The copied file may not be immediately available and polling is required.
5
6
  *
6
7
  * @param srcFileRef - A reference to the source file to be copied.
7
- * @param dstFolderRef - A reference to the destination folder.
8
+ * @param dstFolderRef - A reference to the destination folder or site (if targeting root).
8
9
  * @param dstFileName - The name of the copied file.
9
10
  * @returns Nothing. The copied file may not be immediately available, and polling is required.
10
11
  * @see https://learn.microsoft.com/en-us/graph/api/driveitem-copy
11
12
  */
12
- export default function initiateCopyDriveItem(srcFileRef: DriveItemRef, dstFolderRef: DriveItemRef, dstFileName: string): GraphOperation<void>;
13
+ export default function initiateCopyDriveItem(srcFileRef: DriveItemRef, dstFolderRef: DriveRef | DriveItemRef, dstFileName: string): GraphOperation<void>;
13
14
  //# sourceMappingURL=initiateCopyDriveItem.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"initiateCopyDriveItem.d.ts","sourceRoot":"","sources":["../../../../src/operations/driveItem/initiateCopyDriveItem.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAGrE;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,GAAG,cAAc,CAAC,IAAI,CAAC,CAkB7I"}
1
+ {"version":3,"file":"initiateCopyDriveItem.d.ts","sourceRoot":"","sources":["../../../../src/operations/driveItem/initiateCopyDriveItem.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAGrE;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,GAAG,YAAY,EAAE,WAAW,EAAE,MAAM,GAAG,cAAc,CAAC,IAAI,CAAC,CAkBxJ"}
@@ -7,7 +7,7 @@ const templatedPaths_ts_1 = require("../../services/templatedPaths.js");
7
7
  * Initiate an asynchronous copy of an item. NOTE: The copied file may not be immediately available and polling is required.
8
8
  *
9
9
  * @param srcFileRef - A reference to the source file to be copied.
10
- * @param dstFolderRef - A reference to the destination folder.
10
+ * @param dstFolderRef - A reference to the destination folder or site (if targeting root).
11
11
  * @param dstFileName - The name of the copied file.
12
12
  * @returns Nothing. The copied file may not be immediately available, and polling is required.
13
13
  * @see https://learn.microsoft.com/en-us/graph/api/driveitem-copy
@@ -25,7 +25,7 @@ function initiateCopyDriveItem(srcFileRef, dstFolderRef, dstFileName) {
25
25
  parentReference: {
26
26
  siteId: dstFolderRef.siteId,
27
27
  driveId: dstFolderRef.driveId,
28
- id: dstFolderRef.itemId,
28
+ id: "itemId" in dstFolderRef ? dstFolderRef.itemId : undefined,
29
29
  },
30
30
  },
31
31
  responseTransform: () => undefined,
@@ -19,4 +19,13 @@ export declare function driveItemPath(...segments: string[]): DriveItemPath;
19
19
  * @throws ProtocolError if the item ID is missing.
20
20
  */
21
21
  export declare function createDriveItemRef(driveRef: DriveRef, itemId: DriveItemId | undefined): DriveItemRef;
22
+ /**
23
+ * Splits a drive item path into its folder path and file name.
24
+ * @param filePath - The full path of the file.
25
+ * @returns An object containing the folder path and file name.
26
+ */
27
+ export declare function splitDriveItemPath(filePath: DriveItemPath): {
28
+ folderPath: DriveItemPath;
29
+ fileName: string;
30
+ };
22
31
  //# sourceMappingURL=driveItem.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"driveItem.d.ts","sourceRoot":"","sources":["../../../src/services/driveItem.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAMtD,eAAO,MAAM,qBAAqB,SAAS,CAAC;AAE5C,eAAO,MAAM,iBAAiB,eAAqB,CAAC;AAEpD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,aAAa,CAkClE;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,GAAG,SAAS,GAAG,YAAY,CAWpG"}
1
+ {"version":3,"file":"driveItem.d.ts","sourceRoot":"","sources":["../../../src/services/driveItem.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAMtD,eAAO,MAAM,qBAAqB,SAAS,CAAC;AAE5C,eAAO,MAAM,iBAAiB,eAAqB,CAAC;AAEpD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,aAAa,CAkClE;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,GAAG,SAAS,GAAG,YAAY,CAWpG;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,aAAa,GAAG;IAAE,UAAU,EAAE,aAAa,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAa3G"}
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.rootDriveItemPath = exports.workbookFileExtension = void 0;
7
7
  exports.driveItemPath = driveItemPath;
8
8
  exports.createDriveItemRef = createDriveItemRef;
9
+ exports.splitDriveItemPath = splitDriveItemPath;
9
10
  const InvalidArgumentError_ts_1 = __importDefault(require("../errors/InvalidArgumentError.js"));
10
11
  const ProtocolError_ts_1 = __importDefault(require("../errors/ProtocolError.js"));
11
12
  const segmentPattern = /^[^"*:<>?\\|#]{1,256}$/;
@@ -63,3 +64,20 @@ function createDriveItemRef(driveRef, itemId) {
63
64
  itemId,
64
65
  };
65
66
  }
67
+ /**
68
+ * Splits a drive item path into its folder path and file name.
69
+ * @param filePath - The full path of the file.
70
+ * @returns An object containing the folder path and file name.
71
+ */
72
+ function splitDriveItemPath(filePath) {
73
+ if (!filePath.startsWith("/")) {
74
+ throw new InvalidArgumentError_ts_1.default("File path must start with a '/'");
75
+ }
76
+ const pos = filePath.lastIndexOf("/");
77
+ const fileName = filePath.substring(pos + 1);
78
+ const folderPath = (pos === 0 ? "/" : filePath.substring(0, pos));
79
+ return {
80
+ folderPath,
81
+ fileName,
82
+ };
83
+ }
@@ -0,0 +1,14 @@
1
+ import type { DriveItem } from "@microsoft/microsoft-graph-types";
2
+ import type { DriveItemPath } from "../models/DriveItemPath.ts";
3
+ import type { DriveItemRef } from "../models/DriveItemRef.ts";
4
+ import type { DriveRef } from "../models/DriveRef.ts";
5
+ /**
6
+ * Copy a drive item, blocking and polling for completion.
7
+ *
8
+ * @param srcFileRef - A reference to the source file to be copied.
9
+ * @param dstFilePath - Destination file path
10
+ * @param timeoutMs - Timeout in milliseconds for the copy operation.
11
+ * @returns
12
+ */
13
+ export default function copyDriveItem(srcFileRef: DriveItemRef, dstDriveRef: DriveRef, dstFilePath: DriveItemPath, timeoutMs?: number): Promise<DriveItem & DriveItemRef>;
14
+ //# sourceMappingURL=copyDriveItem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copyDriveItem.d.ts","sourceRoot":"","sources":["../../../src/tasks/copyDriveItem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAElE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAMtD;;;;;;;GAOG;AACH,wBAA8B,aAAa,CAAC,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,SAAS,SAAQ,GAAG,OAAO,CAAC,SAAS,GAAG,YAAY,CAAC,CAqB7K"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = copyDriveItem;
7
+ const TimeoutError_ts_1 = __importDefault(require("../errors/TimeoutError.js"));
8
+ const getDriveItemByPath_ts_1 = __importDefault(require("../operations/driveItem/getDriveItemByPath.js"));
9
+ const initiateCopyDriveItem_ts_1 = __importDefault(require("../operations/driveItem/initiateCopyDriveItem.js"));
10
+ const driveItem_ts_1 = require("../services/driveItem.js");
11
+ const sleep_ts_1 = require("../services/sleep.js");
12
+ /**
13
+ * Copy a drive item, blocking and polling for completion.
14
+ *
15
+ * @param srcFileRef - A reference to the source file to be copied.
16
+ * @param dstFilePath - Destination file path
17
+ * @param timeoutMs - Timeout in milliseconds for the copy operation.
18
+ * @returns
19
+ */
20
+ async function copyDriveItem(srcFileRef, dstDriveRef, dstFilePath, timeoutMs = 16000) {
21
+ const { folderPath, fileName } = (0, driveItem_ts_1.splitDriveItemPath)(dstFilePath);
22
+ const dstFolder = folderPath === "/" ? dstDriveRef : await (0, getDriveItemByPath_ts_1.default)(dstDriveRef, folderPath);
23
+ await (0, initiateCopyDriveItem_ts_1.default)(srcFileRef, dstFolder, fileName);
24
+ const start = Date.now();
25
+ let delay = 1000;
26
+ while (true) {
27
+ try {
28
+ return await (0, getDriveItemByPath_ts_1.default)(dstDriveRef, dstFilePath);
29
+ }
30
+ catch (_) {
31
+ const elapsedTime = Date.now() - start;
32
+ if (elapsedTime + delay > timeoutMs) {
33
+ throw new TimeoutError_ts_1.default(`Timeout while copying ${srcFileRef.itemId} to ${dstFilePath}`);
34
+ }
35
+ await (0, sleep_ts_1.sleep)(delay);
36
+ delay = Math.min(delay * 2, timeoutMs - (Date.now() - start)); // Double the delay but don't exceed remaining time
37
+ }
38
+ }
39
+ }
@@ -0,0 +1,4 @@
1
+ export default class TimeoutError extends Error {
2
+ constructor(message: string);
3
+ }
4
+ //# sourceMappingURL=TimeoutError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TimeoutError.d.ts","sourceRoot":"","sources":["../../../src/errors/TimeoutError.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM;CAIlC"}
@@ -0,0 +1,6 @@
1
+ export default class TimeoutError extends Error {
2
+ constructor(message) {
3
+ super(message);
4
+ this.name = "TimeoutError";
5
+ }
6
+ }
@@ -6,10 +6,10 @@ import ProtocolError from "./errors/ProtocolError.js";
6
6
  import RequestFailedError from "./errors/RequestFailedError.js";
7
7
  import { getCurrentAccessToken } from "./services/accessToken.js";
8
8
  import { getContext } from "./services/context.js";
9
+ import { executeHttpRequest } from "./services/http.js";
9
10
  import { isGatewayTimeout, isHttpSuccess, isHttpTooManyRequests, isServiceUnavailable } from "./services/httpStatus.js";
10
11
  import { operationIdToIndex, operationIndexToId } from "./services/operationId.js";
11
12
  import { sleep } from "./services/sleep.js";
12
- import { executeHttpRequest } from "./services/http.js";
13
13
  export const authenticationScope = "https://graph.microsoft.com/.default";
14
14
  export const endpoint = "https://graph.microsoft.com/v1.0";
15
15
  export const batchEndpoint = `${endpoint}/$batch`;
@@ -118,20 +118,20 @@ async function innerFetch(args) {
118
118
  }
119
119
  let retryAfterMilliseconds = defaultRetryDelayMilliseconds;
120
120
  let response = null;
121
- let attempts = 0; // Track the number of attempts
122
- while (attempts < maxRetries) {
121
+ let retry = 0;
122
+ while (retry < maxRetries) {
123
123
  try {
124
124
  response = await executeHttpRequest({
125
125
  url,
126
126
  ...options,
127
127
  });
128
- break; // If successful, exit the loop
128
+ break;
129
129
  }
130
130
  catch (error) {
131
131
  if (axios.isAxiosError(error) && error.response) {
132
132
  response = error.response;
133
133
  if (!(isHttpTooManyRequests(response.status) || isServiceUnavailable(response.status) || isGatewayTimeout(response.status))) {
134
- throw error; // Don't retry for other error codes
134
+ throw error;
135
135
  }
136
136
  const requestedRetryAfterSeconds = Number.parseInt(response.headers["retry-after"] ?? "0", 10);
137
137
  if (requestedRetryAfterSeconds) {
@@ -139,13 +139,12 @@ async function innerFetch(args) {
139
139
  }
140
140
  await sleep(retryAfterMilliseconds);
141
141
  retryAfterMilliseconds *= consecutiveRetryDelayMultiplier;
142
- attempts++; // Increment the attempt counter
143
- if (attempts >= maxRetries) {
142
+ retry++;
143
+ if (retry >= maxRetries) {
144
144
  RequestFailedError.throw(`GraphAPI fetch exceed retry limit of ${maxRetries} attempts.`, args);
145
145
  }
146
146
  }
147
147
  else {
148
- // For non-Axios errors or errors without response, just throw
149
148
  throw error;
150
149
  }
151
150
  }
@@ -1,13 +1,14 @@
1
1
  import type { DriveItemRef } from "../../models/DriveItemRef.ts";
2
+ import type { DriveRef } from "../../models/DriveRef.ts";
2
3
  import type { GraphOperation } from "../../models/GraphOperation.ts";
3
4
  /**
4
5
  * Initiate an asynchronous copy of an item. NOTE: The copied file may not be immediately available and polling is required.
5
6
  *
6
7
  * @param srcFileRef - A reference to the source file to be copied.
7
- * @param dstFolderRef - A reference to the destination folder.
8
+ * @param dstFolderRef - A reference to the destination folder or site (if targeting root).
8
9
  * @param dstFileName - The name of the copied file.
9
10
  * @returns Nothing. The copied file may not be immediately available, and polling is required.
10
11
  * @see https://learn.microsoft.com/en-us/graph/api/driveitem-copy
11
12
  */
12
- export default function initiateCopyDriveItem(srcFileRef: DriveItemRef, dstFolderRef: DriveItemRef, dstFileName: string): GraphOperation<void>;
13
+ export default function initiateCopyDriveItem(srcFileRef: DriveItemRef, dstFolderRef: DriveRef | DriveItemRef, dstFileName: string): GraphOperation<void>;
13
14
  //# sourceMappingURL=initiateCopyDriveItem.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"initiateCopyDriveItem.d.ts","sourceRoot":"","sources":["../../../../src/operations/driveItem/initiateCopyDriveItem.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAGrE;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,GAAG,cAAc,CAAC,IAAI,CAAC,CAkB7I"}
1
+ {"version":3,"file":"initiateCopyDriveItem.d.ts","sourceRoot":"","sources":["../../../../src/operations/driveItem/initiateCopyDriveItem.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAGrE;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,GAAG,YAAY,EAAE,WAAW,EAAE,MAAM,GAAG,cAAc,CAAC,IAAI,CAAC,CAkBxJ"}
@@ -4,7 +4,7 @@ import { generatePath } from "../../services/templatedPaths.js";
4
4
  * Initiate an asynchronous copy of an item. NOTE: The copied file may not be immediately available and polling is required.
5
5
  *
6
6
  * @param srcFileRef - A reference to the source file to be copied.
7
- * @param dstFolderRef - A reference to the destination folder.
7
+ * @param dstFolderRef - A reference to the destination folder or site (if targeting root).
8
8
  * @param dstFileName - The name of the copied file.
9
9
  * @returns Nothing. The copied file may not be immediately available, and polling is required.
10
10
  * @see https://learn.microsoft.com/en-us/graph/api/driveitem-copy
@@ -22,7 +22,7 @@ export default function initiateCopyDriveItem(srcFileRef, dstFolderRef, dstFileN
22
22
  parentReference: {
23
23
  siteId: dstFolderRef.siteId,
24
24
  driveId: dstFolderRef.driveId,
25
- id: dstFolderRef.itemId,
25
+ id: "itemId" in dstFolderRef ? dstFolderRef.itemId : undefined,
26
26
  },
27
27
  },
28
28
  responseTransform: () => undefined,
@@ -19,4 +19,13 @@ export declare function driveItemPath(...segments: string[]): DriveItemPath;
19
19
  * @throws ProtocolError if the item ID is missing.
20
20
  */
21
21
  export declare function createDriveItemRef(driveRef: DriveRef, itemId: DriveItemId | undefined): DriveItemRef;
22
+ /**
23
+ * Splits a drive item path into its folder path and file name.
24
+ * @param filePath - The full path of the file.
25
+ * @returns An object containing the folder path and file name.
26
+ */
27
+ export declare function splitDriveItemPath(filePath: DriveItemPath): {
28
+ folderPath: DriveItemPath;
29
+ fileName: string;
30
+ };
22
31
  //# sourceMappingURL=driveItem.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"driveItem.d.ts","sourceRoot":"","sources":["../../../src/services/driveItem.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAMtD,eAAO,MAAM,qBAAqB,SAAS,CAAC;AAE5C,eAAO,MAAM,iBAAiB,eAAqB,CAAC;AAEpD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,aAAa,CAkClE;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,GAAG,SAAS,GAAG,YAAY,CAWpG"}
1
+ {"version":3,"file":"driveItem.d.ts","sourceRoot":"","sources":["../../../src/services/driveItem.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAMtD,eAAO,MAAM,qBAAqB,SAAS,CAAC;AAE5C,eAAO,MAAM,iBAAiB,eAAqB,CAAC;AAEpD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,aAAa,CAkClE;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,GAAG,SAAS,GAAG,YAAY,CAWpG;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,aAAa,GAAG;IAAE,UAAU,EAAE,aAAa,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAa3G"}
@@ -55,3 +55,20 @@ export function createDriveItemRef(driveRef, itemId) {
55
55
  itemId,
56
56
  };
57
57
  }
58
+ /**
59
+ * Splits a drive item path into its folder path and file name.
60
+ * @param filePath - The full path of the file.
61
+ * @returns An object containing the folder path and file name.
62
+ */
63
+ export function splitDriveItemPath(filePath) {
64
+ if (!filePath.startsWith("/")) {
65
+ throw new InvalidArgumentError("File path must start with a '/'");
66
+ }
67
+ const pos = filePath.lastIndexOf("/");
68
+ const fileName = filePath.substring(pos + 1);
69
+ const folderPath = (pos === 0 ? "/" : filePath.substring(0, pos));
70
+ return {
71
+ folderPath,
72
+ fileName,
73
+ };
74
+ }
@@ -0,0 +1,14 @@
1
+ import type { DriveItem } from "@microsoft/microsoft-graph-types";
2
+ import type { DriveItemPath } from "../models/DriveItemPath.ts";
3
+ import type { DriveItemRef } from "../models/DriveItemRef.ts";
4
+ import type { DriveRef } from "../models/DriveRef.ts";
5
+ /**
6
+ * Copy a drive item, blocking and polling for completion.
7
+ *
8
+ * @param srcFileRef - A reference to the source file to be copied.
9
+ * @param dstFilePath - Destination file path
10
+ * @param timeoutMs - Timeout in milliseconds for the copy operation.
11
+ * @returns
12
+ */
13
+ export default function copyDriveItem(srcFileRef: DriveItemRef, dstDriveRef: DriveRef, dstFilePath: DriveItemPath, timeoutMs?: number): Promise<DriveItem & DriveItemRef>;
14
+ //# sourceMappingURL=copyDriveItem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copyDriveItem.d.ts","sourceRoot":"","sources":["../../../src/tasks/copyDriveItem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAElE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAMtD;;;;;;;GAOG;AACH,wBAA8B,aAAa,CAAC,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,SAAS,SAAQ,GAAG,OAAO,CAAC,SAAS,GAAG,YAAY,CAAC,CAqB7K"}
@@ -0,0 +1,33 @@
1
+ import TimeoutError from "../errors/TimeoutError.js";
2
+ import getDriveItemByPath from "../operations/driveItem/getDriveItemByPath.js";
3
+ import initiateCopyDriveItem from "../operations/driveItem/initiateCopyDriveItem.js";
4
+ import { splitDriveItemPath } from "../services/driveItem.js";
5
+ import { sleep } from "../services/sleep.js";
6
+ /**
7
+ * Copy a drive item, blocking and polling for completion.
8
+ *
9
+ * @param srcFileRef - A reference to the source file to be copied.
10
+ * @param dstFilePath - Destination file path
11
+ * @param timeoutMs - Timeout in milliseconds for the copy operation.
12
+ * @returns
13
+ */
14
+ export default async function copyDriveItem(srcFileRef, dstDriveRef, dstFilePath, timeoutMs = 16000) {
15
+ const { folderPath, fileName } = splitDriveItemPath(dstFilePath);
16
+ const dstFolder = folderPath === "/" ? dstDriveRef : await getDriveItemByPath(dstDriveRef, folderPath);
17
+ await initiateCopyDriveItem(srcFileRef, dstFolder, fileName);
18
+ const start = Date.now();
19
+ let delay = 1000;
20
+ while (true) {
21
+ try {
22
+ return await getDriveItemByPath(dstDriveRef, dstFilePath);
23
+ }
24
+ catch (_) {
25
+ const elapsedTime = Date.now() - start;
26
+ if (elapsedTime + delay > timeoutMs) {
27
+ throw new TimeoutError(`Timeout while copying ${srcFileRef.itemId} to ${dstFilePath}`);
28
+ }
29
+ await sleep(delay);
30
+ delay = Math.min(delay * 2, timeoutMs - (Date.now() - start)); // Double the delay but don't exceed remaining time
31
+ }
32
+ }
33
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "microsoft-graph",
3
- "version": "2.11.3",
3
+ "version": "2.12.0",
4
4
  "description": "Microsoft GraphAPI SDK for NodeJS",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -97,6 +97,11 @@
97
97
  "require": "./dist/cjs/errors/RequestFailedError.js",
98
98
  "types": "./dist/esm/errors/RequestFailedError.d.ts"
99
99
  },
100
+ "./errors/TimeoutError": {
101
+ "import": "./dist/esm/errors/TimeoutError.js",
102
+ "require": "./dist/cjs/errors/TimeoutError.js",
103
+ "types": "./dist/esm/errors/TimeoutError.d.ts"
104
+ },
100
105
  "./errors/UnsupportedAddressTypeError": {
101
106
  "import": "./dist/esm/errors/UnsupportedAddressTypeError.js",
102
107
  "require": "./dist/cjs/errors/UnsupportedAddressTypeError.js",
@@ -692,6 +697,11 @@
692
697
  "require": "./dist/cjs/services/workbookWorksheet.js",
693
698
  "types": "./dist/esm/services/workbookWorksheet.d.ts"
694
699
  },
700
+ "./tasks/copyDriveItem": {
701
+ "import": "./dist/esm/tasks/copyDriveItem.js",
702
+ "require": "./dist/cjs/tasks/copyDriveItem.js",
703
+ "types": "./dist/esm/tasks/copyDriveItem.d.ts"
704
+ },
695
705
  "./tasks/createWorkbookAndStartSession": {
696
706
  "import": "./dist/esm/tasks/createWorkbookAndStartSession.js",
697
707
  "require": "./dist/cjs/tasks/createWorkbookAndStartSession.js",
@@ -807,6 +817,11 @@
807
817
  "import": "./dist/esm/errors/RequestFailedError.js",
808
818
  "types": "./dist/esm/errors/RequestFailedError.d.ts"
809
819
  },
820
+ "./dist/cjs/errors/TimeoutError.js": {
821
+ "require": "./dist/cjs/errors/TimeoutError.js",
822
+ "import": "./dist/esm/errors/TimeoutError.js",
823
+ "types": "./dist/esm/errors/TimeoutError.d.ts"
824
+ },
810
825
  "./dist/cjs/errors/UnsupportedAddressTypeError.js": {
811
826
  "require": "./dist/cjs/errors/UnsupportedAddressTypeError.js",
812
827
  "import": "./dist/esm/errors/UnsupportedAddressTypeError.js",
@@ -1402,6 +1417,11 @@
1402
1417
  "import": "./dist/esm/services/workbookWorksheet.js",
1403
1418
  "types": "./dist/esm/services/workbookWorksheet.d.ts"
1404
1419
  },
1420
+ "./dist/cjs/tasks/copyDriveItem.js": {
1421
+ "require": "./dist/cjs/tasks/copyDriveItem.js",
1422
+ "import": "./dist/esm/tasks/copyDriveItem.js",
1423
+ "types": "./dist/esm/tasks/copyDriveItem.d.ts"
1424
+ },
1405
1425
  "./dist/cjs/tasks/createWorkbookAndStartSession.js": {
1406
1426
  "require": "./dist/cjs/tasks/createWorkbookAndStartSession.js",
1407
1427
  "import": "./dist/esm/tasks/createWorkbookAndStartSession.js",