microsoft-graph 2.11.3 → 2.13.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.
- package/biome.jsonc +1 -1
- package/dist/cjs/errors/TimeoutError.d.ts +4 -0
- package/dist/cjs/errors/TimeoutError.d.ts.map +1 -0
- package/dist/cjs/errors/TimeoutError.js +9 -0
- package/dist/cjs/graphApi.js +7 -8
- package/dist/cjs/operations/driveItem/initiateCopyDriveItem.d.ts +3 -2
- package/dist/cjs/operations/driveItem/initiateCopyDriveItem.d.ts.map +1 -1
- package/dist/cjs/operations/driveItem/initiateCopyDriveItem.js +2 -2
- package/dist/cjs/operations/driveItem/moveDriveItem.d.ts +14 -0
- package/dist/cjs/operations/driveItem/moveDriveItem.d.ts.map +1 -0
- package/dist/cjs/operations/driveItem/moveDriveItem.js +33 -0
- package/dist/cjs/services/driveItem.d.ts +9 -0
- package/dist/cjs/services/driveItem.d.ts.map +1 -1
- package/dist/cjs/services/driveItem.js +18 -0
- package/dist/cjs/tasks/copyDriveItem.d.ts +14 -0
- package/dist/cjs/tasks/copyDriveItem.d.ts.map +1 -0
- package/dist/cjs/tasks/copyDriveItem.js +39 -0
- package/dist/esm/errors/TimeoutError.d.ts +4 -0
- package/dist/esm/errors/TimeoutError.d.ts.map +1 -0
- package/dist/esm/errors/TimeoutError.js +6 -0
- package/dist/esm/graphApi.js +7 -8
- package/dist/esm/operations/driveItem/initiateCopyDriveItem.d.ts +3 -2
- package/dist/esm/operations/driveItem/initiateCopyDriveItem.d.ts.map +1 -1
- package/dist/esm/operations/driveItem/initiateCopyDriveItem.js +2 -2
- package/dist/esm/operations/driveItem/moveDriveItem.d.ts +14 -0
- package/dist/esm/operations/driveItem/moveDriveItem.d.ts.map +1 -0
- package/dist/esm/operations/driveItem/moveDriveItem.js +30 -0
- package/dist/esm/services/driveItem.d.ts +9 -0
- package/dist/esm/services/driveItem.d.ts.map +1 -1
- package/dist/esm/services/driveItem.js +17 -0
- package/dist/esm/tasks/copyDriveItem.d.ts +14 -0
- package/dist/esm/tasks/copyDriveItem.d.ts.map +1 -0
- package/dist/esm/tasks/copyDriveItem.js +33 -0
- package/package.json +898 -143
- package/update-exports.ts +82 -93
- package/vitest.config.ts +17 -17
package/biome.jsonc
CHANGED
|
@@ -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"}
|
package/dist/cjs/graphApi.js
CHANGED
|
@@ -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
|
|
131
|
-
while (
|
|
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;
|
|
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;
|
|
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
|
-
|
|
152
|
-
if (
|
|
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,
|
|
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,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DriveItemRef } from "../../models/DriveItemRef.ts";
|
|
2
|
+
import type { DriveRef } from "../../models/DriveRef.ts";
|
|
3
|
+
import type { GraphOperation } from "../../models/GraphOperation.ts";
|
|
4
|
+
/**
|
|
5
|
+
* Moves a file to a new location in the same drive.
|
|
6
|
+
*
|
|
7
|
+
* @param srcFileRef - A reference to the source file to be copied.
|
|
8
|
+
* @param dstFolderRef - A reference to the destination folder or site (if targeting root).
|
|
9
|
+
* @param dstFileName - The name of the copied file.
|
|
10
|
+
* @returns new DriveItemRef.
|
|
11
|
+
* @see https://learn.microsoft.com/en-us/graph/api/driveitem-move
|
|
12
|
+
*/
|
|
13
|
+
export default function moveDriveItem(srcFileRef: DriveItemRef, dstFolderRef: DriveRef | DriveItemRef, dstFileName: string): GraphOperation<void>;
|
|
14
|
+
//# sourceMappingURL=moveDriveItem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"moveDriveItem.d.ts","sourceRoot":"","sources":["../../../../src/operations/driveItem/moveDriveItem.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,aAAa,CAAC,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,GAAG,YAAY,EAAE,WAAW,EAAE,MAAM,GAAG,cAAc,CAAC,IAAI,CAAC,CAkBhJ"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = moveDriveItem;
|
|
4
|
+
const graphApi_ts_1 = require("../../graphApi.js");
|
|
5
|
+
const templatedPaths_ts_1 = require("../../services/templatedPaths.js");
|
|
6
|
+
/**
|
|
7
|
+
* Moves a file to a new location in the same drive.
|
|
8
|
+
*
|
|
9
|
+
* @param srcFileRef - A reference to the source file to be copied.
|
|
10
|
+
* @param dstFolderRef - A reference to the destination folder or site (if targeting root).
|
|
11
|
+
* @param dstFileName - The name of the copied file.
|
|
12
|
+
* @returns new DriveItemRef.
|
|
13
|
+
* @see https://learn.microsoft.com/en-us/graph/api/driveitem-move
|
|
14
|
+
*/
|
|
15
|
+
function moveDriveItem(srcFileRef, dstFolderRef, dstFileName) {
|
|
16
|
+
return (0, graphApi_ts_1.operation)({
|
|
17
|
+
contextId: srcFileRef.contextId,
|
|
18
|
+
method: "PATCH",
|
|
19
|
+
path: (0, templatedPaths_ts_1.generatePath)("/sites/{site-id}/drives/{drive-id}/items/{item-id}", srcFileRef),
|
|
20
|
+
headers: {
|
|
21
|
+
"content-type": "application/json",
|
|
22
|
+
},
|
|
23
|
+
body: {
|
|
24
|
+
name: dstFileName,
|
|
25
|
+
parentReference: {
|
|
26
|
+
siteId: dstFolderRef.siteId,
|
|
27
|
+
driveId: dstFolderRef.driveId,
|
|
28
|
+
id: "itemId" in dstFolderRef ? dstFolderRef.itemId : "root",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
responseTransform: () => undefined,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
@@ -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 @@
|
|
|
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"}
|
package/dist/esm/graphApi.js
CHANGED
|
@@ -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
|
|
122
|
-
while (
|
|
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;
|
|
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;
|
|
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
|
-
|
|
143
|
-
if (
|
|
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,
|
|
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,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DriveItemRef } from "../../models/DriveItemRef.ts";
|
|
2
|
+
import type { DriveRef } from "../../models/DriveRef.ts";
|
|
3
|
+
import type { GraphOperation } from "../../models/GraphOperation.ts";
|
|
4
|
+
/**
|
|
5
|
+
* Moves a file to a new location in the same drive.
|
|
6
|
+
*
|
|
7
|
+
* @param srcFileRef - A reference to the source file to be copied.
|
|
8
|
+
* @param dstFolderRef - A reference to the destination folder or site (if targeting root).
|
|
9
|
+
* @param dstFileName - The name of the copied file.
|
|
10
|
+
* @returns new DriveItemRef.
|
|
11
|
+
* @see https://learn.microsoft.com/en-us/graph/api/driveitem-move
|
|
12
|
+
*/
|
|
13
|
+
export default function moveDriveItem(srcFileRef: DriveItemRef, dstFolderRef: DriveRef | DriveItemRef, dstFileName: string): GraphOperation<void>;
|
|
14
|
+
//# sourceMappingURL=moveDriveItem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"moveDriveItem.d.ts","sourceRoot":"","sources":["../../../../src/operations/driveItem/moveDriveItem.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,aAAa,CAAC,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,GAAG,YAAY,EAAE,WAAW,EAAE,MAAM,GAAG,cAAc,CAAC,IAAI,CAAC,CAkBhJ"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { operation } from "../../graphApi.js";
|
|
2
|
+
import { generatePath } from "../../services/templatedPaths.js";
|
|
3
|
+
/**
|
|
4
|
+
* Moves a file to a new location in the same drive.
|
|
5
|
+
*
|
|
6
|
+
* @param srcFileRef - A reference to the source file to be copied.
|
|
7
|
+
* @param dstFolderRef - A reference to the destination folder or site (if targeting root).
|
|
8
|
+
* @param dstFileName - The name of the copied file.
|
|
9
|
+
* @returns new DriveItemRef.
|
|
10
|
+
* @see https://learn.microsoft.com/en-us/graph/api/driveitem-move
|
|
11
|
+
*/
|
|
12
|
+
export default function moveDriveItem(srcFileRef, dstFolderRef, dstFileName) {
|
|
13
|
+
return operation({
|
|
14
|
+
contextId: srcFileRef.contextId,
|
|
15
|
+
method: "PATCH",
|
|
16
|
+
path: generatePath("/sites/{site-id}/drives/{drive-id}/items/{item-id}", srcFileRef),
|
|
17
|
+
headers: {
|
|
18
|
+
"content-type": "application/json",
|
|
19
|
+
},
|
|
20
|
+
body: {
|
|
21
|
+
name: dstFileName,
|
|
22
|
+
parentReference: {
|
|
23
|
+
siteId: dstFolderRef.siteId,
|
|
24
|
+
driveId: dstFolderRef.driveId,
|
|
25
|
+
id: "itemId" in dstFolderRef ? dstFolderRef.itemId : "root",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
responseTransform: () => undefined,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -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
|
+
}
|