microsoft-graph 3.1.1 → 3.2.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/SECURITY.md CHANGED
@@ -6,4 +6,4 @@ Only the latest version is supported.
6
6
 
7
7
  ## Reporting a Vulnerability
8
8
 
9
- To report a vunerability raise a [GitHub Issue](https://github.com/Future-Secure-AI/microsoft-graph/issues).
9
+ To report a vulnerability raise a [GitHub Issue](https://github.com/Future-Secure-AI/microsoft-graph/issues).
@@ -16,4 +16,10 @@ export type DriveId = string & {
16
16
  export type DriveRef = SiteRef & {
17
17
  driveId: DriveId;
18
18
  };
19
+ /**
20
+ * Name of a drive.
21
+ */
22
+ export type DriveName = string & {
23
+ __brand: "DriveName";
24
+ };
19
25
  //# sourceMappingURL=Drive.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Drive.d.ts","sourceRoot":"","sources":["../../../src/models/Drive.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG;IAC9B,OAAO,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG;IAChC,OAAO,EAAE,OAAO,CAAC;CACjB,CAAC"}
1
+ {"version":3,"file":"Drive.d.ts","sourceRoot":"","sources":["../../../src/models/Drive.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG;IAC9B,OAAO,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG;IAChC,OAAO,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG;IAChC,OAAO,EAAE,WAAW,CAAC;CACrB,CAAC"}
@@ -3,18 +3,21 @@
3
3
  * @module sharepointUrl
4
4
  * @category Services
5
5
  */
6
+ import type { DriveName } from "../models/Drive.ts";
6
7
  import type { DriveItemId } from "../models/DriveItem.ts";
7
8
  import type { HostName } from "../models/HostName.ts";
8
9
  import type { SiteName } from "../models/Site.ts";
10
+ export type SharepointUrlComponents = {
11
+ hostName: HostName | null;
12
+ siteName: SiteName | null;
13
+ driveName: DriveName | null;
14
+ itemId: DriveItemId | null;
15
+ };
9
16
  /**
10
- * Parses a SharePoint document URL to extract the site name, host name, and item ID.
11
- * @param url - The SharePoint document URL.
12
- * @returns An object containing the host name, site name, and item ID.
17
+ * Parses a SharePoint document URL string to extract the site name, host name, drive name and item ID if present.
18
+ * @param urlString SharePoint URL as a string.
19
+ * @returns An object containing the host name, site name, drive name (if present), and item ID (if present).
13
20
  * @throws InvalidArgumentError if the URL is invalid or required components are missing.
14
21
  */
15
- export declare function parseSharepointUrl(url: URL): {
16
- hostName: HostName;
17
- siteName: SiteName;
18
- itemId: DriveItemId;
19
- };
22
+ export declare function parseSharepointUrl(urlString: string): SharepointUrlComponents;
20
23
  //# sourceMappingURL=sharepointUrl.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sharepointUrl.d.ts","sourceRoot":"","sources":["../../../src/services/sharepointUrl.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,GAAG,GAAG;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,WAAW,CAAA;CAAE,CAyB5G"}
1
+ {"version":3,"file":"sharepointUrl.d.ts","sourceRoot":"","sources":["../../../src/services/sharepointUrl.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElD,MAAM,MAAM,uBAAuB,GAAG;IACrC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC1B,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC1B,SAAS,EAAE,SAAS,GAAG,IAAI,CAAC;IAC5B,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;CAC3B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,uBAAuB,CAiD7E"}
@@ -4,37 +4,57 @@
4
4
  * @module sharepointUrl
5
5
  * @category Services
6
6
  */
7
- var __importDefault = (this && this.__importDefault) || function (mod) {
8
- return (mod && mod.__esModule) ? mod : { "default": mod };
9
- };
10
7
  Object.defineProperty(exports, "__esModule", { value: true });
11
8
  exports.parseSharepointUrl = parseSharepointUrl;
12
- const InvalidArgumentError_ts_1 = __importDefault(require("../errors/InvalidArgumentError.js"));
13
9
  /**
14
- * Parses a SharePoint document URL to extract the site name, host name, and item ID.
15
- * @param url - The SharePoint document URL.
16
- * @returns An object containing the host name, site name, and item ID.
10
+ * Parses a SharePoint document URL string to extract the site name, host name, drive name and item ID if present.
11
+ * @param urlString SharePoint URL as a string.
12
+ * @returns An object containing the host name, site name, drive name (if present), and item ID (if present).
17
13
  * @throws InvalidArgumentError if the URL is invalid or required components are missing.
18
14
  */
19
- function parseSharepointUrl(url) {
15
+ function parseSharepointUrl(urlString) {
16
+ let url;
17
+ let hostName = null;
18
+ let siteName = null;
19
+ let driveName = null;
20
+ let itemId = null;
21
+ try {
22
+ url = new URL(urlString);
23
+ }
24
+ catch {
25
+ return {
26
+ hostName: null,
27
+ siteName: null,
28
+ driveName: null,
29
+ itemId: null,
30
+ };
31
+ }
20
32
  if (!url.hostname.endsWith(".sharepoint.com")) {
21
- throw new InvalidArgumentError_ts_1.default("Invalid SharePoint URL. Hostname must end with '.sharepoint.com'.");
33
+ return {
34
+ hostName: null,
35
+ siteName: null,
36
+ driveName: null,
37
+ itemId: null,
38
+ };
22
39
  }
23
- const hostName = url.hostname;
24
- const pathSegments = url.pathname.split("/");
25
- const siteNameIndex = pathSegments.indexOf("sites") + 1;
26
- if (siteNameIndex <= 0 || !pathSegments[siteNameIndex]) {
27
- throw new InvalidArgumentError_ts_1.default("Invalid SharePoint URL. Site name not found.");
40
+ hostName = url.hostname;
41
+ const pathSegments = url.pathname.split("/").filter(Boolean);
42
+ const sitesIdx = pathSegments.findIndex((seg) => seg.toLowerCase() === "sites");
43
+ if (sitesIdx !== -1 && pathSegments[sitesIdx + 1]) {
44
+ siteName = pathSegments[sitesIdx + 1];
45
+ const afterSite = pathSegments[sitesIdx + 2];
46
+ if (afterSite && afterSite.toLowerCase() !== "_layouts" && afterSite.toLowerCase() !== "forms") {
47
+ driveName = afterSite;
48
+ }
28
49
  }
29
- const siteName = pathSegments[siteNameIndex];
30
50
  const sourcedoc = url.searchParams.get("sourcedoc");
31
- if (!sourcedoc) {
32
- throw new InvalidArgumentError_ts_1.default("Invalid SharePoint URL. Path not found in parameters.");
51
+ if (sourcedoc) {
52
+ itemId = decodeURIComponent(sourcedoc.replace(/[{}]/g, "")).toUpperCase();
33
53
  }
34
- const itemId = sourcedoc.replace(/[{}]/g, "").toLocaleUpperCase();
35
54
  return {
36
55
  hostName,
37
56
  siteName,
57
+ driveName,
38
58
  itemId,
39
59
  };
40
60
  }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Retrieves a Drive from a SharePoint URL.
3
+ * @module getDriveFromUrl
4
+ * @category Tasks
5
+ */
6
+ import type { Drive } from "@microsoft/microsoft-graph-types";
7
+ import type { ContextRef } from "../models/Context.ts";
8
+ import type { DriveRef } from "../models/Drive.ts";
9
+ /**
10
+ * Retrieves a Drive from a SharePoint URL.
11
+ *
12
+ * Parses the given SharePoint URL to extract the host, site, and drive names, then locates and returns the corresponding Drive object.
13
+ *
14
+ * @param contextRef - The context reference containing authentication and environment information.
15
+ * @param url - The SharePoint URL pointing to the drive.
16
+ * @returns A Promise that resolves to the Drive object with additional DriveRef properties.
17
+ * @throws If the URL is invalid or the drive cannot be found.
18
+ */
19
+ export default function getDriveFromUrl(contextRef: ContextRef, url: string): Promise<Drive & DriveRef>;
20
+ //# sourceMappingURL=getDriveFromUrl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getDriveFromUrl.d.ts","sourceRoot":"","sources":["../../../src/tasks/getDriveFromUrl.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kCAAkC,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAKnD;;;;;;;;;GASG;AACH,wBAA8B,eAAe,CAAC,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC,CA2B5G"}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ /**
3
+ * Retrieves a Drive from a SharePoint URL.
4
+ * @module getDriveFromUrl
5
+ * @category Tasks
6
+ */
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.default = getDriveFromUrl;
12
+ const getSiteByName_ts_1 = __importDefault(require("../operations/site/getSiteByName.js"));
13
+ const sharepointUrl_ts_1 = require("../services/sharepointUrl.js");
14
+ const iterateDrives_ts_1 = __importDefault(require("./iterateDrives.js"));
15
+ /**
16
+ * Retrieves a Drive from a SharePoint URL.
17
+ *
18
+ * Parses the given SharePoint URL to extract the host, site, and drive names, then locates and returns the corresponding Drive object.
19
+ *
20
+ * @param contextRef - The context reference containing authentication and environment information.
21
+ * @param url - The SharePoint URL pointing to the drive.
22
+ * @returns A Promise that resolves to the Drive object with additional DriveRef properties.
23
+ * @throws If the URL is invalid or the drive cannot be found.
24
+ */
25
+ async function getDriveFromUrl(contextRef, url) {
26
+ const { hostName, siteName, driveName } = (0, sharepointUrl_ts_1.parseSharepointUrl)(url);
27
+ if (!hostName) {
28
+ throw new Error("Invalid SharePoint URL: Host name is missing.");
29
+ }
30
+ if (!siteName) {
31
+ throw new Error("Invalid SharePoint URL: Site name is missing.");
32
+ }
33
+ if (!driveName) {
34
+ throw new Error("Invalid SharePoint URL: Drive name is missing.");
35
+ }
36
+ const site = await (0, getSiteByName_ts_1.default)(contextRef, hostName, siteName);
37
+ let drive = null;
38
+ for await (const d of (0, iterateDrives_ts_1.default)(site)) {
39
+ if (sanitizeUrlName(d.name ?? "") === driveName) {
40
+ drive = d;
41
+ }
42
+ }
43
+ if (!drive) {
44
+ throw new Error(`Drive "${driveName}" not found in site "${siteName}" on host "${hostName}".`);
45
+ }
46
+ return drive;
47
+ }
48
+ function sanitizeUrlName(name) {
49
+ return name.replace(/[^A-Za-z0-9\-_.~]/g, "");
50
+ }
@@ -16,4 +16,10 @@ export type DriveId = string & {
16
16
  export type DriveRef = SiteRef & {
17
17
  driveId: DriveId;
18
18
  };
19
+ /**
20
+ * Name of a drive.
21
+ */
22
+ export type DriveName = string & {
23
+ __brand: "DriveName";
24
+ };
19
25
  //# sourceMappingURL=Drive.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Drive.d.ts","sourceRoot":"","sources":["../../../src/models/Drive.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG;IAC9B,OAAO,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG;IAChC,OAAO,EAAE,OAAO,CAAC;CACjB,CAAC"}
1
+ {"version":3,"file":"Drive.d.ts","sourceRoot":"","sources":["../../../src/models/Drive.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG;IAC9B,OAAO,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG;IAChC,OAAO,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG;IAChC,OAAO,EAAE,WAAW,CAAC;CACrB,CAAC"}
@@ -3,18 +3,21 @@
3
3
  * @module sharepointUrl
4
4
  * @category Services
5
5
  */
6
+ import type { DriveName } from "../models/Drive.ts";
6
7
  import type { DriveItemId } from "../models/DriveItem.ts";
7
8
  import type { HostName } from "../models/HostName.ts";
8
9
  import type { SiteName } from "../models/Site.ts";
10
+ export type SharepointUrlComponents = {
11
+ hostName: HostName | null;
12
+ siteName: SiteName | null;
13
+ driveName: DriveName | null;
14
+ itemId: DriveItemId | null;
15
+ };
9
16
  /**
10
- * Parses a SharePoint document URL to extract the site name, host name, and item ID.
11
- * @param url - The SharePoint document URL.
12
- * @returns An object containing the host name, site name, and item ID.
17
+ * Parses a SharePoint document URL string to extract the site name, host name, drive name and item ID if present.
18
+ * @param urlString SharePoint URL as a string.
19
+ * @returns An object containing the host name, site name, drive name (if present), and item ID (if present).
13
20
  * @throws InvalidArgumentError if the URL is invalid or required components are missing.
14
21
  */
15
- export declare function parseSharepointUrl(url: URL): {
16
- hostName: HostName;
17
- siteName: SiteName;
18
- itemId: DriveItemId;
19
- };
22
+ export declare function parseSharepointUrl(urlString: string): SharepointUrlComponents;
20
23
  //# sourceMappingURL=sharepointUrl.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sharepointUrl.d.ts","sourceRoot":"","sources":["../../../src/services/sharepointUrl.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,GAAG,GAAG;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,WAAW,CAAA;CAAE,CAyB5G"}
1
+ {"version":3,"file":"sharepointUrl.d.ts","sourceRoot":"","sources":["../../../src/services/sharepointUrl.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElD,MAAM,MAAM,uBAAuB,GAAG;IACrC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC1B,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC1B,SAAS,EAAE,SAAS,GAAG,IAAI,CAAC;IAC5B,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;CAC3B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,uBAAuB,CAiD7E"}
@@ -3,32 +3,55 @@
3
3
  * @module sharepointUrl
4
4
  * @category Services
5
5
  */
6
- import InvalidArgumentError from "../errors/InvalidArgumentError.js";
7
6
  /**
8
- * Parses a SharePoint document URL to extract the site name, host name, and item ID.
9
- * @param url - The SharePoint document URL.
10
- * @returns An object containing the host name, site name, and item ID.
7
+ * Parses a SharePoint document URL string to extract the site name, host name, drive name and item ID if present.
8
+ * @param urlString SharePoint URL as a string.
9
+ * @returns An object containing the host name, site name, drive name (if present), and item ID (if present).
11
10
  * @throws InvalidArgumentError if the URL is invalid or required components are missing.
12
11
  */
13
- export function parseSharepointUrl(url) {
12
+ export function parseSharepointUrl(urlString) {
13
+ let url;
14
+ let hostName = null;
15
+ let siteName = null;
16
+ let driveName = null;
17
+ let itemId = null;
18
+ try {
19
+ url = new URL(urlString);
20
+ }
21
+ catch {
22
+ return {
23
+ hostName: null,
24
+ siteName: null,
25
+ driveName: null,
26
+ itemId: null,
27
+ };
28
+ }
14
29
  if (!url.hostname.endsWith(".sharepoint.com")) {
15
- throw new InvalidArgumentError("Invalid SharePoint URL. Hostname must end with '.sharepoint.com'.");
30
+ return {
31
+ hostName: null,
32
+ siteName: null,
33
+ driveName: null,
34
+ itemId: null,
35
+ };
16
36
  }
17
- const hostName = url.hostname;
18
- const pathSegments = url.pathname.split("/");
19
- const siteNameIndex = pathSegments.indexOf("sites") + 1;
20
- if (siteNameIndex <= 0 || !pathSegments[siteNameIndex]) {
21
- throw new InvalidArgumentError("Invalid SharePoint URL. Site name not found.");
37
+ hostName = url.hostname;
38
+ const pathSegments = url.pathname.split("/").filter(Boolean);
39
+ const sitesIdx = pathSegments.findIndex((seg) => seg.toLowerCase() === "sites");
40
+ if (sitesIdx !== -1 && pathSegments[sitesIdx + 1]) {
41
+ siteName = pathSegments[sitesIdx + 1];
42
+ const afterSite = pathSegments[sitesIdx + 2];
43
+ if (afterSite && afterSite.toLowerCase() !== "_layouts" && afterSite.toLowerCase() !== "forms") {
44
+ driveName = afterSite;
45
+ }
22
46
  }
23
- const siteName = pathSegments[siteNameIndex];
24
47
  const sourcedoc = url.searchParams.get("sourcedoc");
25
- if (!sourcedoc) {
26
- throw new InvalidArgumentError("Invalid SharePoint URL. Path not found in parameters.");
48
+ if (sourcedoc) {
49
+ itemId = decodeURIComponent(sourcedoc.replace(/[{}]/g, "")).toUpperCase();
27
50
  }
28
- const itemId = sourcedoc.replace(/[{}]/g, "").toLocaleUpperCase();
29
51
  return {
30
52
  hostName,
31
53
  siteName,
54
+ driveName,
32
55
  itemId,
33
56
  };
34
57
  }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Retrieves a Drive from a SharePoint URL.
3
+ * @module getDriveFromUrl
4
+ * @category Tasks
5
+ */
6
+ import type { Drive } from "@microsoft/microsoft-graph-types";
7
+ import type { ContextRef } from "../models/Context.ts";
8
+ import type { DriveRef } from "../models/Drive.ts";
9
+ /**
10
+ * Retrieves a Drive from a SharePoint URL.
11
+ *
12
+ * Parses the given SharePoint URL to extract the host, site, and drive names, then locates and returns the corresponding Drive object.
13
+ *
14
+ * @param contextRef - The context reference containing authentication and environment information.
15
+ * @param url - The SharePoint URL pointing to the drive.
16
+ * @returns A Promise that resolves to the Drive object with additional DriveRef properties.
17
+ * @throws If the URL is invalid or the drive cannot be found.
18
+ */
19
+ export default function getDriveFromUrl(contextRef: ContextRef, url: string): Promise<Drive & DriveRef>;
20
+ //# sourceMappingURL=getDriveFromUrl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getDriveFromUrl.d.ts","sourceRoot":"","sources":["../../../src/tasks/getDriveFromUrl.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kCAAkC,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAKnD;;;;;;;;;GASG;AACH,wBAA8B,eAAe,CAAC,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC,CA2B5G"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Retrieves a Drive from a SharePoint URL.
3
+ * @module getDriveFromUrl
4
+ * @category Tasks
5
+ */
6
+ import getSiteByName from "../operations/site/getSiteByName.js";
7
+ import { parseSharepointUrl } from "../services/sharepointUrl.js";
8
+ import iterateDrives from "./iterateDrives.js";
9
+ /**
10
+ * Retrieves a Drive from a SharePoint URL.
11
+ *
12
+ * Parses the given SharePoint URL to extract the host, site, and drive names, then locates and returns the corresponding Drive object.
13
+ *
14
+ * @param contextRef - The context reference containing authentication and environment information.
15
+ * @param url - The SharePoint URL pointing to the drive.
16
+ * @returns A Promise that resolves to the Drive object with additional DriveRef properties.
17
+ * @throws If the URL is invalid or the drive cannot be found.
18
+ */
19
+ export default async function getDriveFromUrl(contextRef, url) {
20
+ const { hostName, siteName, driveName } = parseSharepointUrl(url);
21
+ if (!hostName) {
22
+ throw new Error("Invalid SharePoint URL: Host name is missing.");
23
+ }
24
+ if (!siteName) {
25
+ throw new Error("Invalid SharePoint URL: Site name is missing.");
26
+ }
27
+ if (!driveName) {
28
+ throw new Error("Invalid SharePoint URL: Drive name is missing.");
29
+ }
30
+ const site = await getSiteByName(contextRef, hostName, siteName);
31
+ let drive = null;
32
+ for await (const d of iterateDrives(site)) {
33
+ if (sanitizeUrlName(d.name ?? "") === driveName) {
34
+ drive = d;
35
+ }
36
+ }
37
+ if (!drive) {
38
+ throw new Error(`Drive "${driveName}" not found in site "${siteName}" on host "${hostName}".`);
39
+ }
40
+ return drive;
41
+ }
42
+ function sanitizeUrlName(name) {
43
+ return name.replace(/[^A-Za-z0-9\-_.~]/g, "");
44
+ }
@@ -22,6 +22,22 @@ Identifier for a drive.
22
22
 
23
23
  ***
24
24
 
25
+ ### DriveName
26
+
27
+ > **DriveName** = `string` & `object`
28
+
29
+ Defined in: [src/models/Drive.ts:28](https://github.com/Future-Secure-AI/microsoft-graph/blob/main/src/models/Drive.ts#L28)
30
+
31
+ Name of a drive.
32
+
33
+ #### Type declaration
34
+
35
+ ##### \_\_brand
36
+
37
+ > **\_\_brand**: `"DriveName"`
38
+
39
+ ***
40
+
25
41
  ### DriveRef
26
42
 
27
43
  > **DriveRef** = [`SiteRef`](Site-1.md#siteref) & `object`
@@ -180,6 +180,7 @@
180
180
  | [copyDriveItem](copyDriveItem.md) | Copy a drive item. |
181
181
  | [createWorkbookAndStartSession](createWorkbookAndStartSession.md) | Create a new workbook and open a session for that workbook. |
182
182
  | [downloadDriveItemContent](downloadDriveItemContent.md) | Download a drive item and save it to the local disk. |
183
+ | [getDriveFromUrl](getDriveFromUrl.md) | Retrieves a Drive from a SharePoint URL. |
183
184
  | [insertWorkbookRangeRow](insertWorkbookRangeRow.md) | Inserts a single row into a workbook range. |
184
185
  | [insertWorkbookRangeRows](insertWorkbookRangeRows.md) | Inserts rows into a workbook range. |
185
186
  | [iterateDriveItems](iterateDriveItems.md) | List drive items in a drive or a drive item. |
@@ -0,0 +1,34 @@
1
+ [Microsoft Graph SDK](README.md) / getDriveFromUrl
2
+
3
+ # getDriveFromUrl
4
+
5
+ Retrieves a Drive from a SharePoint URL.
6
+
7
+ ## Functions
8
+
9
+ ### getDriveFromUrl()
10
+
11
+ > **getDriveFromUrl**(`contextRef`, `url`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`Drive` & [`SiteRef`](Site-1.md#siteref) & `object`\>
12
+
13
+ Defined in: [src/tasks/getDriveFromUrl.ts:24](https://github.com/Future-Secure-AI/microsoft-graph/blob/main/src/tasks/getDriveFromUrl.ts#L24)
14
+
15
+ Retrieves a Drive from a SharePoint URL.
16
+
17
+ Parses the given SharePoint URL to extract the host, site, and drive names, then locates and returns the corresponding Drive object.
18
+
19
+ #### Parameters
20
+
21
+ | Parameter | Type | Description |
22
+ | ------ | ------ | ------ |
23
+ | `contextRef` | [`ContextRef`](Context-1.md#contextref) | The context reference containing authentication and environment information. |
24
+ | `url` | `string` | The SharePoint URL pointing to the drive. |
25
+
26
+ #### Returns
27
+
28
+ [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`Drive` & [`SiteRef`](Site-1.md#siteref) & `object`\>
29
+
30
+ A Promise that resolves to the Drive object with additional DriveRef properties.
31
+
32
+ #### Throws
33
+
34
+ If the URL is invalid or the drive cannot be found.
@@ -4,39 +4,44 @@
4
4
 
5
5
  Utilities for parsing and extracting information from SharePoint URLs.
6
6
 
7
- ## Functions
8
-
9
- ### parseSharepointUrl()
7
+ ## Type Aliases
10
8
 
11
- > **parseSharepointUrl**(`url`): `object`
9
+ ### SharepointUrlComponents
12
10
 
13
- Defined in: [src/services/sharepointUrl.ts:18](https://github.com/Future-Secure-AI/microsoft-graph/blob/main/src/services/sharepointUrl.ts#L18)
11
+ > **SharepointUrlComponents** = `object`
14
12
 
15
- Parses a SharePoint document URL to extract the site name, host name, and item ID.
13
+ Defined in: [src/services/sharepointUrl.ts:12](https://github.com/Future-Secure-AI/microsoft-graph/blob/main/src/services/sharepointUrl.ts#L12)
16
14
 
17
- #### Parameters
15
+ #### Properties
18
16
 
19
- | Parameter | Type | Description |
17
+ | Property | Type | Defined in |
20
18
  | ------ | ------ | ------ |
21
- | `url` | [`URL`](https://developer.mozilla.org/docs/Web/API/URL) | The SharePoint document URL. |
19
+ | <a id="drivename"></a> `driveName` | [`DriveName`](Drive-1.md#drivename) \| `null` | [src/services/sharepointUrl.ts:15](https://github.com/Future-Secure-AI/microsoft-graph/blob/main/src/services/sharepointUrl.ts#L15) |
20
+ | <a id="hostname"></a> `hostName` | [`HostName`](HostName.md#hostname) \| `null` | [src/services/sharepointUrl.ts:13](https://github.com/Future-Secure-AI/microsoft-graph/blob/main/src/services/sharepointUrl.ts#L13) |
21
+ | <a id="itemid"></a> `itemId` | [`DriveItemId`](DriveItem-1.md#driveitemid) \| `null` | [src/services/sharepointUrl.ts:16](https://github.com/Future-Secure-AI/microsoft-graph/blob/main/src/services/sharepointUrl.ts#L16) |
22
+ | <a id="sitename"></a> `siteName` | [`SiteName`](Site-1.md#sitename) \| `null` | [src/services/sharepointUrl.ts:14](https://github.com/Future-Secure-AI/microsoft-graph/blob/main/src/services/sharepointUrl.ts#L14) |
22
23
 
23
- #### Returns
24
+ ## Functions
24
25
 
25
- `object`
26
+ ### parseSharepointUrl()
27
+
28
+ > **parseSharepointUrl**(`urlString`): [`SharepointUrlComponents`](#sharepointurlcomponents)
26
29
 
27
- An object containing the host name, site name, and item ID.
30
+ Defined in: [src/services/sharepointUrl.ts:25](https://github.com/Future-Secure-AI/microsoft-graph/blob/main/src/services/sharepointUrl.ts#L25)
28
31
 
29
- ##### hostName
32
+ Parses a SharePoint document URL string to extract the site name, host name, drive name and item ID if present.
30
33
 
31
- > **hostName**: [`HostName`](HostName.md#hostname)
34
+ #### Parameters
32
35
 
33
- ##### itemId
36
+ | Parameter | Type | Description |
37
+ | ------ | ------ | ------ |
38
+ | `urlString` | `string` | SharePoint URL as a string. |
34
39
 
35
- > **itemId**: [`DriveItemId`](DriveItem-1.md#driveitemid)
40
+ #### Returns
36
41
 
37
- ##### siteName
42
+ [`SharepointUrlComponents`](#sharepointurlcomponents)
38
43
 
39
- > **siteName**: [`SiteName`](Site-1.md#sitename)
44
+ An object containing the host name, site name, drive name (if present), and item ID (if present).
40
45
 
41
46
  #### Throws
42
47
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "microsoft-graph",
3
- "version": "3.1.1",
3
+ "version": "3.2.0",
4
4
  "description": "Microsoft GraphAPI SDK for NodeJS",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -1649,6 +1649,16 @@
1649
1649
  "require": "./dist/cjs/tasks/downloadDriveItemContent.js",
1650
1650
  "types": "./dist/esm/tasks/downloadDriveItemContent.d.ts"
1651
1651
  },
1652
+ "./getDriveFromUrl": {
1653
+ "import": "./dist/esm/tasks/getDriveFromUrl.js",
1654
+ "require": "./dist/cjs/tasks/getDriveFromUrl.js",
1655
+ "types": "./dist/esm/tasks/getDriveFromUrl.d.ts"
1656
+ },
1657
+ "./dist/cjs/tasks/getDriveFromUrl": {
1658
+ "import": "./dist/esm/tasks/getDriveFromUrl.js",
1659
+ "require": "./dist/cjs/tasks/getDriveFromUrl.js",
1660
+ "types": "./dist/esm/tasks/getDriveFromUrl.d.ts"
1661
+ },
1652
1662
  "./getRangeLastUsedCell": {
1653
1663
  "import": "./dist/esm/tasks/getRangeLastUsedCell.js",
1654
1664
  "require": "./dist/cjs/tasks/getRangeLastUsedCell.js",