microsoft-graph 3.7.2 → 3.8.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/dist/cjs/models/Address.d.ts +32 -1
- package/dist/cjs/models/Address.d.ts.map +1 -1
- package/dist/cjs/models/DriveItem.d.ts +6 -0
- package/dist/cjs/models/DriveItem.d.ts.map +1 -1
- package/dist/cjs/operations/driveItem/createDriveItem.d.ts +3 -0
- package/dist/cjs/operations/driveItem/createDriveItem.d.ts.map +1 -1
- package/dist/cjs/operations/driveItem/createDriveItem.js +3 -0
- package/dist/cjs/operations/driveItem/createDriveItemContent.d.ts +21 -0
- package/dist/cjs/operations/driveItem/createDriveItemContent.d.ts.map +1 -0
- package/dist/cjs/operations/driveItem/createDriveItemContent.js +122 -0
- package/dist/cjs/operations/driveItem/existsDriveItem.d.ts.map +1 -1
- package/dist/cjs/operations/driveItem/existsDriveItem.js +1 -2
- package/dist/cjs/operations/driveItem/getDriveItemContent.d.ts.map +1 -1
- package/dist/cjs/operations/driveItem/getDriveItemContent.js +2 -9
- package/dist/cjs/operations/driveItem/streamDriveItemContent.d.ts.map +1 -1
- package/dist/cjs/operations/driveItem/streamDriveItemContent.js +2 -9
- package/dist/cjs/services/http.d.ts +12 -2
- package/dist/cjs/services/http.d.ts.map +1 -1
- package/dist/cjs/services/http.js +207 -3
- package/dist/cjs/services/httpStatus.d.ts +6 -0
- package/dist/cjs/services/httpStatus.d.ts.map +1 -1
- package/dist/cjs/services/httpStatus.js +9 -0
- package/dist/cjs/services/operationInvoker.d.ts +0 -1
- package/dist/cjs/services/operationInvoker.d.ts.map +1 -1
- package/dist/cjs/services/operationInvoker.js +8 -207
- package/dist/cjs/services/usedAddress.d.ts +25 -0
- package/dist/cjs/services/usedAddress.d.ts.map +1 -0
- package/dist/cjs/services/usedAddress.js +69 -0
- package/dist/cjs/tasks/iterateDriveItems.d.ts.map +1 -1
- package/dist/cjs/tasks/iterateDriveItems.js +1 -2
- package/dist/cjs/tasks/iterateDrives.d.ts.map +1 -1
- package/dist/cjs/tasks/iterateDrives.js +1 -2
- package/dist/cjs/tasks/iterateSiteSearch.d.ts.map +1 -1
- package/dist/cjs/tasks/iterateSiteSearch.js +1 -2
- package/dist/cjs/tasks/iterateSites.d.ts.map +1 -1
- package/dist/cjs/tasks/iterateSites.js +1 -2
- package/dist/esm/models/Address.d.ts +32 -1
- package/dist/esm/models/Address.d.ts.map +1 -1
- package/dist/esm/models/DriveItem.d.ts +6 -0
- package/dist/esm/models/DriveItem.d.ts.map +1 -1
- package/dist/esm/operations/driveItem/createDriveItem.d.ts +3 -0
- package/dist/esm/operations/driveItem/createDriveItem.d.ts.map +1 -1
- package/dist/esm/operations/driveItem/createDriveItem.js +3 -0
- package/dist/esm/operations/driveItem/createDriveItemContent.d.ts +21 -0
- package/dist/esm/operations/driveItem/createDriveItemContent.d.ts.map +1 -0
- package/dist/esm/operations/driveItem/createDriveItemContent.js +116 -0
- package/dist/esm/operations/driveItem/existsDriveItem.d.ts.map +1 -1
- package/dist/esm/operations/driveItem/existsDriveItem.js +2 -3
- package/dist/esm/operations/driveItem/getDriveItemContent.d.ts.map +1 -1
- package/dist/esm/operations/driveItem/getDriveItemContent.js +4 -11
- package/dist/esm/operations/driveItem/streamDriveItemContent.d.ts.map +1 -1
- package/dist/esm/operations/driveItem/streamDriveItemContent.js +4 -11
- package/dist/esm/services/http.d.ts +12 -2
- package/dist/esm/services/http.d.ts.map +1 -1
- package/dist/esm/services/http.js +204 -2
- package/dist/esm/services/httpStatus.d.ts +6 -0
- package/dist/esm/services/httpStatus.d.ts.map +1 -1
- package/dist/esm/services/httpStatus.js +8 -0
- package/dist/esm/services/operationInvoker.d.ts +0 -1
- package/dist/esm/services/operationInvoker.d.ts.map +1 -1
- package/dist/esm/services/operationInvoker.js +10 -208
- package/dist/esm/services/usedAddress.d.ts +25 -0
- package/dist/esm/services/usedAddress.d.ts.map +1 -0
- package/dist/esm/services/usedAddress.js +63 -0
- package/dist/esm/tasks/iterateDriveItems.d.ts.map +1 -1
- package/dist/esm/tasks/iterateDriveItems.js +2 -3
- package/dist/esm/tasks/iterateDrives.d.ts.map +1 -1
- package/dist/esm/tasks/iterateDrives.js +2 -3
- package/dist/esm/tasks/iterateSiteSearch.d.ts.map +1 -1
- package/dist/esm/tasks/iterateSiteSearch.js +2 -3
- package/dist/esm/tasks/iterateSites.d.ts.map +1 -1
- package/dist/esm/tasks/iterateSites.js +2 -3
- package/docs/api/Address.md +99 -13
- package/docs/api/DriveItem-1.md +16 -0
- package/docs/api/README.md +2 -1
- package/docs/api/createDriveItemContent.md +37 -0
- package/docs/api/http.md +65 -4
- package/docs/api/httpStatus.md +48 -26
- package/docs/api/operationInvoker.md +3 -22
- package/docs/api/services/usedAddress.md +47 -0
- package/docs/api/streamDriveItemContent.md +1 -1
- package/package.json +21 -1
- package/docs/api/createDriveItem.md +0 -38
|
@@ -13,6 +13,12 @@ export type ColumnAddress = `${Uppercase<string>}`;
|
|
|
13
13
|
* @example 'C:D'
|
|
14
14
|
*/
|
|
15
15
|
export type ColumnRangeAddress = `${CellAddress}:${CellAddress}`;
|
|
16
|
+
/**
|
|
17
|
+
* Address of a used range in a column, either from the start or to the end.
|
|
18
|
+
* @example 'C:'
|
|
19
|
+
* @example ':D'
|
|
20
|
+
*/
|
|
21
|
+
export type UsedColumnRangeAddress = `${ColumnAddress}:` | `:${ColumnAddress}`;
|
|
16
22
|
/**
|
|
17
23
|
* Address of a single row in a worksheet.
|
|
18
24
|
* @example '3'
|
|
@@ -23,6 +29,12 @@ export type RowAddress = `${number}`;
|
|
|
23
29
|
* @example '3:5'
|
|
24
30
|
*/
|
|
25
31
|
export type RowRangeAddress = `${RowAddress}:${RowAddress}`;
|
|
32
|
+
/**
|
|
33
|
+
* Address of a used range in a row, either from the start or to the end.
|
|
34
|
+
* @example '3:'
|
|
35
|
+
* @example ':5'
|
|
36
|
+
*/
|
|
37
|
+
export type UsedRowRangeAddress = `${RowAddress}:` | `:${RowAddress}`;
|
|
26
38
|
/**
|
|
27
39
|
* Address of a single cell in a worksheet.
|
|
28
40
|
* @example 'C3'
|
|
@@ -33,14 +45,33 @@ export type CellAddress = `${ColumnAddress}${RowAddress}`;
|
|
|
33
45
|
* @example 'C3:D5'
|
|
34
46
|
*/
|
|
35
47
|
export type CellRangeAddress = `${CellAddress}:${CellAddress}`;
|
|
48
|
+
/**
|
|
49
|
+
* Address of a used range in a cell, either from the start or to the end.
|
|
50
|
+
* @example 'C3:'
|
|
51
|
+
* @example ':D5'
|
|
52
|
+
*/
|
|
53
|
+
export type UsedCellRangeAddress = `${CellAddress}:` | `:${CellAddress}`;
|
|
54
|
+
/**
|
|
55
|
+
* Address representing the entire used range in a worksheet.
|
|
56
|
+
* @example ':'
|
|
57
|
+
*/
|
|
58
|
+
export type AllUsedAddress = ":";
|
|
36
59
|
/**
|
|
37
60
|
* Any type of address.
|
|
38
61
|
* @remarks This is a union of all the address types defined above.
|
|
39
62
|
* @example 'C', 'C:D', '3', '3:5', 'C3', 'C3:D5'
|
|
40
63
|
*/
|
|
41
|
-
export type Address = ColumnAddress |
|
|
64
|
+
export type Address = ColumnAddress | ColumnRangeAddress | RowAddress | RowRangeAddress | CellAddress | CellRangeAddress;
|
|
65
|
+
/**
|
|
66
|
+
* Any type of used range address, including entire, column, row, or cell used ranges.
|
|
67
|
+
*/
|
|
68
|
+
export type UsedAddress = AllUsedAddress | UsedColumnRangeAddress | UsedRowRangeAddress | UsedCellRangeAddress;
|
|
42
69
|
/**
|
|
43
70
|
* Address when decomposed into its components.
|
|
71
|
+
* @property startColumn - The starting column address.
|
|
72
|
+
* @property endColumn - The ending column address.
|
|
73
|
+
* @property startRow - The starting row address.
|
|
74
|
+
* @property endRow - The ending row address.
|
|
44
75
|
*/
|
|
45
76
|
export type DecomposedAddress = {
|
|
46
77
|
startColumn: ColumnAddress;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Address.d.ts","sourceRoot":"","sources":["../../../src/models/Address.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,GAAG,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;AAEnD;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,GAAG,WAAW,IAAI,WAAW,EAAE,CAAC;AAEjE;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,GAAG,MAAM,EAAE,CAAC;AAErC;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,GAAG,UAAU,IAAI,UAAU,EAAE,CAAC;AAE5D;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,GAAG,aAAa,GAAG,UAAU,EAAE,CAAC;AAE1D;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,GAAG,WAAW,IAAI,WAAW,EAAE,CAAC;AAE/D;;;;GAIG;AACH,MAAM,MAAM,OAAO,GAAG,aAAa,GAAG,
|
|
1
|
+
{"version":3,"file":"Address.d.ts","sourceRoot":"","sources":["../../../src/models/Address.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,GAAG,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;AAEnD;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,GAAG,WAAW,IAAI,WAAW,EAAE,CAAC;AAEjE;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,GAAG,GAAG,aAAa,GAAG,GAAG,IAAI,aAAa,EAAE,CAAC;AAE/E;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,GAAG,MAAM,EAAE,CAAC;AAErC;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,GAAG,UAAU,IAAI,UAAU,EAAE,CAAC;AAE5D;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,GAAG,UAAU,GAAG,GAAG,IAAI,UAAU,EAAE,CAAC;AAEtE;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,GAAG,aAAa,GAAG,UAAU,EAAE,CAAC;AAE1D;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,GAAG,WAAW,IAAI,WAAW,EAAE,CAAC;AAE/D;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG,GAAG,WAAW,GAAG,GAAG,IAAI,WAAW,EAAE,CAAC;AAEzE;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,GAAG,CAAC;AACjC;;;;GAIG;AACH,MAAM,MAAM,OAAO,GAAG,aAAa,GAAG,kBAAkB,GAAG,UAAU,GAAG,eAAe,GAAG,WAAW,GAAG,gBAAgB,CAAC;AAEzH;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,cAAc,GAAG,sBAAsB,GAAG,mBAAmB,GAAG,oBAAoB,CAAC;AAE/G;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC/B,WAAW,EAAE,aAAa,CAAC;IAC3B,SAAS,EAAE,aAAa,CAAC;IACzB,QAAQ,EAAE,UAAU,CAAC;IACrB,MAAM,EAAE,UAAU,CAAC;CACnB,CAAC"}
|
|
@@ -22,4 +22,10 @@ export type DriveItemPath = string & {
|
|
|
22
22
|
export type DriveItemRef = DriveRef & {
|
|
23
23
|
itemId: DriveItemId;
|
|
24
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* File/folder name of a drive item. Includes file extension if applicable.
|
|
27
|
+
*/
|
|
28
|
+
export type DriveItemName = string & {
|
|
29
|
+
__brand: "DriveItemName";
|
|
30
|
+
};
|
|
25
31
|
//# sourceMappingURL=DriveItem.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DriveItem.d.ts","sourceRoot":"","sources":["../../../src/models/DriveItem.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG;IAClC,OAAO,EAAE,aAAa,CAAC;CACvB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG;IACpC,OAAO,EAAE,eAAe,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG;IACrC,MAAM,EAAE,WAAW,CAAC;CACpB,CAAC"}
|
|
1
|
+
{"version":3,"file":"DriveItem.d.ts","sourceRoot":"","sources":["../../../src/models/DriveItem.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG;IAClC,OAAO,EAAE,aAAa,CAAC;CACvB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG;IACpC,OAAO,EAAE,eAAe,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG;IACrC,MAAM,EAAE,WAAW,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG;IACpC,OAAO,EAAE,eAAe,CAAC;CACzB,CAAC"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Creates new drive item in the specified parent drive or folder.
|
|
3
3
|
* @module createDriveItem
|
|
4
4
|
* @category Operations
|
|
5
|
+
* @hidden
|
|
5
6
|
*/
|
|
6
7
|
import type { DriveItem } from "@microsoft/microsoft-graph-types";
|
|
7
8
|
import type { DriveRef } from "../../models/Drive.ts";
|
|
@@ -14,6 +15,8 @@ import type { GraphOperation } from "../../models/GraphOperation.ts";
|
|
|
14
15
|
* @returns The newly created drive item.
|
|
15
16
|
* @remarks If the file already exists, it will be replaced.
|
|
16
17
|
* @see https://learn.microsoft.com/en-us/graph/api/driveitem-put-content
|
|
18
|
+
* @deprecated Use {@link createDriveItemContent} instead for uploading content.
|
|
19
|
+
* @hidden
|
|
17
20
|
*/
|
|
18
21
|
export default function createDriveItem(parentRef: DriveRef | DriveItemRef, itemPath: DriveItemPath, contextType: string, content: ArrayBuffer): GraphOperation<DriveItem & DriveItemRef>;
|
|
19
22
|
//# sourceMappingURL=createDriveItem.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDriveItem.d.ts","sourceRoot":"","sources":["../../../../src/operations/driveItem/createDriveItem.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"createDriveItem.d.ts","sourceRoot":"","sources":["../../../../src/operations/driveItem/createDriveItem.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAe,aAAa,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC1F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAKrE;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,SAAS,EAAE,QAAQ,GAAG,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,cAAc,CAAC,SAAS,GAAG,YAAY,CAAC,CAsBxL"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Creates new drive item in the specified parent drive or folder.
|
|
4
4
|
* @module createDriveItem
|
|
5
5
|
* @category Operations
|
|
6
|
+
* @hidden
|
|
6
7
|
*/
|
|
7
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
9
|
exports.default = createDriveItem;
|
|
@@ -16,6 +17,8 @@ const templatedPaths_ts_1 = require("../../services/templatedPaths.js");
|
|
|
16
17
|
* @returns The newly created drive item.
|
|
17
18
|
* @remarks If the file already exists, it will be replaced.
|
|
18
19
|
* @see https://learn.microsoft.com/en-us/graph/api/driveitem-put-content
|
|
20
|
+
* @deprecated Use {@link createDriveItemContent} instead for uploading content.
|
|
21
|
+
* @hidden
|
|
19
22
|
*/
|
|
20
23
|
function createDriveItem(parentRef, itemPath, contextType, content) {
|
|
21
24
|
const pathSegment = parentRef.itemId ? "items/{item-id}" : "root";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new drive item in the specified parent drive or folder using a stream as content.
|
|
3
|
+
* @module createDriveItemContent
|
|
4
|
+
* @category Operations
|
|
5
|
+
*/
|
|
6
|
+
import type { DriveItem } from "@microsoft/microsoft-graph-types";
|
|
7
|
+
import type { DriveRef } from "../../models/Drive.ts";
|
|
8
|
+
import type { DriveItemPath, DriveItemRef } from "../../models/DriveItem.ts";
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new drive item in the specified parent drive or folder using a stream as content.
|
|
11
|
+
* @param parentRef Reference to the parent drive or folder where the drive item will be created.
|
|
12
|
+
* @param itemPath Path (including the filename) for the new drive item within the given parent.
|
|
13
|
+
* @param contentStream A Node.js readable stream containing the file content.
|
|
14
|
+
* @param totalSize The total size in bytes of the content to be uploaded.
|
|
15
|
+
* @param conflictBehavior Optional. Specifies how to handle conflicts if the file already exists. Default is 'fail'.
|
|
16
|
+
* @returns The newly created drive item.
|
|
17
|
+
* @see https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession
|
|
18
|
+
* @see https://learn.microsoft.com/en-us/graph/api/resources/uploadsession
|
|
19
|
+
*/
|
|
20
|
+
export default function createDriveItemContent(parentRef: DriveRef | DriveItemRef, itemPath: DriveItemPath, contentStream: NodeJS.ReadableStream, totalSize: number, conflictBehavior?: "fail" | "replace" | "rename", chunkSize?: number): Promise<DriveItem & DriveItemRef>;
|
|
21
|
+
//# sourceMappingURL=createDriveItemContent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createDriveItemContent.d.ts","sourceRoot":"","sources":["../../../../src/operations/driveItem/createDriveItemContent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAElE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAe,aAAa,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAkB1F;;;;;;;;;;GAUG;AACH,wBAA8B,sBAAsB,CAAC,SAAS,EAAE,QAAQ,GAAG,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,CAAC,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,gBAAgB,GAAE,MAAM,GAAG,SAAS,GAAG,QAAiB,EAAE,SAAS,SAAmB,GAAG,OAAO,CAAC,SAAS,GAAG,YAAY,CAAC,CAmGpS"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new drive item in the specified parent drive or folder using a stream as content.
|
|
4
|
+
* @module createDriveItemContent
|
|
5
|
+
* @category Operations
|
|
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 = createDriveItemContent;
|
|
12
|
+
const ProtocolError_ts_1 = __importDefault(require("../../errors/ProtocolError.js"));
|
|
13
|
+
const driveItem_ts_1 = require("../../services/driveItem.js");
|
|
14
|
+
const http_ts_1 = require("../../services/http.js");
|
|
15
|
+
const operationInvoker_ts_1 = require("../../services/operationInvoker.js");
|
|
16
|
+
const templatedPaths_ts_1 = require("../../services/templatedPaths.js");
|
|
17
|
+
const defaultChunkSize = 10 * 1024 * 1024;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new drive item in the specified parent drive or folder using a stream as content.
|
|
20
|
+
* @param parentRef Reference to the parent drive or folder where the drive item will be created.
|
|
21
|
+
* @param itemPath Path (including the filename) for the new drive item within the given parent.
|
|
22
|
+
* @param contentStream A Node.js readable stream containing the file content.
|
|
23
|
+
* @param totalSize The total size in bytes of the content to be uploaded.
|
|
24
|
+
* @param conflictBehavior Optional. Specifies how to handle conflicts if the file already exists. Default is 'fail'.
|
|
25
|
+
* @returns The newly created drive item.
|
|
26
|
+
* @see https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession
|
|
27
|
+
* @see https://learn.microsoft.com/en-us/graph/api/resources/uploadsession
|
|
28
|
+
*/
|
|
29
|
+
async function createDriveItemContent(parentRef, itemPath, contentStream, totalSize, conflictBehavior = "fail", chunkSize = defaultChunkSize) {
|
|
30
|
+
const pathSegment = parentRef.itemId ? "items/{item-id}" : "root";
|
|
31
|
+
const uploadSessionUrl = `${operationInvoker_ts_1.endpoint}${(0, templatedPaths_ts_1.generatePath)(`/sites/{site-id}/drives/{drive-id}/${pathSegment}:/${itemPath}:/createUploadSession`, parentRef)}`;
|
|
32
|
+
const accessToken = await parentRef.context.generateAccessToken();
|
|
33
|
+
const fileName = itemPath.split("/").pop();
|
|
34
|
+
const { uploadUrl } = await (0, http_ts_1.execute)({
|
|
35
|
+
url: uploadSessionUrl,
|
|
36
|
+
method: "POST",
|
|
37
|
+
headers: {
|
|
38
|
+
authorization: `Bearer ${accessToken}`,
|
|
39
|
+
"content-type": "application/json",
|
|
40
|
+
},
|
|
41
|
+
data: JSON.stringify({
|
|
42
|
+
item: {
|
|
43
|
+
"@microsoft.graph.conflictBehavior": conflictBehavior,
|
|
44
|
+
name: fileName,
|
|
45
|
+
},
|
|
46
|
+
}),
|
|
47
|
+
responseType: "json",
|
|
48
|
+
});
|
|
49
|
+
let position = 0;
|
|
50
|
+
let driveItem = null;
|
|
51
|
+
let streamEnded = false;
|
|
52
|
+
const chunks = [];
|
|
53
|
+
contentStream.on("data", (chunk) => {
|
|
54
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
55
|
+
});
|
|
56
|
+
contentStream.on("end", () => {
|
|
57
|
+
streamEnded = true;
|
|
58
|
+
});
|
|
59
|
+
contentStream.on("error", () => {
|
|
60
|
+
// error will be handled in readChunk
|
|
61
|
+
});
|
|
62
|
+
let chunk = await readChunk();
|
|
63
|
+
while (chunk !== null) {
|
|
64
|
+
let currentChunk = chunk;
|
|
65
|
+
while (currentChunk.length > 0) {
|
|
66
|
+
const thisChunk = currentChunk.subarray(0, chunkSize);
|
|
67
|
+
const start = position;
|
|
68
|
+
const end = position + thisChunk.length - 1;
|
|
69
|
+
const contentRange = `bytes ${start}-${end}/${totalSize}`;
|
|
70
|
+
const res = await (0, http_ts_1.execute)({
|
|
71
|
+
url: uploadUrl,
|
|
72
|
+
method: "PUT",
|
|
73
|
+
headers: {
|
|
74
|
+
"Content-Length": thisChunk.length.toString(),
|
|
75
|
+
"Content-Range": contentRange,
|
|
76
|
+
},
|
|
77
|
+
data: thisChunk,
|
|
78
|
+
responseType: "json",
|
|
79
|
+
});
|
|
80
|
+
position += thisChunk.length;
|
|
81
|
+
currentChunk = currentChunk.subarray(chunkSize);
|
|
82
|
+
if (isDriveItem(res)) {
|
|
83
|
+
driveItem = res;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (driveItem)
|
|
88
|
+
break;
|
|
89
|
+
chunk = await readChunk();
|
|
90
|
+
}
|
|
91
|
+
if (!driveItem) {
|
|
92
|
+
throw new ProtocolError_ts_1.default(`Upload did not complete successfully. Last position: ${position}`);
|
|
93
|
+
}
|
|
94
|
+
const itemRef = (0, driveItem_ts_1.createDriveItemRef)(parentRef, driveItem.id);
|
|
95
|
+
return {
|
|
96
|
+
...driveItem,
|
|
97
|
+
...itemRef,
|
|
98
|
+
};
|
|
99
|
+
function isDriveItem(obj) {
|
|
100
|
+
return typeof obj === "object" && obj !== null && "id" in obj;
|
|
101
|
+
}
|
|
102
|
+
function readChunk() {
|
|
103
|
+
return new Promise((resolve, reject) => {
|
|
104
|
+
if (chunks.length > 0) {
|
|
105
|
+
const next = chunks.shift();
|
|
106
|
+
return resolve(next ?? null);
|
|
107
|
+
}
|
|
108
|
+
if (streamEnded)
|
|
109
|
+
return resolve(null);
|
|
110
|
+
contentStream.once("data", (chunk) => {
|
|
111
|
+
resolve(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
112
|
+
});
|
|
113
|
+
contentStream.once("end", () => {
|
|
114
|
+
streamEnded = true;
|
|
115
|
+
resolve(null);
|
|
116
|
+
});
|
|
117
|
+
contentStream.once("error", (err) => {
|
|
118
|
+
reject(err);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"existsDriveItem.d.ts","sourceRoot":"","sources":["../../../../src/operations/driveItem/existsDriveItem.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAM/D;;;;GAIG;AACH,wBAA8B,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"existsDriveItem.d.ts","sourceRoot":"","sources":["../../../../src/operations/driveItem/existsDriveItem.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAM/D;;;;GAIG;AACH,wBAA8B,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,CAsB3G"}
|
|
@@ -19,13 +19,12 @@ async function existsDriveItem(driveRef, itemPath) {
|
|
|
19
19
|
// Note this method doesn't match the standard pattern since the batching library doesn't support non-JSON return types.
|
|
20
20
|
const url = `${operationInvoker_ts_1.endpoint}${(0, templatedPaths_ts_1.generatePath)(`/sites/{site-id}/drives/{drive-id}/root:${itemPath}`, driveRef)}`;
|
|
21
21
|
const accessToken = await driveRef.context.generateAccessToken();
|
|
22
|
-
const response = await (0, http_ts_1.
|
|
22
|
+
const response = await (0, http_ts_1.executeRaw)({
|
|
23
23
|
url,
|
|
24
24
|
method: "GET",
|
|
25
25
|
headers: {
|
|
26
26
|
authorization: `Bearer ${accessToken}`,
|
|
27
27
|
},
|
|
28
|
-
validateStatus: () => true,
|
|
29
28
|
});
|
|
30
29
|
if ((0, httpStatus_ts_1.isHttpOk)(response.status)) {
|
|
31
30
|
return true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDriveItemContent.d.ts","sourceRoot":"","sources":["../../../../src/operations/driveItem/getDriveItemContent.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"getDriveItemContent.d.ts","sourceRoot":"","sources":["../../../../src/operations/driveItem/getDriveItemContent.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAK9D;;;;;;;;;GASG;AACH,wBAA8B,mBAAmB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,CAqB7F"}
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.default = getDriveItemContent;
|
|
10
10
|
const http_ts_1 = require("../../services/http.js");
|
|
11
|
-
const httpStatus_ts_1 = require("../../services/httpStatus.js");
|
|
12
11
|
const operationInvoker_ts_1 = require("../../services/operationInvoker.js");
|
|
13
12
|
const templatedPaths_ts_1 = require("../../services/templatedPaths.js");
|
|
14
13
|
/**
|
|
@@ -25,7 +24,7 @@ async function getDriveItemContent(itemRef) {
|
|
|
25
24
|
// Note this method doesn't match the standard pattern since the batching library doesn't support non-JSON return types, and there appears to be no value in adding support.
|
|
26
25
|
const url = `${operationInvoker_ts_1.endpoint}${(0, templatedPaths_ts_1.generatePath)("/sites/{site-id}/drives/{drive-id}/items/{item-id}/content", itemRef)}`;
|
|
27
26
|
const accessToken = await itemRef.context.generateAccessToken();
|
|
28
|
-
const response = await (0, http_ts_1.
|
|
27
|
+
const response = await (0, http_ts_1.execute)({
|
|
29
28
|
url,
|
|
30
29
|
method: "GET",
|
|
31
30
|
headers: {
|
|
@@ -33,13 +32,7 @@ async function getDriveItemContent(itemRef) {
|
|
|
33
32
|
},
|
|
34
33
|
responseType: "arraybuffer",
|
|
35
34
|
});
|
|
36
|
-
|
|
37
|
-
(0, operationInvoker_ts_1.throwException)(response.status, "Failed to get content");
|
|
38
|
-
}
|
|
39
|
-
if (!Buffer.isBuffer(response.data)) {
|
|
40
|
-
throw new Error(`Unexpected response type: ${typeof response.data}`);
|
|
41
|
-
}
|
|
42
|
-
const buffer = response.data.buffer.slice(response.data.byteOffset, response.data.byteOffset + response.data.byteLength);
|
|
35
|
+
const buffer = response.buffer.slice(response.byteOffset, response.byteOffset + response.byteLength);
|
|
43
36
|
if (!(buffer instanceof ArrayBuffer)) {
|
|
44
37
|
throw new Error("Failed to convert Buffer to ArrayBuffer");
|
|
45
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streamDriveItemContent.d.ts","sourceRoot":"","sources":["../../../../src/operations/driveItem/streamDriveItemContent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"streamDriveItemContent.d.ts","sourceRoot":"","sources":["../../../../src/operations/driveItem/streamDriveItemContent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAK9D;;;;;;;GAOG;AACH,wBAA8B,sBAAsB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAe1G"}
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.default = streamDriveItemContent;
|
|
9
9
|
const http_ts_1 = require("../../services/http.js");
|
|
10
|
-
const httpStatus_ts_1 = require("../../services/httpStatus.js");
|
|
11
10
|
const operationInvoker_ts_1 = require("../../services/operationInvoker.js");
|
|
12
11
|
const templatedPaths_ts_1 = require("../../services/templatedPaths.js");
|
|
13
12
|
/**
|
|
@@ -22,7 +21,7 @@ async function streamDriveItemContent(itemRef) {
|
|
|
22
21
|
// TODO: Rename to getDriveItemContent at next breaking update
|
|
23
22
|
const url = `${operationInvoker_ts_1.endpoint}${(0, templatedPaths_ts_1.generatePath)("/sites/{site-id}/drives/{drive-id}/items/{item-id}/content", itemRef)}`;
|
|
24
23
|
const accessToken = await itemRef.context.generateAccessToken();
|
|
25
|
-
const response = await (0, http_ts_1.
|
|
24
|
+
const response = await (0, http_ts_1.execute)({
|
|
26
25
|
url,
|
|
27
26
|
method: "GET",
|
|
28
27
|
headers: {
|
|
@@ -30,11 +29,5 @@ async function streamDriveItemContent(itemRef) {
|
|
|
30
29
|
},
|
|
31
30
|
responseType: "stream",
|
|
32
31
|
});
|
|
33
|
-
|
|
34
|
-
(0, operationInvoker_ts_1.throwException)(response.status, "Failed to stream content");
|
|
35
|
-
}
|
|
36
|
-
if (!response || typeof response.data?.pipe !== "function") {
|
|
37
|
-
throw new Error("Failed to get a streamable response");
|
|
38
|
-
}
|
|
39
|
-
return response.data;
|
|
32
|
+
return response;
|
|
40
33
|
}
|
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
* @module http
|
|
4
4
|
* @category Services
|
|
5
5
|
*/
|
|
6
|
-
import { type
|
|
7
|
-
|
|
6
|
+
import { type AxiosResponse, type RawAxiosRequestHeaders, type ResponseType } from "axios";
|
|
7
|
+
import type { HttpMethod } from "../models/Http.ts";
|
|
8
|
+
export type Request = {
|
|
9
|
+
url: string;
|
|
10
|
+
method: HttpMethod;
|
|
11
|
+
headers?: RawAxiosRequestHeaders;
|
|
12
|
+
data?: unknown;
|
|
13
|
+
responseType?: ResponseType;
|
|
14
|
+
};
|
|
15
|
+
export declare function execute<TResponse>(request: Request): Promise<TResponse>;
|
|
16
|
+
export declare function throwHttpException(responseCode: number, message: string): never;
|
|
17
|
+
export declare function executeRaw(request: Request): Promise<AxiosResponse<any, any>>;
|
|
8
18
|
//# sourceMappingURL=http.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/services/http.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/services/http.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAc,EAA+C,KAAK,aAAa,EAA4B,KAAK,sBAAsB,EAAE,KAAK,YAAY,EAAE,MAAM,OAAO,CAAC;AA0BzK,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAkCpD,MAAM,MAAM,OAAO,GAAG;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,CAAC,EAAE,sBAAsB,CAAC;IACjC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,YAAY,CAAC,EAAE,YAAY,CAAC;CAC5B,CAAC;AAEF,wBAAsB,OAAO,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAkD7E;AAED,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,KAAK,CAwE/E;AAID,wBAAsB,UAAU,CAAC,OAAO,EAAE,OAAO,oCAMhD"}
|
|
@@ -8,15 +8,164 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
8
8
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
9
|
};
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.
|
|
11
|
+
exports.execute = execute;
|
|
12
|
+
exports.throwHttpException = throwHttpException;
|
|
13
|
+
exports.executeRaw = executeRaw;
|
|
12
14
|
const axios_1 = __importDefault(require("axios"));
|
|
13
15
|
const https_proxy_agent_1 = require("https-proxy-agent");
|
|
16
|
+
const BadRequestError_ts_1 = __importDefault(require("../errors/BadRequestError.js"));
|
|
17
|
+
const BandwidthLimitExceededError_ts_1 = __importDefault(require("../errors/BandwidthLimitExceededError.js"));
|
|
18
|
+
const ConflictError_ts_1 = __importDefault(require("../errors/ConflictError.js"));
|
|
19
|
+
const ForbiddenError_ts_1 = __importDefault(require("../errors/ForbiddenError.js"));
|
|
20
|
+
const GatewayTimeoutError_ts_1 = __importDefault(require("../errors/GatewayTimeoutError.js"));
|
|
21
|
+
const GoneError_ts_1 = __importDefault(require("../errors/GoneError.js"));
|
|
22
|
+
const InsufficientStorageError_ts_1 = __importDefault(require("../errors/InsufficientStorageError.js"));
|
|
23
|
+
const InternalServerError_ts_1 = __importDefault(require("../errors/InternalServerError.js"));
|
|
24
|
+
const LengthRequiredError_ts_1 = __importDefault(require("../errors/LengthRequiredError.js"));
|
|
25
|
+
const LockedError_ts_1 = __importDefault(require("../errors/LockedError.js"));
|
|
26
|
+
const MethodNotAllowedError_ts_1 = __importDefault(require("../errors/MethodNotAllowedError.js"));
|
|
27
|
+
const NeverError_ts_1 = __importDefault(require("../errors/NeverError.js"));
|
|
28
|
+
const NotAcceptableError_ts_1 = __importDefault(require("../errors/NotAcceptableError.js"));
|
|
29
|
+
const NotFoundError_ts_1 = __importDefault(require("../errors/NotFoundError.js"));
|
|
30
|
+
const NotImplementedError_ts_1 = __importDefault(require("../errors/NotImplementedError.js"));
|
|
31
|
+
const PaymentRequiredError_ts_1 = __importDefault(require("../errors/PaymentRequiredError.js"));
|
|
32
|
+
const PreconditionFailedError_ts_1 = __importDefault(require("../errors/PreconditionFailedError.js"));
|
|
33
|
+
const RequestedRangeNotSatisfiableError_ts_1 = __importDefault(require("../errors/RequestedRangeNotSatisfiableError.js"));
|
|
34
|
+
const RequestEntityTooLargeError_ts_1 = __importDefault(require("../errors/RequestEntityTooLargeError.js"));
|
|
35
|
+
const ServiceUnavailableError_ts_1 = __importDefault(require("../errors/ServiceUnavailableError.js"));
|
|
36
|
+
const TooManyRequestsError_ts_1 = __importDefault(require("../errors/TooManyRequestsError.js"));
|
|
37
|
+
const UnauthorizedError_ts_1 = __importDefault(require("../errors/UnauthorizedError.js"));
|
|
38
|
+
const UnprocessableEntityError_ts_1 = __importDefault(require("../errors/UnprocessableEntityError.js"));
|
|
39
|
+
const UnsupportedMediaTypeError_ts_1 = __importDefault(require("../errors/UnsupportedMediaTypeError.js"));
|
|
40
|
+
const httpStatus_ts_1 = require("./httpStatus.js");
|
|
41
|
+
const sleep_ts_1 = require("./sleep.js");
|
|
42
|
+
const maxRetries = 3;
|
|
43
|
+
const defaultRetryDelayMilliseconds = 1000;
|
|
44
|
+
const consecutiveRetryDelayMultiplier = 2;
|
|
45
|
+
async function execute(request) {
|
|
46
|
+
let retryAfterMilliseconds = defaultRetryDelayMilliseconds;
|
|
47
|
+
let response = null;
|
|
48
|
+
let attempts = 0;
|
|
49
|
+
let errorLog = "";
|
|
50
|
+
while (true) {
|
|
51
|
+
try {
|
|
52
|
+
response = await executeRaw(request);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
const message = error instanceof Error ? error.message : error?.toString() || "Unknown error";
|
|
56
|
+
response = {
|
|
57
|
+
status: -1,
|
|
58
|
+
statusText: message,
|
|
59
|
+
headers: {},
|
|
60
|
+
data: null,
|
|
61
|
+
config: request,
|
|
62
|
+
request: null,
|
|
63
|
+
};
|
|
64
|
+
errorLog += message;
|
|
65
|
+
}
|
|
66
|
+
errorLog += requestToString(request);
|
|
67
|
+
errorLog += responseToString(response);
|
|
68
|
+
attempts++;
|
|
69
|
+
if ((0, httpStatus_ts_1.isHttpSuccess)(response.status) || !(0, httpStatus_ts_1.isRetryable)(response.status) || attempts === maxRetries) {
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
const requestedRetryAfterSeconds = Number.parseInt(response.headers["retry-after"] ?? "0", 10);
|
|
73
|
+
if (requestedRetryAfterSeconds) {
|
|
74
|
+
retryAfterMilliseconds = requestedRetryAfterSeconds * 1000;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
retryAfterMilliseconds += Math.random() * 1000; // Add some randomness to the retry delay to avoid thundering herd problem
|
|
78
|
+
}
|
|
79
|
+
errorLog += waitToString(retryAfterMilliseconds);
|
|
80
|
+
await (0, sleep_ts_1.sleep)(retryAfterMilliseconds);
|
|
81
|
+
retryAfterMilliseconds *= consecutiveRetryDelayMultiplier;
|
|
82
|
+
}
|
|
83
|
+
if (!response) {
|
|
84
|
+
throw new NeverError_ts_1.default("Response is empty.");
|
|
85
|
+
}
|
|
86
|
+
if (!(0, httpStatus_ts_1.isHttpSuccess)(response.status)) {
|
|
87
|
+
handleResponseError(response, errorLog, attempts);
|
|
88
|
+
}
|
|
89
|
+
return response.data;
|
|
90
|
+
}
|
|
91
|
+
function throwHttpException(responseCode, message) {
|
|
92
|
+
if ((0, httpStatus_ts_1.isHttpBadRequest)(responseCode)) {
|
|
93
|
+
throw new BadRequestError_ts_1.default(message);
|
|
94
|
+
}
|
|
95
|
+
if ((0, httpStatus_ts_1.isHttpUnauthorized)(responseCode)) {
|
|
96
|
+
throw new UnauthorizedError_ts_1.default(message);
|
|
97
|
+
}
|
|
98
|
+
if ((0, httpStatus_ts_1.isHttpPaymentRequired)(responseCode)) {
|
|
99
|
+
throw new PaymentRequiredError_ts_1.default(message);
|
|
100
|
+
}
|
|
101
|
+
if ((0, httpStatus_ts_1.isHttpForbidden)(responseCode)) {
|
|
102
|
+
throw new ForbiddenError_ts_1.default(message);
|
|
103
|
+
}
|
|
104
|
+
if ((0, httpStatus_ts_1.isHttpNotFound)(responseCode)) {
|
|
105
|
+
throw new NotFoundError_ts_1.default(message);
|
|
106
|
+
}
|
|
107
|
+
if ((0, httpStatus_ts_1.isHttpMethodNotAllowed)(responseCode)) {
|
|
108
|
+
throw new MethodNotAllowedError_ts_1.default(message);
|
|
109
|
+
}
|
|
110
|
+
if ((0, httpStatus_ts_1.isHttpNotAcceptable)(responseCode)) {
|
|
111
|
+
throw new NotAcceptableError_ts_1.default(message);
|
|
112
|
+
}
|
|
113
|
+
if ((0, httpStatus_ts_1.isHttpConflict)(responseCode)) {
|
|
114
|
+
throw new ConflictError_ts_1.default(message);
|
|
115
|
+
}
|
|
116
|
+
if ((0, httpStatus_ts_1.isHttpGone)(responseCode)) {
|
|
117
|
+
throw new GoneError_ts_1.default(message);
|
|
118
|
+
}
|
|
119
|
+
if ((0, httpStatus_ts_1.isHttpLengthRequired)(responseCode)) {
|
|
120
|
+
throw new LengthRequiredError_ts_1.default(message);
|
|
121
|
+
}
|
|
122
|
+
if ((0, httpStatus_ts_1.isHttpPreconditionFailed)(responseCode)) {
|
|
123
|
+
throw new PreconditionFailedError_ts_1.default(message);
|
|
124
|
+
}
|
|
125
|
+
if ((0, httpStatus_ts_1.isHttpRequestEntityTooLarge)(responseCode)) {
|
|
126
|
+
throw new RequestEntityTooLargeError_ts_1.default(message);
|
|
127
|
+
}
|
|
128
|
+
if ((0, httpStatus_ts_1.isHttpUnsupportedMediaType)(responseCode)) {
|
|
129
|
+
throw new UnsupportedMediaTypeError_ts_1.default(message);
|
|
130
|
+
}
|
|
131
|
+
if ((0, httpStatus_ts_1.isHttpRequestedRangeNotSatisfiable)(responseCode)) {
|
|
132
|
+
throw new RequestedRangeNotSatisfiableError_ts_1.default(message);
|
|
133
|
+
}
|
|
134
|
+
if ((0, httpStatus_ts_1.isHttpUnprocessableEntity)(responseCode)) {
|
|
135
|
+
throw new UnprocessableEntityError_ts_1.default(message);
|
|
136
|
+
}
|
|
137
|
+
if ((0, httpStatus_ts_1.isHttpLocked)(responseCode)) {
|
|
138
|
+
throw new LockedError_ts_1.default(message);
|
|
139
|
+
}
|
|
140
|
+
if ((0, httpStatus_ts_1.isHttpTooManyRequests)(responseCode)) {
|
|
141
|
+
throw new TooManyRequestsError_ts_1.default(message);
|
|
142
|
+
}
|
|
143
|
+
if ((0, httpStatus_ts_1.isHttpInternalServerError)(responseCode)) {
|
|
144
|
+
throw new InternalServerError_ts_1.default(message);
|
|
145
|
+
}
|
|
146
|
+
if ((0, httpStatus_ts_1.isHttpNotImplemented)(responseCode)) {
|
|
147
|
+
throw new NotImplementedError_ts_1.default(message);
|
|
148
|
+
}
|
|
149
|
+
if ((0, httpStatus_ts_1.isHttpServiceUnavailable)(responseCode)) {
|
|
150
|
+
throw new ServiceUnavailableError_ts_1.default(message);
|
|
151
|
+
}
|
|
152
|
+
if ((0, httpStatus_ts_1.isHttpGatewayTimeout)(responseCode)) {
|
|
153
|
+
throw new GatewayTimeoutError_ts_1.default(message);
|
|
154
|
+
}
|
|
155
|
+
if ((0, httpStatus_ts_1.isHttpInsufficientStorage)(responseCode)) {
|
|
156
|
+
throw new InsufficientStorageError_ts_1.default(message);
|
|
157
|
+
}
|
|
158
|
+
if ((0, httpStatus_ts_1.isHttpBandwidthLimitExceeded)(responseCode)) {
|
|
159
|
+
throw new BandwidthLimitExceededError_ts_1.default(message);
|
|
160
|
+
}
|
|
161
|
+
throw new Error(message);
|
|
162
|
+
}
|
|
14
163
|
let instance = null;
|
|
15
|
-
async function
|
|
164
|
+
async function executeRaw(request) {
|
|
16
165
|
if (!instance) {
|
|
17
166
|
instance = createAxiosInstance();
|
|
18
167
|
}
|
|
19
|
-
return await instance(
|
|
168
|
+
return await instance(request);
|
|
20
169
|
}
|
|
21
170
|
function createAxiosInstance() {
|
|
22
171
|
const config = {
|
|
@@ -30,3 +179,58 @@ function createAxiosInstance() {
|
|
|
30
179
|
}
|
|
31
180
|
return axios_1.default.create(config);
|
|
32
181
|
}
|
|
182
|
+
function requestToString(request) {
|
|
183
|
+
const url = request.url || "";
|
|
184
|
+
let message = ` 📤 ${request.method} ${url}\n`;
|
|
185
|
+
if (request.data) {
|
|
186
|
+
message += errorObjectToString(request.data);
|
|
187
|
+
}
|
|
188
|
+
return message;
|
|
189
|
+
}
|
|
190
|
+
function responseToString(response) {
|
|
191
|
+
const message = ` 📥 ${response.status} ${response.statusText}\n`;
|
|
192
|
+
// TODO: Is there any case where we care about the response body?
|
|
193
|
+
// if (response.data) {
|
|
194
|
+
// message += errorObjectToString(response.data);
|
|
195
|
+
// }
|
|
196
|
+
return message;
|
|
197
|
+
}
|
|
198
|
+
function waitToString(milliseconds) {
|
|
199
|
+
return ` ⏳ Wait ${milliseconds}ms for retry.\n`;
|
|
200
|
+
}
|
|
201
|
+
function errorObjectToString(obj) {
|
|
202
|
+
const maxLength = 1024;
|
|
203
|
+
const ellipses = "...";
|
|
204
|
+
let str = JSON.stringify(obj, null, 2)
|
|
205
|
+
.split("\n")
|
|
206
|
+
.map((line) => ` ${line}`)
|
|
207
|
+
.join("\n");
|
|
208
|
+
if (str.length > maxLength) {
|
|
209
|
+
str = `${str.substring(0, maxLength - ellipses.length)}${ellipses}`;
|
|
210
|
+
}
|
|
211
|
+
return `${str}\n`;
|
|
212
|
+
}
|
|
213
|
+
function handleResponseError(response, errorLog, attempts, operationIndex = null) {
|
|
214
|
+
const error = response.data;
|
|
215
|
+
let message = error?.error?.message;
|
|
216
|
+
if (message && !message.endsWith(".")) {
|
|
217
|
+
message += ".";
|
|
218
|
+
}
|
|
219
|
+
if (error?.error?.innerError?.message) {
|
|
220
|
+
message += ` ${error.error.innerError.message}`;
|
|
221
|
+
}
|
|
222
|
+
if (message && !message.endsWith(".")) {
|
|
223
|
+
message += ".";
|
|
224
|
+
}
|
|
225
|
+
if (!message) {
|
|
226
|
+
message = response.statusText;
|
|
227
|
+
}
|
|
228
|
+
if (attempts > 1) {
|
|
229
|
+
message += ` Operation attempted ${attempts} time(s).`;
|
|
230
|
+
}
|
|
231
|
+
if (operationIndex !== null) {
|
|
232
|
+
message += ` (op #${operationIndex})`;
|
|
233
|
+
}
|
|
234
|
+
message += `\n${errorLog}`;
|
|
235
|
+
throwHttpException(response.status, message);
|
|
236
|
+
}
|
|
@@ -15,6 +15,12 @@ export declare function isHttpSuccess(status: number): boolean;
|
|
|
15
15
|
* @returns True if the status code is 200, otherwise false.
|
|
16
16
|
*/
|
|
17
17
|
export declare function isHttpOk(status: number): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Checks if the HTTP status code is created
|
|
20
|
+
* @param status - The HTTP status code.
|
|
21
|
+
* @returns True if the status code is 201, otherwise false.
|
|
22
|
+
*/
|
|
23
|
+
export declare function isHttpCreated(status: number): boolean;
|
|
18
24
|
/**
|
|
19
25
|
* Checks if the HTTP status code indicates not found.
|
|
20
26
|
* @param status - The HTTP status code.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpStatus.d.ts","sourceRoot":"","sources":["../../../src/services/httpStatus.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEhE;AAED;;;;GAIG;AACH,wBAAgB,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