@pipedream/sharepoint 0.7.0 → 0.7.2

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.
@@ -5,7 +5,7 @@ export default {
5
5
  key: "sharepoint-create-link",
6
6
  name: "Create Link",
7
7
  description: "Create a sharing link for a DriveItem. [See the documentation](https://docs.microsoft.com/en-us/graph/api/driveitem-createlink?view=graph-rest-1.0&tabs=http)",
8
- version: "0.0.5",
8
+ version: "0.0.6",
9
9
  type: "action",
10
10
  annotations: {
11
11
  destructiveHint: false,
@@ -1,11 +1,14 @@
1
1
  import sharepoint from "../../sharepoint.app.mjs";
2
2
  import fs from "fs";
3
+ import path from "path";
4
+ import { ConfigurationError } from "@pipedream/platform";
5
+ import constants from "../../common/constants.mjs";
3
6
 
4
7
  export default {
5
8
  key: "sharepoint-download-file",
6
9
  name: "Download File",
7
10
  description: "Download a Microsoft Sharepoint file to the /tmp directory. [See the documentation](https://learn.microsoft.com/en-us/graph/api/driveitem-get-content?view=graph-rest-1.0&tabs=http)",
8
- version: "0.0.10",
11
+ version: "0.0.11",
9
12
  annotations: {
10
13
  destructiveHint: false,
11
14
  openWorldHint: true,
@@ -44,31 +47,114 @@ export default {
44
47
  label: "Filename",
45
48
  description: "The filename to save the downloaded file as in the `/tmp` directory",
46
49
  },
50
+ convertToFormat: {
51
+ type: "string",
52
+ label: "Convert To Format",
53
+ description: "The format to convert the file to. See the [Format Options](https://learn.microsoft.com/en-us/graph/api/driveitem-get-content-format?view=graph-rest-1.0&tabs=http#format-options) for supported source formats",
54
+ options: [
55
+ "pdf",
56
+ "html",
57
+ ],
58
+ optional: true,
59
+ },
47
60
  syncDir: {
48
61
  type: "dir",
49
62
  accessMode: "write",
50
63
  sync: true,
51
64
  },
52
65
  },
66
+ methods: {
67
+ async getOriginalFileData($) {
68
+ const { name: originalFilename } = await this.sharepoint.getDriveItem({
69
+ $,
70
+ driveId: this.driveId,
71
+ siteId: this.siteId,
72
+ fileId: this.fileId,
73
+ });
74
+ const originalExtension = path.extname(originalFilename).slice(1)
75
+ .toLowerCase() || undefined;
76
+ return {
77
+ originalFilename,
78
+ originalExtension,
79
+ };
80
+ },
81
+ formatNewFilename(originalExtension) {
82
+ const parsed = path.parse(this.filename);
83
+ if (this.convertToFormat) {
84
+ const base = parsed.ext
85
+ ? parsed.name
86
+ : this.filename;
87
+ return `${base}.${this.convertToFormat.toLowerCase()}`;
88
+ }
89
+ if (parsed.ext) {
90
+ return this.filename;
91
+ }
92
+ return originalExtension
93
+ ? `${this.filename}.${originalExtension}`
94
+ : this.filename;
95
+ },
96
+ validateConversionFormat(originalExtension) {
97
+ const supportedFormats = this.convertToFormat === "pdf"
98
+ ? constants.PDF_CONVERTIBLE_FORMATS
99
+ : this.convertToFormat === "html"
100
+ ? constants.HTML_CONVERTIBLE_FORMATS
101
+ : [];
102
+ if (!supportedFormats.includes(originalExtension)) {
103
+ throw new ConfigurationError(`The file extension "${originalExtension}" is not supported for conversion to "${this.convertToFormat}". Supported formats are: ${supportedFormats.join(", ")}`);
104
+ }
105
+ },
106
+ },
53
107
  async run({ $ }) {
54
- const response = await this.sharepoint.getFile({
108
+ const {
109
+ originalFilename, originalExtension,
110
+ } = await this.getOriginalFileData($);
111
+
112
+ // ensure filename has an extension
113
+ const filename = this.formatNewFilename(originalExtension);
114
+
115
+ if (this.convertToFormat) {
116
+ this.validateConversionFormat(originalExtension);
117
+ }
118
+
119
+ let response;
120
+ let args = {
55
121
  $,
56
122
  driveId: this.driveId,
57
123
  fileId: this.fileId,
58
- responseType: "arraybuffer",
59
- });
124
+ params: {
125
+ format: this.convertToFormat,
126
+ },
127
+ };
128
+ try {
129
+ response = await this.sharepoint.getFile({
130
+ ...args,
131
+ responseType: "arraybuffer",
132
+ });
133
+ } catch {
134
+ // throw error without buffer encoding
135
+ await this.sharepoint.getFile(args);
136
+ }
60
137
 
61
138
  const rawcontent = response.toString("base64");
62
139
  const buffer = Buffer.from(rawcontent, "base64");
63
140
  // Since the filepath is not returned as one of the standard keys (filePath
64
141
  // or path), save the file to STASH_DIR, if defined, so it is synced at the
65
142
  // end of execution.
66
- const downloadedFilepath = `${process.env.STASH_DIR || "/tmp"}/${this.filename}`;
143
+ const downloadedFilepath = `${process.env.STASH_DIR || "/tmp"}/${filename}`;
67
144
  fs.writeFileSync(downloadedFilepath, buffer);
68
145
 
69
- return {
70
- filename: this.filename,
146
+ const data = {
147
+ filename,
148
+ fileSize: `${buffer.length} bytes`,
149
+ extension: this.convertToFormat || originalExtension,
71
150
  downloadedFilepath,
72
151
  };
152
+
153
+ if (this.convertToFormat) {
154
+ data.originalFilename = originalFilename;
155
+ data.originalExtension = originalExtension;
156
+ }
157
+
158
+ return data;
73
159
  },
74
160
  };
@@ -6,7 +6,7 @@ export default {
6
6
  key: "sharepoint-find-file-by-name",
7
7
  name: "Find File by Name",
8
8
  description: "Search for a file or folder by name. [See the documentation](https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_search)",
9
- version: "0.1.2",
9
+ version: "0.1.3",
10
10
  type: "action",
11
11
  annotations: {
12
12
  destructiveHint: false,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "sharepoint-get-excel-table",
5
5
  name: "Get Excel Table",
6
6
  description: "Retrieve a table from an Excel spreadsheet stored in Sharepoint [See the documentation](https://learn.microsoft.com/en-us/graph/api/table-range?view=graph-rest-1.0&tabs=http)",
7
- version: "0.0.4",
7
+ version: "0.0.5",
8
8
  type: "action",
9
9
  annotations: {
10
10
  destructiveHint: false,
@@ -13,11 +13,10 @@ export default {
13
13
  },
14
14
  props: {
15
15
  sharepoint,
16
+ // eslint-disable-next-line pipedream/props-label, pipedream/props-description
16
17
  alert: {
17
18
  type: "alert",
18
19
  alertType: "info",
19
- label: "Excel Table Information",
20
- description: "Information about selecting Excel tables",
21
20
  content: `Note: The table must exist within the Excel spreadsheet.
22
21
  \nSee Microsoft's documentation on how to [Create and Format a Table](https://support.microsoft.com/en-us/office/create-and-format-tables-e81aa349-b006-4f8a-9806-5af9df0ac664)
23
22
  `,
@@ -24,6 +24,51 @@ const SHARING_LINK_SCOPE_OPTIONS = [
24
24
  },
25
25
  ];
26
26
 
27
+ const PDF_CONVERTIBLE_FORMATS = [
28
+ "doc",
29
+ "docx",
30
+ "dot",
31
+ "dotx",
32
+ "dotm",
33
+ "dsn",
34
+ "dwg",
35
+ "eml",
36
+ "epub",
37
+ "fluidframework",
38
+ "form",
39
+ "htm",
40
+ "html",
41
+ "loop",
42
+ "loot",
43
+ "markdown",
44
+ "md",
45
+ "msg",
46
+ "note",
47
+ "odp",
48
+ "ods",
49
+ "odt",
50
+ "page",
51
+ "pps",
52
+ "ppsx",
53
+ "ppt",
54
+ "pptx",
55
+ "pulse",
56
+ "rtf",
57
+ "task",
58
+ "tif",
59
+ "tiff",
60
+ "wbtx",
61
+ "whiteboard",
62
+ "xls",
63
+ "xlsm",
64
+ "xlsx",
65
+ ];
66
+
67
+ const HTML_CONVERTIBLE_FORMATS = [
68
+ "loop",
69
+ "fluid",
70
+ "wbtx",
71
+ ];
27
72
  const RETURN_CONTENT_TYPE_OPTIONS = [
28
73
  {
29
74
  label: "Only Files",
@@ -42,5 +87,7 @@ const RETURN_CONTENT_TYPE_OPTIONS = [
42
87
  export default {
43
88
  SHARING_LINK_TYPE_OPTIONS,
44
89
  SHARING_LINK_SCOPE_OPTIONS,
90
+ PDF_CONVERTIBLE_FORMATS,
91
+ HTML_CONVERTIBLE_FORMATS,
45
92
  RETURN_CONTENT_TYPE_OPTIONS,
46
93
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/sharepoint",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "Pipedream Microsoft Sharepoint Online Components",
5
5
  "main": "sharepoint.app.mjs",
6
6
  "keywords": [