microsoft-graph 2.0.0 → 2.1.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/.vscode/settings.json +1 -0
- package/LICENCE.md +96 -325
- package/dist/docs/getItem.js +11 -0
- package/dist/microsoftGraph/errors/BadTemplateError.js +6 -0
- package/dist/microsoftGraph/errors/InvalidArgumentError.js +6 -0
- package/dist/microsoftGraph/errors/RequestFailedError.js +6 -0
- package/dist/microsoftGraph/graphApi.js +49 -0
- package/dist/microsoftGraph/helpers/openSite.js +12 -0
- package/dist/microsoftGraph/helpers/openWorkbook.js +23 -0
- package/dist/microsoftGraph/helpers/openWorksheet.js +7 -0
- package/dist/microsoftGraph/models/AccessToken.js +1 -0
- package/dist/microsoftGraph/models/DriveId.js +1 -0
- package/dist/microsoftGraph/models/DriveItemId.js +1 -0
- package/dist/microsoftGraph/models/DriveItemPath.js +1 -0
- package/dist/microsoftGraph/models/DriveItemRef.js +1 -0
- package/dist/microsoftGraph/models/DriveRef.js +1 -0
- package/dist/microsoftGraph/models/GraphOperation.js +1 -0
- package/dist/microsoftGraph/models/GraphOptions.js +1 -0
- package/dist/microsoftGraph/models/HostName.js +1 -0
- package/dist/microsoftGraph/models/Scope.js +1 -0
- package/dist/microsoftGraph/models/SiteId.js +1 -0
- package/dist/microsoftGraph/models/SiteName.js +1 -0
- package/dist/microsoftGraph/models/SiteRef.js +1 -0
- package/dist/microsoftGraph/models/WorkbookNamedRangeRef.js +1 -0
- package/dist/microsoftGraph/models/WorkbookRangeAddress.js +1 -0
- package/dist/microsoftGraph/models/WorkbookRangeName.js +1 -0
- package/dist/microsoftGraph/models/WorkbookRangeRef.js +1 -0
- package/dist/microsoftGraph/models/WorkbookRef.js +1 -0
- package/dist/microsoftGraph/models/WorkbookSessionId.js +1 -0
- package/dist/microsoftGraph/models/WorkbookWorksheetId.js +1 -0
- package/dist/microsoftGraph/models/WorkbookWorksheetRef.js +1 -0
- package/dist/microsoftGraph/models/regenerate-dtos.js +68 -0
- package/dist/microsoftGraph/operations/drive/createFolder.js +17 -0
- package/dist/microsoftGraph/operations/drive/listDrives.js +11 -0
- package/dist/microsoftGraph/operations/driveItem/copyDriveItem.js +20 -0
- package/dist/microsoftGraph/operations/driveItem/deleteDriveItem.js +11 -0
- package/dist/microsoftGraph/operations/driveItem/getDriveItem.js +11 -0
- package/dist/microsoftGraph/operations/driveItem/getDriveItemByPath.js +11 -0
- package/dist/microsoftGraph/operations/driveItem/listDriveItems.js +11 -0
- package/dist/microsoftGraph/operations/site/getSite.js +11 -0
- package/dist/microsoftGraph/operations/site/getSiteByName.js +11 -0
- package/dist/microsoftGraph/operations/site/listSites.js +11 -0
- package/dist/microsoftGraph/operations/site/searchSites.js +11 -0
- package/dist/microsoftGraph/operations/workbook/createWorkbook.js +14 -0
- package/dist/microsoftGraph/operations/workbook/deleteWorkbook.js +5 -0
- package/dist/microsoftGraph/operations/workbookRange/clearWorkbookRange.js +16 -0
- package/dist/microsoftGraph/operations/workbookRange/deleteWorkbookRange.js +16 -0
- package/dist/microsoftGraph/operations/workbookRange/getWorkbookNamedRange.js +13 -0
- package/dist/microsoftGraph/operations/workbookRange/getWorkbookRange.js +13 -0
- package/dist/microsoftGraph/operations/workbookRange/getWorkbookUsedRange.js +13 -0
- package/dist/microsoftGraph/operations/workbookRange/insertWorkbookCells.js +16 -0
- package/dist/microsoftGraph/operations/workbookRange/updateWorkbookNamedRange.js +14 -0
- package/dist/microsoftGraph/operations/workbookRange/updateWorkbookRange.js +14 -0
- package/dist/microsoftGraph/operations/workbookSession/closeWorkbookSession.js +17 -0
- package/dist/microsoftGraph/operations/workbookSession/createWorkbookSession.js +15 -0
- package/dist/microsoftGraph/operations/workbookSession/refreshWorkbookSession.js +18 -0
- package/dist/microsoftGraph/operations/workbookWorksheet/createWorkbookWorksheet.js +16 -0
- package/dist/microsoftGraph/operations/workbookWorksheet/deleteWorkbookWorksheet.js +13 -0
- package/dist/microsoftGraph/operations/workbookWorksheet/listWorkbookWorksheets.js +13 -0
- package/dist/microsoftGraph/operations/workbookWorksheet/updateWorkbookWorksheet.js +14 -0
- package/dist/microsoftGraph/services/accessToken.js +12 -0
- package/dist/microsoftGraph/services/configuration.js +20 -0
- package/dist/microsoftGraph/services/sharepointUrl.js +23 -0
- package/dist/microsoftGraph/services/stringCaseConversion.js +3 -0
- package/dist/microsoftGraph/services/templatedPaths.js +19 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +503 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// biome-ignore lint/correctness/noNodejsModules: Fit for purpose
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
// biome-ignore lint/correctness/noNodejsModules: Fit for purpose
|
|
4
|
+
import https from "node:https";
|
|
5
|
+
// biome-ignore lint/correctness/noNodejsModules: Fit for purpose
|
|
6
|
+
import { dirname } from "node:path";
|
|
7
|
+
// biome-ignore lint/correctness/noNodejsModules: Fit for purpose
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
const inputUrl = "https://raw.githubusercontent.com/microsoftgraph/msgraph-typescript-typings/refs/heads/main/microsoft-graph.d.ts";
|
|
10
|
+
const outputFilePath = `${dirname(fileURLToPath(import.meta.url))}/Dto.d.ts`;
|
|
11
|
+
async function downloadFile(url) {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
https.get(url, (res) => {
|
|
14
|
+
if (res.statusCode !== 200) {
|
|
15
|
+
reject(new Error(`Failed to download file: ${res.statusCode}`));
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
let data = "";
|
|
19
|
+
res.on("data", (chunk) => {
|
|
20
|
+
data += chunk;
|
|
21
|
+
});
|
|
22
|
+
res.on("end", () => resolve(data));
|
|
23
|
+
}).on("error", reject);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
async function writeFile(path, data) {
|
|
27
|
+
const payload = `/*\n * DO NOT MODIFY THIS FILE, it is programmatically generated.\n * Run \`npm run regenerate-dtos\` to regenerate.\n*/\n\n${data}`;
|
|
28
|
+
return await fs.writeFile(path, payload, "utf-8");
|
|
29
|
+
}
|
|
30
|
+
function fixWhiteSpace(data) {
|
|
31
|
+
return data.replace(/\u202F/g, " ");
|
|
32
|
+
}
|
|
33
|
+
function fixAnyDataType(data) {
|
|
34
|
+
return data
|
|
35
|
+
.replace(/: any\b/g, ": unknown")
|
|
36
|
+
.replace(/\<any\>/g, "<unknown>");
|
|
37
|
+
}
|
|
38
|
+
function fixLintDisables(data) {
|
|
39
|
+
return data
|
|
40
|
+
.replace(/\/\/ tslint:disable-next-line: [a-z- ]+\n/g, "");
|
|
41
|
+
}
|
|
42
|
+
function linkStronglyTypedIds(data) {
|
|
43
|
+
// biome-ignore lint/style/useTemplate: <explanation>
|
|
44
|
+
return `import type { DriveId } from './DriveId.ts'\n` +
|
|
45
|
+
`import type { DriveItemId } from './DriveItemId.ts'\n` +
|
|
46
|
+
`import type { SiteId } from './SiteId.ts';\n\n` +
|
|
47
|
+
data
|
|
48
|
+
.replace(/export interface Entity\s*{[^}]*id\?: string;/g, "export interface Entity<TId = string> {\n // The unique identifier for an entity. Read-only.\n id?: TId;")
|
|
49
|
+
.replace("export interface BaseItem extends Entity", "export interface BaseItem<TId = string> extends Entity<TId>")
|
|
50
|
+
.replace("export interface Site extends BaseItem", "export interface Site extends BaseItem<SiteId>")
|
|
51
|
+
.replace("export interface Drive extends BaseItem", "export interface Drive extends BaseItem<DriveId>")
|
|
52
|
+
.replace("export interface DriveItem extends BaseItem", "export interface DriveItem extends BaseItem<DriveItemId>")
|
|
53
|
+
.replace("export interface Workbook extends Entity", "export interface Workbook extends Entity<DriveItemId>");
|
|
54
|
+
}
|
|
55
|
+
function fixNamespaces(data) {
|
|
56
|
+
return data
|
|
57
|
+
.replace(/microsoftgraph\./g, "")
|
|
58
|
+
.replace(/Partners\.Billing\.Billing/g, "unknown"); // Workaround possible incorrect ordering. Not worth time to investigate
|
|
59
|
+
}
|
|
60
|
+
let data = await downloadFile(inputUrl);
|
|
61
|
+
data = fixWhiteSpace(data);
|
|
62
|
+
data = fixAnyDataType(data);
|
|
63
|
+
data = fixLintDisables(data);
|
|
64
|
+
data = fixNamespaces(data);
|
|
65
|
+
data = linkStronglyTypedIds(data);
|
|
66
|
+
await writeFile(outputFilePath, data);
|
|
67
|
+
// biome-ignore lint/suspicious/noConsoleLog: <explanation>
|
|
68
|
+
console.log(`File saved to ${outputFilePath}`);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { generatePath } from "../../services/templatedPaths.js";
|
|
2
|
+
/** Create folder if it doesn't exist, and return the folder. @see https://learn.microsoft.com/en-us/graph/api/driveitem-post-children */
|
|
3
|
+
export default function createFolder(driveRef, folderPath, opts) {
|
|
4
|
+
return {
|
|
5
|
+
method: "POST",
|
|
6
|
+
path: generatePath(`/sites/{site-id}/drives/{drive-id}/root:${folderPath}:/children`, driveRef),
|
|
7
|
+
headers: {
|
|
8
|
+
'content-type': 'application/json',
|
|
9
|
+
},
|
|
10
|
+
body: {
|
|
11
|
+
name: folderPath,
|
|
12
|
+
folder: {},
|
|
13
|
+
"@microsoft.graph.conflictBehavior": "rename", // Do nothing if already exists
|
|
14
|
+
},
|
|
15
|
+
dependsOn: opts?.dependsOn,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { generatePath } from "../../services/templatedPaths.js";
|
|
2
|
+
/** Retrieve the list of Drive resources available for a Site. @see https://learn.microsoft.com/en-us/graph/api/drive-list */
|
|
3
|
+
export default function listDrives(siteRef, opts) {
|
|
4
|
+
return {
|
|
5
|
+
method: "GET",
|
|
6
|
+
path: generatePath("/sites/{site-id}/drives", siteRef),
|
|
7
|
+
headers: {},
|
|
8
|
+
body: null,
|
|
9
|
+
dependsOn: opts?.dependsOn,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { generatePath } from "../../services/templatedPaths.js";
|
|
2
|
+
/** Initiate an asyncronous copy of an item. NOTE: The copied file may not be immediately available and polling is required. @see https://learn.microsoft.com/en-us/graph/api/driveitem-copy */
|
|
3
|
+
export default function copyDriveItem(srcFileRef, dstFolderRef, dstFileName, opts) {
|
|
4
|
+
return {
|
|
5
|
+
method: "POST",
|
|
6
|
+
path: generatePath("/sites/{site-id}/drives/{drive-id}/items/{item-id}/copy", srcFileRef),
|
|
7
|
+
headers: {
|
|
8
|
+
'content-type': 'application/json',
|
|
9
|
+
},
|
|
10
|
+
body: {
|
|
11
|
+
name: dstFileName,
|
|
12
|
+
parentReference: {
|
|
13
|
+
siteId: dstFolderRef.siteId,
|
|
14
|
+
driveId: dstFolderRef.driveId,
|
|
15
|
+
id: dstFolderRef.itemId,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
dependsOn: opts?.dependsOn,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { generatePath } from "../../services/templatedPaths.js";
|
|
2
|
+
/** Delete an item. @see https://learn.microsoft.com/en-us/graph/api/driveitem-delete */
|
|
3
|
+
export default function deleteDriveItem(itemRef, opts) {
|
|
4
|
+
return {
|
|
5
|
+
method: "DELETE",
|
|
6
|
+
path: generatePath("/sites/{site-id}/drives/{drive-id}/items/{item-id}", itemRef),
|
|
7
|
+
headers: {},
|
|
8
|
+
body: null,
|
|
9
|
+
dependsOn: opts?.dependsOn,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { generatePath } from "../../services/templatedPaths.js";
|
|
2
|
+
/** Retrieve the metadata for an item in a drive. @see https://learn.microsoft.com/en-us/graph/api/driveitem-get */
|
|
3
|
+
export default function getDriveItem(itemRef, opts) {
|
|
4
|
+
return {
|
|
5
|
+
method: "GET",
|
|
6
|
+
path: generatePath("/sites/{site-id}/drives/{drive-id}/items/{item-id}", itemRef),
|
|
7
|
+
headers: {},
|
|
8
|
+
body: null,
|
|
9
|
+
dependsOn: opts?.dependsOn,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { generatePath } from "../../services/templatedPaths.js";
|
|
2
|
+
/** Retrieve the metadata for an item in a drive by file path. If the target file is moved this will cease working. @see https://learn.microsoft.com/en-us/graph/api/driveitem-get */
|
|
3
|
+
export default function getDriveItemByPath(driveRef, itemPath, opts) {
|
|
4
|
+
return {
|
|
5
|
+
method: "GET",
|
|
6
|
+
path: generatePath(`/sites/{site-id}/drives/{drive-id}/root:${itemPath}`, driveRef),
|
|
7
|
+
headers: {},
|
|
8
|
+
body: null,
|
|
9
|
+
dependsOn: opts?.dependsOn,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { generatePath } from "../../services/templatedPaths.js";
|
|
2
|
+
/** Retrieve the metadata for items in a drive by file path. @see https://learn.microsoft.com/en-us/graph/api/driveitem-list-children */
|
|
3
|
+
export default function listDriveItems(driveRef, itemPath, opts) {
|
|
4
|
+
return {
|
|
5
|
+
method: "GET",
|
|
6
|
+
path: generatePath(`/sites/{site-id}/drives/{drive-id}/root:${itemPath}:/children`, driveRef),
|
|
7
|
+
headers: {},
|
|
8
|
+
body: null,
|
|
9
|
+
dependsOn: opts?.dependsOn,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { generatePath } from "../../services/templatedPaths.js";
|
|
2
|
+
/** Retrieve properties for a site resource. @see https://learn.microsoft.com/en-us/graph/api/site-get */
|
|
3
|
+
export default function getSite(siteRef, opts) {
|
|
4
|
+
return {
|
|
5
|
+
method: "GET",
|
|
6
|
+
path: generatePath("/sites/{site-id}", siteRef),
|
|
7
|
+
headers: {},
|
|
8
|
+
body: null,
|
|
9
|
+
dependsOn: opts?.dependsOn,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { generatePath } from "../../services/templatedPaths.js";
|
|
2
|
+
/** Get site by name. @see https://learn.microsoft.com/en-us/graph/api/site-getbypath */
|
|
3
|
+
export default function getSiteByName(hostName, siteName, opts) {
|
|
4
|
+
return {
|
|
5
|
+
method: "GET",
|
|
6
|
+
path: generatePath("/sites/{host-name}:/{site-name}", { hostName, siteName }),
|
|
7
|
+
headers: {},
|
|
8
|
+
body: null,
|
|
9
|
+
dependsOn: opts?.dependsOn,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { generatePath } from "../../services/templatedPaths.js";
|
|
2
|
+
/** List sites that are available. @see https://learn.microsoft.com/en-us/graph/api/site-list */
|
|
3
|
+
export default function listSites(opts) {
|
|
4
|
+
return {
|
|
5
|
+
method: "GET",
|
|
6
|
+
path: generatePath("/sites", {}),
|
|
7
|
+
headers: {},
|
|
8
|
+
body: null,
|
|
9
|
+
dependsOn: opts?.dependsOn,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { generatePath } from "../../services/templatedPaths.js";
|
|
2
|
+
/** Find accessible sites that match keywords provided. @see https://learn.microsoft.com/en-us/graph/api/site-search */
|
|
3
|
+
export default function searchSites(search, opts) {
|
|
4
|
+
return {
|
|
5
|
+
method: "GET",
|
|
6
|
+
path: generatePath("/sites?search={search}", { search }),
|
|
7
|
+
headers: {},
|
|
8
|
+
body: null,
|
|
9
|
+
dependsOn: opts?.dependsOn,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { generatePath } from "../../services/templatedPaths.js";
|
|
2
|
+
const emptyWorkbookBase64 = "UEsFBgAAAAAAAAAAAAAAAAAAAAAAAA==";
|
|
3
|
+
/** Create a new blank workbook. */
|
|
4
|
+
export default function createWorkbook(driveRef, itemPath, opts) {
|
|
5
|
+
return {
|
|
6
|
+
method: "PUT",
|
|
7
|
+
path: generatePath(`/sites/{site-id}/drives/{drive-id}/root:${itemPath}:/content`, driveRef),
|
|
8
|
+
headers: {
|
|
9
|
+
"content-type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
10
|
+
},
|
|
11
|
+
body: emptyWorkbookBase64,
|
|
12
|
+
dependsOn: opts?.dependsOn,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { generatePath } from "../../services/templatedPaths.js";
|
|
2
|
+
/** Clear a range - content, formatting or both. @see https://learn.microsoft.com/en-us/graph/api/range-delete */
|
|
3
|
+
export default function clearWorkbookRange(rangeRef, applyTo = "All", opts) {
|
|
4
|
+
return {
|
|
5
|
+
method: "POST",
|
|
6
|
+
path: generatePath("/sites/{site-id}/drives/{drive-id}/items/{item-id}/workbook/worksheets/{worksheet-id}/range(address='{address}')/clear", rangeRef),
|
|
7
|
+
headers: {
|
|
8
|
+
'workbook-session-id': rangeRef.sessionId,
|
|
9
|
+
"content-type": "application/json",
|
|
10
|
+
},
|
|
11
|
+
body: {
|
|
12
|
+
applyTo
|
|
13
|
+
},
|
|
14
|
+
dependsOn: opts?.dependsOn,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { generatePath } from "../../services/templatedPaths.js";
|
|
2
|
+
/** Delete a range. @see https://learn.microsoft.com/en-us/graph/api/range-clear */
|
|
3
|
+
export default function deleteWorkbookRange(rangeRef, shift, opts) {
|
|
4
|
+
return {
|
|
5
|
+
method: "POST",
|
|
6
|
+
path: generatePath("/sites/{site-id}/drives/{drive-id}/items/{item-id}/workbook/worksheets/{worksheet-id}/range(address='{address}')/delete", rangeRef),
|
|
7
|
+
headers: {
|
|
8
|
+
'workbook-session-id': rangeRef.sessionId,
|
|
9
|
+
'content-type': 'application/json',
|
|
10
|
+
},
|
|
11
|
+
body: {
|
|
12
|
+
shift
|
|
13
|
+
},
|
|
14
|
+
dependsOn: opts?.dependsOn,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { generatePath } from "../../services/templatedPaths.js";
|
|
2
|
+
/** Retrieve range that has been defined using the "named range" functionality. @see https://learn.microsoft.com/en-us/graph/api/range-get */
|
|
3
|
+
export default function getWorkbookNamedRange(rangeRef, opts) {
|
|
4
|
+
return {
|
|
5
|
+
method: "GET",
|
|
6
|
+
path: generatePath("/sites/{site-id}/drives/{drive-id}/items/{item-id}/workbook/names/{range-name}/range", rangeRef),
|
|
7
|
+
headers: {
|
|
8
|
+
'workbook-session-id': rangeRef.sessionId,
|
|
9
|
+
},
|
|
10
|
+
body: null,
|
|
11
|
+
dependsOn: opts?.dependsOn,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { generatePath } from "../../services/templatedPaths.js";
|
|
2
|
+
/** Fetch a range, including values and formatting. @see https://learn.microsoft.com/en-us/graph/api/range-get */
|
|
3
|
+
export default function getWorkbookRange(rangeRef, opts) {
|
|
4
|
+
return {
|
|
5
|
+
method: "GET",
|
|
6
|
+
path: generatePath(`/sites/{site-id}/drives/{drive-id}/items/{item-id}/workbook/worksheets/{worksheet-id}/range(address='{address}')`, rangeRef),
|
|
7
|
+
headers: {
|
|
8
|
+
'workbook-session-id': rangeRef.sessionId,
|
|
9
|
+
},
|
|
10
|
+
body: null,
|
|
11
|
+
dependsOn: opts?.dependsOn,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { generatePath } from "../../services/templatedPaths.js";
|
|
2
|
+
/** Retrieve the used range in a worksheet, ignoring trailing rows and columns that are blank. @see https://learn.microsoft.com/en-us/graph/api/range-usedrange */
|
|
3
|
+
export default function getWorkbookUsedRange(worksheetRef, opts) {
|
|
4
|
+
return {
|
|
5
|
+
method: "GET",
|
|
6
|
+
path: generatePath("/sites/{site-id}/drives/{drive-id}/items/{item-id}/workbook/worksheets/{worksheet-id}/range/usedRange", worksheetRef),
|
|
7
|
+
headers: {
|
|
8
|
+
'workbook-session-id': worksheetRef.sessionId,
|
|
9
|
+
},
|
|
10
|
+
body: null,
|
|
11
|
+
dependsOn: opts?.dependsOn,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { generatePath } from "../../services/templatedPaths.js";
|
|
2
|
+
/** Insert a new blank range at a specified address, shifting existing cells. Use `updateRange` after to set content. @see https://learn.microsoft.com/en-us/graph/api/range-insert */
|
|
3
|
+
export default function insertWorkbookCells(worksheetRef, address, shift, opts) {
|
|
4
|
+
return {
|
|
5
|
+
method: "POST",
|
|
6
|
+
path: generatePath(`/sites/{site-id}/drives/{drive-id}/items/{item-id}/workbook/worksheets/{worksheet-id}/range(address='${address}')/insert`, worksheetRef),
|
|
7
|
+
headers: {
|
|
8
|
+
'workbook-session-id': worksheetRef.sessionId,
|
|
9
|
+
'content-type': 'application/json',
|
|
10
|
+
},
|
|
11
|
+
body: {
|
|
12
|
+
shift
|
|
13
|
+
},
|
|
14
|
+
dependsOn: opts?.dependsOn,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { generatePath } from "../../services/templatedPaths.js";
|
|
2
|
+
/** Update range that has been defined using the "named range" functionality. Properties that aren't included in the request maintain their previous values or are recalculated based on changes to other property values. @see https://learn.microsoft.com/en-us/graph/api/range-update */
|
|
3
|
+
export default function updateWorkbookNamedRange(rangeRef, value, opts) {
|
|
4
|
+
return {
|
|
5
|
+
method: "PATCH",
|
|
6
|
+
path: generatePath("/sites/{site-id}/drives/{drive-id}/items/{item-id}/workbook/names/{range-name}/range", rangeRef),
|
|
7
|
+
headers: {
|
|
8
|
+
'workbook-session-id': rangeRef.sessionId,
|
|
9
|
+
'content-type': 'application/json',
|
|
10
|
+
},
|
|
11
|
+
body: value,
|
|
12
|
+
dependsOn: opts?.dependsOn,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { generatePath } from "../../services/templatedPaths.js";
|
|
2
|
+
/** Update range, including values and formatting. Properties that aren't included in the request maintain their previous values or are recalculated based on changes to other property values. @see https://learn.microsoft.com/en-us/graph/api/range-update */
|
|
3
|
+
export default function updateWorkbookRange(rangeRef, update, opts) {
|
|
4
|
+
return {
|
|
5
|
+
method: "PATCH",
|
|
6
|
+
path: generatePath(`/sites/{site-id}/drives/{drive-id}/items/{item-id}/workbook/worksheets/{worksheet-id}/range(address='{address}')`, rangeRef),
|
|
7
|
+
headers: {
|
|
8
|
+
'workbook-session-id': rangeRef.sessionId,
|
|
9
|
+
'content-type': 'application/json',
|
|
10
|
+
},
|
|
11
|
+
body: update,
|
|
12
|
+
dependsOn: opts?.dependsOn,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import InvalidArgumentError from "../../errors/InvalidArgumentError.js";
|
|
2
|
+
import { generatePath } from "../../services/templatedPaths.js";
|
|
3
|
+
/** Close an existing workbook session. @see https://learn.microsoft.com/en-us/graph/api/workbook-closesession */
|
|
4
|
+
export default function closeWorkbookSession(workbookRef, opts) {
|
|
5
|
+
if (!workbookRef.sessionId) {
|
|
6
|
+
throw new InvalidArgumentError("Workbook session ID is required to close a session.");
|
|
7
|
+
}
|
|
8
|
+
return {
|
|
9
|
+
method: "POST",
|
|
10
|
+
path: generatePath("/sites/{site-id}/drives/{drive-id}/items/{item-id}/workbook/closeSession", workbookRef),
|
|
11
|
+
headers: {
|
|
12
|
+
'workbook-session-id': workbookRef.sessionId,
|
|
13
|
+
},
|
|
14
|
+
body: null,
|
|
15
|
+
dependsOn: opts?.dependsOn,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { generatePath } from "../../services/templatedPaths.js";
|
|
2
|
+
/** Create a new workbook session. Typically the persistent session expires after about 5 minutes of inactivity. Non persistent session expires after about 7 minutes of inactivity. Most performant with `persistChanges = true`. @see https://learn.microsoft.com/en-us/graph/api/workbook-createsession @see https://learn.microsoft.com/en-us/graph/api/resources/excel#usage */
|
|
3
|
+
export default function createWorkbookSession(workbookRef, persistChanges = true, opts) {
|
|
4
|
+
return {
|
|
5
|
+
method: "POST",
|
|
6
|
+
path: generatePath("/sites/{site-id}/drives/{drive-id}/items/{item-id}/workbook/createSession", workbookRef),
|
|
7
|
+
headers: {
|
|
8
|
+
'content-type': 'application/json',
|
|
9
|
+
},
|
|
10
|
+
body: {
|
|
11
|
+
persistChanges
|
|
12
|
+
},
|
|
13
|
+
dependsOn: opts?.dependsOn,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import InvalidArgumentError from "../../errors/InvalidArgumentError.js";
|
|
2
|
+
import { generatePath } from "../../services/templatedPaths.js";
|
|
3
|
+
/** Refresh a workbook session. @see https://learn.microsoft.com/en-us/graph/api/workbook-refreshsession */
|
|
4
|
+
export default function refreshWorkbookSession(workbookRef, opts) {
|
|
5
|
+
if (!workbookRef.sessionId) {
|
|
6
|
+
throw new InvalidArgumentError("Workbook session ID is required to refresh a session.");
|
|
7
|
+
}
|
|
8
|
+
return {
|
|
9
|
+
method: "POST",
|
|
10
|
+
path: generatePath("/sites/{site-id}/drives/{drive-id}/items/{item-id}/workbook/refreshSession", workbookRef),
|
|
11
|
+
headers: {
|
|
12
|
+
'workbook-session-id': workbookRef.sessionId,
|
|
13
|
+
'content-type': 'application/json',
|
|
14
|
+
},
|
|
15
|
+
body: null,
|
|
16
|
+
dependsOn: opts?.dependsOn,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { generatePath } from "../../services/templatedPaths.js";
|
|
2
|
+
/** Create a new worksheet, optionally with a defined name. @see https://learn.microsoft.com/en-us/graph/api/worksheetcollection-add */
|
|
3
|
+
export default function createWorkbookWorksheet(workbookRef, name, opts) {
|
|
4
|
+
return {
|
|
5
|
+
method: "POST",
|
|
6
|
+
path: generatePath("/sites/{site-id}/drives/{drive-id}/items/{item-id}/workbook/worksheets/add", workbookRef),
|
|
7
|
+
headers: {
|
|
8
|
+
'workbook-session-id': workbookRef.sessionId,
|
|
9
|
+
'content-type': 'application/json',
|
|
10
|
+
},
|
|
11
|
+
body: {
|
|
12
|
+
name
|
|
13
|
+
},
|
|
14
|
+
dependsOn: opts?.dependsOn,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { generatePath } from "../../services/templatedPaths.js";
|
|
2
|
+
/** Permanently delete a worksheet. @see https://learn.microsoft.com/en-us/graph/api/worksheet-delete */
|
|
3
|
+
export default function deleteWorkbookWorksheet(worksheetRef, opts) {
|
|
4
|
+
return {
|
|
5
|
+
method: "DELETE",
|
|
6
|
+
path: generatePath("/sites/{site-id}/drives/{drive-id}/items/{item-id}/workbook/worksheets/{worksheet-id}", worksheetRef),
|
|
7
|
+
headers: {
|
|
8
|
+
'workbook-session-id': worksheetRef.sessionId,
|
|
9
|
+
},
|
|
10
|
+
body: null,
|
|
11
|
+
dependsOn: opts?.dependsOn,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { generatePath } from "../../services/templatedPaths.js";
|
|
2
|
+
/** Retrieve a list of worksheets. @see https://learn.microsoft.com/en-us/graph/api/worksheet-list */
|
|
3
|
+
export default function listWorkbookWorksheets(workbookRef, opts) {
|
|
4
|
+
return {
|
|
5
|
+
method: "GET",
|
|
6
|
+
path: generatePath("/sites/{site-id}/drives/{drive-id}/items/{item-id}/workbook/worksheets", workbookRef),
|
|
7
|
+
headers: {
|
|
8
|
+
'workbook-session-id': workbookRef.sessionId,
|
|
9
|
+
},
|
|
10
|
+
body: null,
|
|
11
|
+
dependsOn: opts?.dependsOn,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { generatePath } from "../../services/templatedPaths.js";
|
|
2
|
+
/** Update the name, position and/or visibility of a worksheet. @see https://learn.microsoft.com/en-us/graph/api/worksheet-update */
|
|
3
|
+
export default function updateWorkbookWorksheet(worksheetRef, updates, opts) {
|
|
4
|
+
return {
|
|
5
|
+
method: "PATCH",
|
|
6
|
+
path: generatePath("/sites/{site-id}/drives/{drive-id}/items/{item-id}/workbook/worksheets/{worksheet-id}", worksheetRef),
|
|
7
|
+
headers: {
|
|
8
|
+
'workbook-session-id': worksheetRef.sessionId,
|
|
9
|
+
'content-type': 'application/json',
|
|
10
|
+
},
|
|
11
|
+
body: updates,
|
|
12
|
+
dependsOn: opts?.dependsOn,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ClientSecretCredential } from "@azure/identity";
|
|
2
|
+
import { azureClientId, azureClientSecret, azureTenantId } from "./configuration.js";
|
|
3
|
+
const credential = new ClientSecretCredential(azureTenantId, azureClientId, azureClientSecret);
|
|
4
|
+
const innerTokenCache = {};
|
|
5
|
+
/** Get an access token for a given scope. If an unexpired one is cached it will be returned, otherwise requests a new one. */
|
|
6
|
+
export async function getCurrentAccessToken(scope) {
|
|
7
|
+
let innerToken = innerTokenCache[scope];
|
|
8
|
+
if (!innerToken || innerToken.expiresOnTimestamp < Date.now()) {
|
|
9
|
+
innerTokenCache[scope] = innerToken = await credential.getToken(scope);
|
|
10
|
+
}
|
|
11
|
+
return innerToken.token;
|
|
12
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const missingEnvironmentVariables = [];
|
|
2
|
+
function tryGetEnvironmentVariable(env, fallbackValue = null) {
|
|
3
|
+
const value = process.env[env]?.trim() ?? "";
|
|
4
|
+
if (value === "") {
|
|
5
|
+
if (fallbackValue === null) {
|
|
6
|
+
missingEnvironmentVariables.push(env); // It's fatal if env is unset and there is no fallbackValue, however we want to report all of these in one batch..
|
|
7
|
+
}
|
|
8
|
+
return fallbackValue ?? "";
|
|
9
|
+
}
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
export const azureTenantId = tryGetEnvironmentVariable("AZURE_TENANT_ID");
|
|
13
|
+
export const azureClientId = tryGetEnvironmentVariable("AZURE_CLIENT_ID");
|
|
14
|
+
export const azureClientSecret = tryGetEnvironmentVariable("AZURE_CLIENT_SECRET");
|
|
15
|
+
export const defaultSiteId = tryGetEnvironmentVariable("SHAREPOINT_DEFAULT_SITE_ID");
|
|
16
|
+
export const defaultDriveId = tryGetEnvironmentVariable("SHAREPOINT_DEFAULT_DRIVE_ID");
|
|
17
|
+
if (missingEnvironmentVariables.length > 0) {
|
|
18
|
+
console.error(`\x1b[31mFATAL: Required environment variable(s) ${missingEnvironmentVariables.join(", ")} missing, empty or whitespace.\x1b[0m`);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import InvalidArgumentError from "../errors/InvalidArgumentError.js";
|
|
2
|
+
const sharepointUrlPattern = /^\/sites\/([^\/]+)/;
|
|
3
|
+
/** Get the site name and item path from a given SharePoint URL. (ie https://lachlandev.sharepoint.com/sites/Nexus-Test/Shared%20Documents/Forms/AllItems.aspx?newTargetListUrl=%2Fsites%2FNexus%2DTest%2FShared%20Documents)) */
|
|
4
|
+
export function parseSharepointUrl(uiUrl) {
|
|
5
|
+
if (!uiUrl.hostname.endsWith(".sharepoint.com")) {
|
|
6
|
+
throw new InvalidArgumentError("Invalid SharePoint URL. Must end with '.sharepoint.com'.");
|
|
7
|
+
}
|
|
8
|
+
const hostname = uiUrl.hostname;
|
|
9
|
+
const pathMatch = uiUrl.pathname.match(sharepointUrlPattern);
|
|
10
|
+
if (!pathMatch) {
|
|
11
|
+
throw new InvalidArgumentError("Invalid SharePoint URL. Must start with '/sites/'.");
|
|
12
|
+
}
|
|
13
|
+
const siteName = pathMatch[1];
|
|
14
|
+
const itemPath = (uiUrl.searchParams.get("viewPath") || uiUrl.searchParams.get("newTargetListUrl") || null);
|
|
15
|
+
if (!itemPath) {
|
|
16
|
+
throw new InvalidArgumentError("Invalid SharePoint URL. Path not found in parameters.");
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
hostname,
|
|
20
|
+
siteName,
|
|
21
|
+
itemPath,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import BadTemplateError from "../errors/BadTemplateError.js";
|
|
2
|
+
import { kebabToCamelCase } from "./stringCaseConversion.js";
|
|
3
|
+
/** Create a GraphAPI path based on a given template and arguments. Escaping is automatically handeld */
|
|
4
|
+
export function generatePath(template, args) {
|
|
5
|
+
if (!template.startsWith("/")) {
|
|
6
|
+
throw new BadTemplateError("Path template must start with a slash.");
|
|
7
|
+
}
|
|
8
|
+
if (template.includes("\n")) {
|
|
9
|
+
throw new BadTemplateError("Path template must not contain newlines.");
|
|
10
|
+
}
|
|
11
|
+
return template.replace(/{(\w+)}/g, (key) => {
|
|
12
|
+
const camelCaseKey = kebabToCamelCase(key);
|
|
13
|
+
const value = args[camelCaseKey];
|
|
14
|
+
if (value === undefined) {
|
|
15
|
+
throw new BadTemplateError(`Path template references argument '${camelCaseKey}' however no such argument provided.`);
|
|
16
|
+
}
|
|
17
|
+
return encodeURIComponent(value);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../src/index.ts"],"version":"5.7.3"}
|