microsoft-graph 2.0.0 → 2.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/.github/workflows/check.yml +23 -0
- package/.vscode/settings.json +8 -2
- package/LICENCE.md +96 -325
- package/biome.jsonc +16 -46
- package/dist/docs/getItem.js +11 -0
- package/dist/errors/EnvironmentVariableMissingError.d.ts.map +1 -1
- package/dist/errors/InvalidArgumentError.d.ts.map +1 -1
- package/dist/errors/NeverError.d.ts +4 -0
- package/dist/errors/NeverError.d.ts.map +1 -0
- package/dist/errors/NeverError.js +6 -0
- package/dist/errors/RequestFailedError.d.ts +1 -2
- package/dist/errors/RequestFailedError.d.ts.map +1 -1
- package/dist/errors/RequestFailedError.js +5 -13
- package/dist/graphApi.d.ts +6 -5
- package/dist/graphApi.d.ts.map +1 -1
- package/dist/graphApi.js +118 -75
- 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/models/AccessToken.d.ts.map +1 -1
- package/dist/models/ClientId.d.ts.map +1 -1
- package/dist/models/ClientSecret.d.ts.map +1 -1
- package/dist/models/Context.d.ts.map +1 -1
- package/dist/models/ContextId.d.ts.map +1 -1
- package/dist/models/ContextRef.d.ts.map +1 -1
- package/dist/models/DriveId.d.ts.map +1 -1
- package/dist/models/DriveItemId.d.ts.map +1 -1
- package/dist/models/DriveItemPath.d.ts.map +1 -1
- package/dist/models/DriveItemRef.d.ts.map +1 -1
- package/dist/models/DriveRef.d.ts.map +1 -1
- package/dist/models/GraphOperation.d.ts.map +1 -1
- package/dist/models/GraphOperationDefinition.d.ts.map +1 -1
- package/dist/models/HostName.d.ts.map +1 -1
- package/dist/models/HttpProxy.d.ts.map +1 -1
- package/dist/models/Scope.d.ts.map +1 -1
- package/dist/models/SiteId.d.ts.map +1 -1
- package/dist/models/SiteName.d.ts.map +1 -1
- package/dist/models/SiteRef.d.ts.map +1 -1
- package/dist/models/TenantId.d.ts.map +1 -1
- package/dist/models/WorkbookNamedRangeRef.d.ts.map +1 -1
- package/dist/models/WorkbookRangeAddress.d.ts.map +1 -1
- package/dist/models/WorkbookRangeName.d.ts.map +1 -1
- package/dist/models/WorkbookRangeRef.d.ts.map +1 -1
- package/dist/models/WorkbookRef.d.ts.map +1 -1
- package/dist/models/WorkbookSessionId.d.ts.map +1 -1
- package/dist/models/WorkbookTableId.d.ts.map +1 -1
- package/dist/models/WorkbookTableRef.d.ts.map +1 -1
- package/dist/models/WorkbookWorksheetId.d.ts.map +1 -1
- package/dist/models/WorkbookWorksheetName.d.ts.map +1 -1
- package/dist/models/WorkbookWorksheetRef.d.ts.map +1 -1
- package/dist/operations/drive/createFolder.d.ts.map +1 -1
- package/dist/operations/drive/createFolder.js +3 -3
- package/dist/operations/drive/createFolder.test.js +2 -2
- package/dist/operations/drive/listDrives.d.ts.map +1 -1
- package/dist/operations/drive/listDrives.js +4 -4
- package/dist/operations/driveItem/deleteDriveItem.js +1 -1
- package/dist/operations/driveItem/deleteDriveItem.test.js +2 -2
- package/dist/operations/driveItem/getDriveItem.js +3 -3
- package/dist/operations/driveItem/getDriveItem.test.js +2 -2
- package/dist/operations/driveItem/getDriveItemByPath.js +3 -3
- package/dist/operations/driveItem/getDriveItemByPath.test.js +2 -2
- package/dist/operations/driveItem/getDriveItemContent.d.ts.map +1 -1
- package/dist/operations/driveItem/getDriveItemContent.js +3 -3
- package/dist/operations/driveItem/getDriveItemContent.test.js +1 -3
- package/dist/operations/driveItem/initiateCopyDriveItem.js +1 -1
- package/dist/operations/driveItem/initiateCopyDriveItem.test.js +2 -2
- package/dist/operations/driveItem/listDriveItems.d.ts.map +1 -1
- package/dist/operations/driveItem/listDriveItems.js +3 -3
- package/dist/operations/driveItem/listDriveItems.test.js +1 -1
- package/dist/operations/site/getSite.js +3 -3
- package/dist/operations/site/getSiteByName.js +2 -2
- package/dist/operations/site/listSites.js +3 -3
- package/dist/operations/site/listSites.test.js +1 -1
- package/dist/operations/site/searchSites.js +3 -3
- package/dist/operations/user/userSendMail.js +2 -3
- package/dist/operations/workbook/calculateWorkbook.d.ts.map +1 -1
- package/dist/operations/workbook/calculateWorkbook.js +2 -2
- package/dist/operations/workbook/calculateWorkbook.test.js +3 -3
- package/dist/operations/workbook/createWorkbook.js +3 -3
- package/dist/operations/workbook/deleteWorkbook.d.ts.map +1 -1
- package/dist/operations/workbookRange/clearWorkbookRange.d.ts.map +1 -1
- package/dist/operations/workbookRange/clearWorkbookRange.js +2 -2
- package/dist/operations/workbookRange/clearWorkbookRange.test.js +21 -9
- package/dist/operations/workbookRange/deleteWorkbookRange.d.ts.map +1 -1
- package/dist/operations/workbookRange/deleteWorkbookRange.js +2 -2
- package/dist/operations/workbookRange/deleteWorkbookRange.test.js +21 -9
- package/dist/operations/workbookRange/getWorkbookNamedRange.js +3 -3
- package/dist/operations/workbookRange/getWorkbookUsedRange.js +3 -3
- package/dist/operations/workbookRange/getWorkbookUsedRange.test.js +14 -8
- package/dist/operations/workbookRange/getWorkbookVisibleRange.d.ts.map +1 -1
- package/dist/operations/workbookRange/getWorkbookVisibleRange.js +4 -3
- package/dist/operations/workbookRange/getWorkbookVisibleRange.test.js +21 -15
- package/dist/operations/workbookRange/insertWorkbookCells.d.ts.map +1 -1
- package/dist/operations/workbookRange/insertWorkbookCells.js +4 -4
- package/dist/operations/workbookRange/insertWorkbookCells.test.js +3 -3
- package/dist/operations/workbookRange/updateWorkbookNamedRange.js +1 -1
- package/dist/operations/workbookRange/updateWorkbookRange.js +3 -3
- package/dist/operations/workbookRange/updateWorkbookRange.test.js +13 -7
- package/dist/operations/workbookSession/closeWorkbookSession.js +1 -1
- package/dist/operations/workbookSession/createWorkbookSession.js +5 -5
- package/dist/operations/workbookSession/refreshWorkbookSession.js +1 -1
- package/dist/operations/workbookTable/createWorkbookTable.js +4 -4
- package/dist/operations/workbookTable/createWorkbookTable.test.js +2 -2
- package/dist/operations/workbookTable/getWorkbookTable.js +3 -3
- package/dist/operations/workbookTable/getWorkbookTable.test.js +2 -2
- package/dist/operations/workbookTable/getWorkbookTableBodyRange.js +3 -3
- package/dist/operations/workbookTable/getWorkbookTableBodyRange.test.js +4 -4
- package/dist/operations/workbookTable/getWorkbookTableHeaderRange.js +3 -3
- package/dist/operations/workbookTable/getWorkbookTableHeaderRange.test.js +3 -3
- package/dist/operations/workbookTable/listWorkbookTableColumns.js +2 -2
- package/dist/operations/workbookTable/listWorkbookTableColumns.test.js +2 -2
- package/dist/operations/workbookTable/listWorkbookTableRows.js +2 -2
- package/dist/operations/workbookTable/listWorkbookTableRows.test.js +2 -2
- package/dist/operations/workbookTable/listWorkbookTables.js +3 -3
- package/dist/operations/workbookTable/listWorkbookTables.test.js +2 -2
- package/dist/operations/workbookWorksheet/createWorkbookWorksheet.js +4 -4
- package/dist/operations/workbookWorksheet/createWorkbookWorksheet.test.js +3 -3
- package/dist/operations/workbookWorksheet/deleteWorkbookWorksheet.d.ts.map +1 -1
- package/dist/operations/workbookWorksheet/deleteWorkbookWorksheet.js +1 -1
- package/dist/operations/workbookWorksheet/deleteWorkbookWorksheet.test.js +3 -3
- package/dist/operations/workbookWorksheet/getWorkbookWorksheetRange.js +3 -3
- package/dist/operations/workbookWorksheet/getWorkbookWorksheetRange.test.js +7 -4
- package/dist/operations/workbookWorksheet/listWorkbookWorksheets.js +3 -3
- package/dist/operations/workbookWorksheet/listWorkbookWorksheets.test.js +5 -5
- package/dist/operations/workbookWorksheet/updateWorkbookWorksheet.d.ts.map +1 -1
- package/dist/operations/workbookWorksheet/updateWorkbookWorksheet.js +3 -3
- package/dist/operations/workbookWorksheet/updateWorkbookWorksheet.test.js +3 -3
- package/dist/services/context.d.ts.map +1 -1
- package/dist/services/context.js +2 -2
- package/dist/services/drive.d.ts.map +1 -1
- package/dist/services/driveItem.d.ts.map +1 -1
- package/dist/services/driveItem.js +2 -6
- package/dist/services/httpStatus.d.ts +1 -0
- package/dist/services/httpStatus.d.ts.map +1 -1
- package/dist/services/httpStatus.js +3 -0
- package/dist/services/random.js +2 -2
- package/dist/services/sharepointUrl.test.js +6 -6
- package/dist/services/site.js +2 -2
- package/dist/services/sleep.js +1 -1
- package/dist/services/templatedPaths.d.ts.map +1 -1
- package/dist/services/workbookRange.d.ts.map +1 -1
- package/dist/services/workbookRange.js +1 -1
- package/dist/services/workbookTable.d.ts.map +1 -1
- package/dist/services/workbookTable.js +1 -1
- package/dist/services/workbookWorksheet.d.ts.map +1 -1
- package/dist/services/workbookWorksheet.js +1 -1
- package/dist/tasks/createWorkbookAndStartSession.js +1 -1
- package/dist/tasks/getRangeLastUsedCell.d.ts.map +1 -1
- package/dist/tasks/getRangeLastUsedCell.js +1 -1
- package/dist/tasks/getRangeLastUsedCell.test.js +9 -9
- package/dist/tasks/getWorkbookTableVisibleBody.test.js +21 -21
- package/dist/tasks/getWorkbookWorksheetRefByName.js +1 -1
- package/dist/tasks/safeDeleteWorkbook.d.ts +4 -0
- package/dist/tasks/safeDeleteWorkbook.d.ts.map +1 -0
- package/dist/tasks/safeDeleteWorkbook.js +9 -0
- package/dist/tasks/setColumnHidden.js +1 -2
- package/dist/tasks/setColumnHidden.test.js +5 -5
- package/dist/tasks/setRowHidden.js +1 -2
- package/dist/tasks/setRowHidden.test.js +5 -5
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/docs/lockedWorkbook.md +2 -0
- package/docs/pivotTables.md +9 -0
- package/docs/requestRetrying.md +3 -0
- package/package.json +512 -3
|
@@ -1,21 +1,13 @@
|
|
|
1
|
-
import { isHttpOk } from "../services/httpStatus.js";
|
|
2
1
|
export default class RequestFailedError extends Error {
|
|
3
2
|
constructor(message) {
|
|
4
3
|
super(message);
|
|
5
4
|
this.name = "RequestFailedError";
|
|
6
5
|
}
|
|
7
|
-
static
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
`Error: ${JSON.stringify(error, null, 2)}}`);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
static throwIfNotOkOperation(status, index, op, error) {
|
|
15
|
-
if (!isHttpOk(status)) {
|
|
16
|
-
throw new RequestFailedError(`GraphAPI operation ${index} failed with HTTP ${status}\n` +
|
|
17
|
-
`Operation: ${JSON.stringify(op, null, 2)}\n` +
|
|
18
|
-
`Error: ${JSON.stringify(error, null, 2)}}`);
|
|
6
|
+
static throw(message, request, response) {
|
|
7
|
+
const r = request;
|
|
8
|
+
if (r?.headers?.authorization) {
|
|
9
|
+
r.headers.authorization = "<REDACTED>";
|
|
19
10
|
}
|
|
11
|
+
throw new RequestFailedError(`${message}\n\nREQUEST: ${JSON.stringify(r, null, 2)}\n\nRESPONSE: ${JSON.stringify(response, null, 2)}`);
|
|
20
12
|
}
|
|
21
13
|
}
|
package/dist/graphApi.d.ts
CHANGED
|
@@ -3,13 +3,14 @@ import type { Scope } from "./models/Scope.ts";
|
|
|
3
3
|
export declare const authenticationScope: Scope;
|
|
4
4
|
export declare const endpoint = "https://graph.microsoft.com/v1.0";
|
|
5
5
|
export declare const batchEndpoint = "https://graph.microsoft.com/v1.0/$batch";
|
|
6
|
-
|
|
7
|
-
[K in keyof T]: T[K] extends GraphOperation<infer R> ? R : never;
|
|
8
|
-
};
|
|
6
|
+
/** Define a operation, which can either be `await`d to execute independently, or passed with other operations ot `parallel` or `sequential` to execute as part of a batch. */
|
|
9
7
|
export declare function operation<T>(definition: GraphOperationDefinition<T>): GraphOperation<T>;
|
|
10
8
|
/** Execute a batch of GraphAPI operations in parallel. Provides the best performance for batch operations, however only useful if operations can logically be performed at the same time. */
|
|
11
|
-
export declare function parallel<T extends GraphOperation<unknown>[]>(...
|
|
9
|
+
export declare function parallel<T extends GraphOperation<unknown>[]>(...operations: T): Promise<OperationResponse<T>>;
|
|
12
10
|
/** Execute a batch of GraphAPI operations sequentially. */
|
|
13
|
-
export declare function sequential<T extends GraphOperation<unknown>[]>(...
|
|
11
|
+
export declare function sequential<T extends GraphOperation<unknown>[]>(...operations: T): Promise<OperationResponse<T>>;
|
|
12
|
+
type OperationResponse<T> = {
|
|
13
|
+
[K in keyof T]: T[K] extends GraphOperation<infer R> ? R : never;
|
|
14
|
+
};
|
|
14
15
|
export {};
|
|
15
16
|
//# sourceMappingURL=graphApi.d.ts.map
|
package/dist/graphApi.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphApi.d.ts","sourceRoot":"","sources":["../src/graphApi.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"graphApi.d.ts","sourceRoot":"","sources":["../src/graphApi.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAgB,cAAc,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACzG,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAQ/C,eAAO,MAAM,mBAAmB,EAA6C,KAAK,CAAC;AACnF,eAAO,MAAM,QAAQ,qCAAqC,CAAC;AAC3D,eAAO,MAAM,aAAa,4CAAuB,CAAC;AAElD,8KAA8K;AAC9K,wBAAgB,SAAS,CAAC,CAAC,EAAE,UAAU,EAAE,wBAAwB,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAQvF;AAED,6LAA6L;AAC7L,wBAAsB,QAAQ,CAAC,CAAC,SAAS,cAAc,CAAC,OAAO,CAAC,EAAE,EAAE,GAAG,UAAU,EAAE,CAAC,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAInH;AAED,2DAA2D;AAC3D,wBAAsB,UAAU,CAAC,CAAC,SAAS,cAAc,CAAC,OAAO,CAAC,EAAE,EAAE,GAAG,UAAU,EAAE,CAAC,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAOrH;AAoBD,KAAK,iBAAiB,CAAC,CAAC,IAAI;KAC1B,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,cAAc,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;CAChE,CAAC"}
|
package/dist/graphApi.js
CHANGED
|
@@ -1,107 +1,160 @@
|
|
|
1
|
-
import fetch from
|
|
1
|
+
import fetch from "node-fetch";
|
|
2
2
|
import InconsistentContextError from "./errors/InconsistentContextError.js";
|
|
3
3
|
import InvalidArgumentError from "./errors/InvalidArgumentError.js";
|
|
4
|
+
import NeverError from "./errors/NeverError.js";
|
|
5
|
+
import ProtocolError from "./errors/ProtocolError.js";
|
|
4
6
|
import RequestFailedError from "./errors/RequestFailedError.js";
|
|
5
7
|
import { getCurrentAccessToken } from "./services/accessToken.js";
|
|
6
8
|
import { getContext } from "./services/context.js";
|
|
7
9
|
import { tryGetHttpAgent } from "./services/httpAgent.js";
|
|
10
|
+
import { isHttpOk, isHttpTooManyRequests } from "./services/httpStatus.js";
|
|
8
11
|
import { operationIdToIndex, operationIndexToId } from "./services/operationId.js";
|
|
12
|
+
import { sleep } from "./services/sleep.js";
|
|
9
13
|
export const authenticationScope = "https://graph.microsoft.com/.default";
|
|
10
14
|
export const endpoint = "https://graph.microsoft.com/v1.0";
|
|
11
15
|
export const batchEndpoint = `${endpoint}/$batch`;
|
|
12
|
-
|
|
16
|
+
/** Define a operation, which can either be `await`d to execute independently, or passed with other operations ot `parallel` or `sequential` to execute as part of a batch. */
|
|
13
17
|
export function operation(definition) {
|
|
14
|
-
|
|
18
|
+
const single = async (definition) => {
|
|
19
|
+
return await executeSingle(definition);
|
|
20
|
+
};
|
|
15
21
|
const op = single(definition);
|
|
16
22
|
op.definition = definition;
|
|
17
23
|
return op;
|
|
18
24
|
}
|
|
19
|
-
|
|
25
|
+
/** Execute a batch of GraphAPI operations in parallel. Provides the best performance for batch operations, however only useful if operations can logically be performed at the same time. */
|
|
26
|
+
export async function parallel(...operations) {
|
|
27
|
+
const definitions = operations.map((op) => op.definition);
|
|
28
|
+
return (await executeBatch(...definitions));
|
|
29
|
+
}
|
|
30
|
+
/** Execute a batch of GraphAPI operations sequentially. */
|
|
31
|
+
export async function sequential(...operations) {
|
|
32
|
+
const definitions = operations.map((definition, index) => ({
|
|
33
|
+
...definition.definition,
|
|
34
|
+
dependsOn: index > 0 ? [index - 1] : undefined, // Each op is dependant on the previous op
|
|
35
|
+
}));
|
|
36
|
+
return (await executeBatch(...definitions));
|
|
37
|
+
}
|
|
38
|
+
const maxBatchOperations = 20; // https://learn.microsoft.com/en-us/graph/json-batching?tabs=http#batch-size-limitations
|
|
39
|
+
const maxRetries = 3;
|
|
40
|
+
const defaultRetryDelayMilliseconds = 1000;
|
|
41
|
+
const consecutiveRetryDelayMultiplier = 2;
|
|
42
|
+
async function executeSingle(definition) {
|
|
20
43
|
const context = getContext(definition.contextId);
|
|
21
44
|
const accessToken = await getCurrentAccessToken(context.tenantId, context.clientId, context.clientSecret, authenticationScope);
|
|
22
45
|
const agent = tryGetHttpAgent(context.httpProxy);
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
...Object.fromEntries(Object.entries(definition.headers ?? {}).filter(([_, v]) => v !== undefined)), // TODO: Tidy
|
|
26
|
-
};
|
|
27
|
-
const reply = await fetch(`${endpoint}${definition.path}`, {
|
|
46
|
+
const response = await innerFetch({
|
|
47
|
+
url: `${endpoint}${definition.path}`,
|
|
28
48
|
method: definition.method,
|
|
29
|
-
headers:
|
|
49
|
+
headers: {
|
|
50
|
+
authorization: createAuthorizationHeader(accessToken),
|
|
51
|
+
...headersToObject(definition.headers),
|
|
52
|
+
},
|
|
30
53
|
body: definition.body === null ? null : JSON.stringify(definition.body),
|
|
31
|
-
agent
|
|
54
|
+
agent,
|
|
32
55
|
});
|
|
33
|
-
|
|
34
|
-
const body = replyContentType?.startsWith("application/json") ? await reply.json() : null;
|
|
35
|
-
RequestFailedError.throwIfNotOkOperation(reply.status, 0, definition, body);
|
|
36
|
-
return definition.responseTransform(body);
|
|
56
|
+
return definition.responseTransform(response);
|
|
37
57
|
}
|
|
38
|
-
|
|
39
|
-
export async function parallel(...ops) {
|
|
40
|
-
const definitions = ops.map(op => op.definition);
|
|
41
|
-
return await execute(...definitions);
|
|
42
|
-
}
|
|
43
|
-
/** Execute a batch of GraphAPI operations sequentially. */
|
|
44
|
-
export async function sequential(...ops) {
|
|
45
|
-
const definitions = ops.map(op => op.definition);
|
|
46
|
-
const sequentialOps = definitions.map((definition, index) => ({
|
|
47
|
-
...definition,
|
|
48
|
-
dependsOn: index > 0 ? [index - 1] : undefined // Each op is dependant on the previous op
|
|
49
|
-
}));
|
|
50
|
-
return await execute(...sequentialOps);
|
|
51
|
-
}
|
|
52
|
-
async function execute(...ops) {
|
|
58
|
+
async function executeBatch(...ops) {
|
|
53
59
|
InvalidArgumentError.throwIfGreater(ops.length, maxBatchOperations, `At most ${maxBatchOperations} operations allowed, but ${ops.length} were provided.`);
|
|
54
60
|
if (ops.length === 0) {
|
|
55
61
|
return [];
|
|
56
62
|
}
|
|
57
|
-
const requestPayload = await composeRequestPayload(ops);
|
|
58
|
-
const reply = await fetch(batchEndpoint, requestPayload);
|
|
59
|
-
const replyPayload = await reply.json();
|
|
60
|
-
RequestFailedError.throwIfNotOkBatch(reply.status, ops, replyPayload);
|
|
61
|
-
const responses = parseResponses(replyPayload, ops);
|
|
62
|
-
return responses;
|
|
63
|
-
}
|
|
64
|
-
async function composeRequestPayload(ops) {
|
|
65
63
|
const firstOp = ops[0];
|
|
66
64
|
if (!firstOp) {
|
|
67
|
-
throw new
|
|
65
|
+
throw new NeverError("First op not found. Should be impossible");
|
|
68
66
|
}
|
|
69
67
|
const contextId = firstOp.contextId;
|
|
70
|
-
if (ops.some(op => op.contextId !== contextId)) {
|
|
68
|
+
if (ops.some((op) => op.contextId !== contextId)) {
|
|
71
69
|
throw new InconsistentContextError("All operations in a batch must share the same contextId.");
|
|
72
70
|
}
|
|
73
71
|
const context = getContext(contextId);
|
|
74
72
|
const accessToken = await getCurrentAccessToken(context.tenantId, context.clientId, context.clientSecret, authenticationScope);
|
|
75
73
|
const agent = tryGetHttpAgent(context.httpProxy);
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
id: operationIndexToId(index),
|
|
79
|
-
method: op.method,
|
|
80
|
-
url: op.path,
|
|
81
|
-
headers: op.headers,
|
|
82
|
-
body: op.body === null ? undefined : op.body,
|
|
83
|
-
dependsOn: op.dependsOn?.map((id) => id.toString())
|
|
84
|
-
}))
|
|
85
|
-
};
|
|
86
|
-
const requestPayload = {
|
|
74
|
+
const body = await innerFetch({
|
|
75
|
+
url: batchEndpoint,
|
|
87
76
|
method: "POST",
|
|
88
77
|
headers: {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
"content-type": "application/json"
|
|
78
|
+
authorization: createAuthorizationHeader(accessToken),
|
|
79
|
+
accept: "application/json",
|
|
80
|
+
"content-type": "application/json",
|
|
92
81
|
},
|
|
93
|
-
body: JSON.stringify(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
82
|
+
body: JSON.stringify({
|
|
83
|
+
requests: ops.map((op, index) => ({
|
|
84
|
+
id: operationIndexToId(index),
|
|
85
|
+
method: op.method,
|
|
86
|
+
url: op.path,
|
|
87
|
+
headers: op.headers,
|
|
88
|
+
body: op.body === null ? undefined : op.body,
|
|
89
|
+
dependsOn: op.dependsOn?.map((id) => id.toString()),
|
|
90
|
+
})),
|
|
91
|
+
}),
|
|
92
|
+
agent,
|
|
93
|
+
});
|
|
94
|
+
const responses = [];
|
|
95
|
+
for (const r of body.responses) {
|
|
96
|
+
const index = operationIdToIndex(r.id);
|
|
97
|
+
const headers = normalizeBatchHeaders(r.headers);
|
|
98
|
+
const contentType = headers["content-type"];
|
|
99
|
+
const body = normalizeBatchBody(contentType, r.body);
|
|
100
|
+
const op = ops[index];
|
|
101
|
+
if (!op) {
|
|
102
|
+
throw new ProtocolError("Reference to operation that was not submitted in the batch");
|
|
103
|
+
}
|
|
104
|
+
if (!isHttpOk(r.status)) {
|
|
105
|
+
const bodyError = body;
|
|
106
|
+
const errorMessage = bodyError?.error ? `[${bodyError.error.code}] ${bodyError.error.message}` : `HTTP ${r.status}`;
|
|
107
|
+
RequestFailedError.throw(`GraphAPI operation ${index} failed: '${errorMessage}'`, op, r);
|
|
108
|
+
}
|
|
109
|
+
responses[index] = op.responseTransform(body);
|
|
110
|
+
}
|
|
111
|
+
return responses; // TODO: Is there a neater way to massage the types correctly? This is functionally correct, but I do want to avoid using `unknown` here if possible.
|
|
112
|
+
}
|
|
113
|
+
/** Execute request, supporting GraphAPI retry logic */
|
|
114
|
+
async function innerFetch(args) {
|
|
115
|
+
const { url, ...options } = args;
|
|
116
|
+
let retryAfterMilliseconds = defaultRetryDelayMilliseconds;
|
|
117
|
+
let response = null;
|
|
118
|
+
let attempts = 0; // Track the number of attempts
|
|
119
|
+
while (attempts < maxRetries) {
|
|
120
|
+
// Retry at most 3 times
|
|
121
|
+
response = await fetch(url, options);
|
|
122
|
+
if (!isHttpTooManyRequests(response.status)) {
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
const requestedRetryAfterSeconds = Number.parseInt(response.headers.get("Retry-After") ?? "0", 10);
|
|
126
|
+
if (requestedRetryAfterSeconds) {
|
|
127
|
+
retryAfterMilliseconds = requestedRetryAfterSeconds * 1000;
|
|
128
|
+
}
|
|
129
|
+
await sleep(retryAfterMilliseconds);
|
|
130
|
+
retryAfterMilliseconds *= consecutiveRetryDelayMultiplier;
|
|
131
|
+
attempts++; // Increment the attempt counter
|
|
132
|
+
}
|
|
133
|
+
if (attempts >= maxRetries) {
|
|
134
|
+
RequestFailedError.throw(`GraphAPI fetch exceed retry limit of ${maxRetries} attempts.`, args);
|
|
135
|
+
}
|
|
136
|
+
if (!response) {
|
|
137
|
+
throw new NeverError("Response is null. Should be impossible");
|
|
138
|
+
}
|
|
139
|
+
if (isHttpTooManyRequests(response.status)) {
|
|
140
|
+
RequestFailedError.throw("GraphAPI fetch failed after 3 retries due to too many requests.", args);
|
|
141
|
+
}
|
|
142
|
+
const replyContentType = response.headers.get("content-type")?.toLowerCase();
|
|
143
|
+
const body = replyContentType?.startsWith("application/json") ? await response.json() : null;
|
|
144
|
+
if (!isHttpOk(response.status)) {
|
|
145
|
+
const bodyError = body;
|
|
146
|
+
const errorMessage = bodyError?.error ? `[${bodyError.error.code}] ${bodyError.error.message}` : `HTTP ${response.status} ${response.statusText}`;
|
|
147
|
+
RequestFailedError.throw(`GraphAPI fetch failed: '${errorMessage}'`, args, body);
|
|
148
|
+
}
|
|
149
|
+
return body;
|
|
97
150
|
}
|
|
98
|
-
function
|
|
151
|
+
function normalizeBatchBody(contentType, body) {
|
|
99
152
|
if (contentType?.startsWith("application/json") && typeof body === "string") {
|
|
100
153
|
return JSON.parse(atob(body));
|
|
101
154
|
}
|
|
102
155
|
return body;
|
|
103
156
|
}
|
|
104
|
-
function
|
|
157
|
+
function normalizeBatchHeaders(input) {
|
|
105
158
|
const headers = {};
|
|
106
159
|
for (const key in input) {
|
|
107
160
|
if (input[key]) {
|
|
@@ -110,19 +163,9 @@ function normalizeHeaders(input) {
|
|
|
110
163
|
}
|
|
111
164
|
return headers;
|
|
112
165
|
}
|
|
113
|
-
function
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const contentType = headers["content-type"];
|
|
119
|
-
const body = normalizeBody(contentType, response.body);
|
|
120
|
-
const op = ops[index];
|
|
121
|
-
if (!op) {
|
|
122
|
-
throw new Error("Op not found. Should be impossible");
|
|
123
|
-
}
|
|
124
|
-
RequestFailedError.throwIfNotOkOperation(response.status, index, op, body);
|
|
125
|
-
results[index] = op.responseTransform(body);
|
|
126
|
-
}
|
|
127
|
-
return results; // TODO: Is there a neater way to massage the types correctly? This is functionally correct, but I do want to avoid using `unknown` here if possible.
|
|
166
|
+
function createAuthorizationHeader(accessToken) {
|
|
167
|
+
return `Bearer ${accessToken}`;
|
|
168
|
+
}
|
|
169
|
+
function headersToObject(obj) {
|
|
170
|
+
return Object.fromEntries(Object.entries(obj).filter(([_, v]) => v !== undefined));
|
|
128
171
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import InvalidArgumentError from "./errors/InvalidArgumentError.js";
|
|
2
|
+
import RequestFailedError from "./errors/RequestFailedError.js";
|
|
3
|
+
import { getCurrentAccessToken } from "./services/accessToken.js";
|
|
4
|
+
const authenticationScope = "https://graph.microsoft.com/.default";
|
|
5
|
+
const batchEndpoint = "https://graph.microsoft.com/v1.0/$batch";
|
|
6
|
+
const minBatchCalls = 1;
|
|
7
|
+
const maxBatchCalls = 20; // https://learn.microsoft.com/en-us/graph/json-batching?tabs=http#batch-size-limitations
|
|
8
|
+
/** Execute GraphAPI batch with up to 20 requests to be executed as a batch. */
|
|
9
|
+
export async function execute(...ops) {
|
|
10
|
+
const accessToken = await getCurrentAccessToken(authenticationScope);
|
|
11
|
+
if (ops.length < minBatchCalls || ops.length > maxBatchCalls) {
|
|
12
|
+
throw new InvalidArgumentError(`Requires at least ${minBatchCalls} and at most ${maxBatchCalls} calls`);
|
|
13
|
+
}
|
|
14
|
+
const response = await fetch(batchEndpoint, {
|
|
15
|
+
method: "POST",
|
|
16
|
+
headers: {
|
|
17
|
+
'authorization': `Bearer ${accessToken}`,
|
|
18
|
+
'accept': 'application/json',
|
|
19
|
+
'content-type': 'application/json'
|
|
20
|
+
},
|
|
21
|
+
body: JSON.stringify({
|
|
22
|
+
requests: ops.map((call, index) => ({
|
|
23
|
+
id: index.toString(),
|
|
24
|
+
method: call.method,
|
|
25
|
+
url: call.path,
|
|
26
|
+
headers: call.headers,
|
|
27
|
+
body: call.body,
|
|
28
|
+
dependsOn: call.dependsOn?.map((id) => id.toString())
|
|
29
|
+
}))
|
|
30
|
+
})
|
|
31
|
+
});
|
|
32
|
+
if (!response.ok) {
|
|
33
|
+
throw new RequestFailedError(`Batch request failed with status ${response.status}`);
|
|
34
|
+
}
|
|
35
|
+
const json = await response.json();
|
|
36
|
+
if (!json.responses) {
|
|
37
|
+
throw new RequestFailedError("Batch request did not return any responses");
|
|
38
|
+
}
|
|
39
|
+
const results = {};
|
|
40
|
+
for (const response of json.responses) {
|
|
41
|
+
if (response.status !== 200) {
|
|
42
|
+
const body = response.body;
|
|
43
|
+
throw new RequestFailedError(`[REQUEST INDEX: ${response.id} STATUS: ${response.status} CODE: ${body.code}]: ${body.message}`);
|
|
44
|
+
}
|
|
45
|
+
const index = Number.parseInt(response.id, 10);
|
|
46
|
+
results[index] = response.body;
|
|
47
|
+
}
|
|
48
|
+
return results;
|
|
49
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { execute } from "../graphApi.js";
|
|
2
|
+
import getSiteByName from "../operations/site/getSiteByName.js";
|
|
3
|
+
/** Convenience helper to get a reference to a site by name. Avoid using this however and code to siteId instead for a less brittle and performant result. */
|
|
4
|
+
export async function openSiteByName(hostName, siteName) {
|
|
5
|
+
const [site] = await execute(getSiteByName(hostName, siteName));
|
|
6
|
+
if (site.id === undefined) { // TODO: This may need to be refined on testing
|
|
7
|
+
throw new Error(`Site ${siteName} not found in host ${hostName}`);
|
|
8
|
+
}
|
|
9
|
+
return {
|
|
10
|
+
siteId: site.id,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { execute } from "../graphApi.js";
|
|
2
|
+
import createWorkbookSession from "../operations/workbookSession/createWorkbookSession.js";
|
|
3
|
+
import { defaultDriveId, defaultSiteId } from "../services/configuration.js";
|
|
4
|
+
/** Opinionated convenience helper to start a workbook session. Includes starting a session. */
|
|
5
|
+
export async function openWorkbook(workbookRef) {
|
|
6
|
+
const [session] = await execute(createWorkbookSession(workbookRef));
|
|
7
|
+
return {
|
|
8
|
+
...workbookRef,
|
|
9
|
+
sessionId: session.id,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export async function openWorkbookInDefaultDrive(itemId) {
|
|
13
|
+
const itemRef = {
|
|
14
|
+
siteId: defaultSiteId,
|
|
15
|
+
driveId: defaultDriveId,
|
|
16
|
+
itemId: itemId
|
|
17
|
+
};
|
|
18
|
+
const [session] = await execute(createWorkbookSession(itemRef));
|
|
19
|
+
return {
|
|
20
|
+
...itemRef,
|
|
21
|
+
sessionId: session.id,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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
|
+
}
|