@pipedream/dropbox 0.3.20 → 0.4.1

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.
@@ -4,7 +4,7 @@ export default {
4
4
  name: "Create a Text File",
5
5
  description: "Creates a brand new text file from plain text content you specify. [See the documentation](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesUpload__anchor)",
6
6
  key: "dropbox-create-a-text-file",
7
- version: "0.0.10",
7
+ version: "0.0.11",
8
8
  type: "action",
9
9
  props: {
10
10
  dropbox,
@@ -4,7 +4,7 @@ export default {
4
4
  name: "Create folder",
5
5
  description: "Create a Folder. [See the documentation](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesCreateFolderV2__anchor)",
6
6
  key: "dropbox-create-folder",
7
- version: "0.0.10",
7
+ version: "0.0.11",
8
8
  type: "action",
9
9
  props: {
10
10
  dropbox,
@@ -4,7 +4,7 @@ export default {
4
4
  name: "Create or Append to a Text File",
5
5
  description: "Adds a new line to an existing text file, or creates a file if it doesn't exist. [See the documentation](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesUpload__anchor)",
6
6
  key: "dropbox-create-or-append-to-a-text-file",
7
- version: "0.0.10",
7
+ version: "0.0.11",
8
8
  type: "action",
9
9
  props: {
10
10
  dropbox,
@@ -1,11 +1,11 @@
1
- import common from "./common.mjs";
2
1
  import consts from "../../common/consts.mjs";
2
+ import common from "./common.mjs";
3
3
 
4
4
  export default {
5
5
  name: "Create/Update a Share Link",
6
6
  description: "Creates or updates a public share link to the file or folder (It allows you to share the file or folder with anyone). [See the documentation](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#sharingCreateSharedLinkWithSettings__anchor)",
7
7
  key: "dropbox-create-update-share-link",
8
- version: "0.0.10",
8
+ version: "0.0.11",
9
9
  type: "action",
10
10
  props: {
11
11
  ...common.props,
@@ -4,7 +4,7 @@ export default {
4
4
  name: "Delete a File/Folder",
5
5
  description: "Permanently removes a file/folder from the server. [See documentation](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesDeleteV2__anchor)",
6
6
  key: "dropbox-delete-file-folder",
7
- version: "0.0.10",
7
+ version: "0.0.11",
8
8
  type: "action",
9
9
  props: {
10
10
  dropbox,
@@ -1,12 +1,15 @@
1
- import dropbox from "../../dropbox.app.mjs";
2
1
  import fs from "fs";
3
- import { file } from "tmp-promise";
2
+ import got from "got";
3
+ import stream from "stream";
4
+ import { promisify } from "util";
5
+ import { checkTmp } from "../../common/utils.mjs";
6
+ import dropbox from "../../dropbox.app.mjs";
4
7
 
5
8
  export default {
6
9
  name: "Download File to TMP",
7
10
  description: "Download a specific file to the temporary directory. [See the documentation](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesDownload__anchor).",
8
11
  key: "dropbox-download-file-to-tmp",
9
- version: "0.0.6",
12
+ version: "0.0.7",
10
13
  type: "action",
11
14
  props: {
12
15
  dropbox,
@@ -27,30 +30,40 @@ export default {
27
30
  },
28
31
  },
29
32
  async run({ $ }) {
30
- const { result } = await this.dropbox.downloadFile({
31
- path: this.dropbox.getNormalizedPath(this.path, false),
32
- });
33
+ try {
34
+ const linkResponse = await this.dropbox.filesGetTemporaryLink({
35
+ path: this.dropbox.getNormalizedPath(this.path, false),
36
+ });
37
+
38
+ console.log("linkResponse: ", linkResponse);
33
39
 
34
- const {
35
- path, cleanup,
36
- } = await file();
40
+ if (!linkResponse || !linkResponse.result) {
41
+ throw new Error("Failed to get temporary download link from Dropbox");
42
+ }
37
43
 
38
- const extension = result.name.split(".").pop();
44
+ const {
45
+ link, metadata,
46
+ } = linkResponse.result;
39
47
 
40
- const tmpPath = this.name
41
- ? `/tmp/${this.name}`
42
- : `${path}.${extension}`;
48
+ const fileName = this.name || metadata.name;
49
+ const cleanFileName = fileName.replace(/[?$#&{}[]<>\*!@:\+\\\/]/g, "");
43
50
 
44
- await fs.promises.appendFile(tmpPath, Buffer.from(result.fileBinary));
45
- await cleanup();
51
+ const tmpPath = checkTmp(cleanFileName);
52
+ const pipeline = promisify(stream.pipeline);
46
53
 
47
- delete result.fileBinary;
54
+ await pipeline(
55
+ got.stream(link),
56
+ fs.createWriteStream(tmpPath),
57
+ );
48
58
 
49
- $.export("$summary", `File successfully saved in "${tmpPath}"`);
59
+ $.export("$summary", `File successfully saved in "${tmpPath}"`);
50
60
 
51
- return {
52
- tmpPath,
53
- ...result,
54
- };
61
+ return {
62
+ tmpPath,
63
+ ...metadata,
64
+ };
65
+ } catch (error) {
66
+ throw new Error(`Failed to download file: ${error.message}`);
67
+ }
55
68
  },
56
69
  };
@@ -4,7 +4,7 @@ export default {
4
4
  name: "List All Files/Subfolders in a Folder",
5
5
  description: "Retrieves a list of files or subfolders in a specified folder [See the documentation](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesListFolder__anchor)",
6
6
  key: "dropbox-list-file-folders-in-a-folder",
7
- version: "0.0.10",
7
+ version: "0.0.11",
8
8
  type: "action",
9
9
  props: {
10
10
  dropbox,
@@ -5,7 +5,7 @@ export default {
5
5
  name: "List File Revisions",
6
6
  description: "Retrieves a list of file revisions needed to recover previous content. [See the documentation](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesListRevisions__anchor)",
7
7
  key: "dropbox-list-file-revisions",
8
- version: "0.0.10",
8
+ version: "0.0.11",
9
9
  type: "action",
10
10
  props: {
11
11
  dropbox,
@@ -4,7 +4,7 @@ export default {
4
4
  name: "Move a File/Folder",
5
5
  description: "Moves a file or folder to a different location in the user's Dropbox [See the documentation](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesMoveV2__anchor)",
6
6
  key: "dropbox-move-file-folder",
7
- version: "0.0.11",
7
+ version: "0.0.12",
8
8
  type: "action",
9
9
  props: {
10
10
  dropbox,
@@ -4,7 +4,7 @@ export default {
4
4
  name: "Rename a File/Folder",
5
5
  description: "Renames a file or folder in the user's Dropbox [See the documentation](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesMoveV2__anchor)",
6
6
  key: "dropbox-rename-file-folder",
7
- version: "0.0.10",
7
+ version: "0.0.11",
8
8
  type: "action",
9
9
  props: {
10
10
  dropbox,
@@ -4,7 +4,7 @@ export default {
4
4
  name: "Restore a File",
5
5
  description: "Restores a previous file version. [See the documentation](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesRestore__anchor)",
6
6
  key: "dropbox-restore-a-file",
7
- version: "0.0.10",
7
+ version: "0.0.11",
8
8
  type: "action",
9
9
  props: {
10
10
  dropbox,
@@ -1,12 +1,12 @@
1
- import dropbox from "../../dropbox.app.mjs";
2
1
  import isNil from "lodash/isNil.js";
3
2
  import consts from "../../common/consts.mjs";
3
+ import dropbox from "../../dropbox.app.mjs";
4
4
 
5
5
  export default {
6
6
  name: "Search files and folders",
7
7
  description: "Searches for files and folders by name. [See the documentation](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesSearchV2__anchor)",
8
8
  key: "dropbox-search-files-folders",
9
- version: "0.0.10",
9
+ version: "0.0.11",
10
10
  type: "action",
11
11
  props: {
12
12
  dropbox,
@@ -1,14 +1,14 @@
1
- import dropbox from "../../dropbox.app.mjs";
2
- import consts from "../../common/consts.mjs";
1
+ import { ConfigurationError } from "@pipedream/platform";
3
2
  import fs from "fs";
4
3
  import got from "got";
5
- import { ConfigurationError } from "@pipedream/platform";
4
+ import consts from "../../common/consts.mjs";
5
+ import dropbox from "../../dropbox.app.mjs";
6
6
 
7
7
  export default {
8
8
  name: "Upload a File",
9
9
  description: "Uploads a file to a selected folder. [See the documentation](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesUpload__anchor)",
10
10
  key: "dropbox-upload-file",
11
- version: "0.0.13",
11
+ version: "0.0.14",
12
12
  type: "action",
13
13
  props: {
14
14
  dropbox,
@@ -0,0 +1,135 @@
1
+ import { ConfigurationError } from "@pipedream/platform";
2
+ import fs from "fs";
3
+ import got from "got";
4
+ import consts from "../../common/consts.mjs";
5
+ import dropbox from "../../dropbox.app.mjs";
6
+
7
+ export default {
8
+ name: "Upload Multiple Files",
9
+ description: "Uploads multiple file to a selected folder. [See the documentation](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesUpload__anchor)",
10
+ key: "dropbox-upload-multiple-files",
11
+ version: "0.0.2",
12
+ type: "action",
13
+ props: {
14
+ dropbox,
15
+ path: {
16
+ propDefinition: [
17
+ dropbox,
18
+ "path",
19
+ () => ({
20
+ filter: ({ metadata: { metadata: { [".tag"]: type } } }) => type === "folder",
21
+ }),
22
+ ],
23
+ description: "The folder to upload to. Type the folder name to search for it in the user's Dropbox.",
24
+ },
25
+ fileUrls: {
26
+ type: "string[]",
27
+ label: "File URLs",
28
+ description: "The URLs of the files you want to upload to Dropbox. Must specify either File URLs or File Paths.",
29
+ default: [],
30
+ optional: true,
31
+ },
32
+ filePaths: {
33
+ type: "string[]",
34
+ label: "File Paths",
35
+ description: "The paths to the files, e.g. /tmp/myFile.csv . Must specify either File URLs or File Paths.",
36
+ default: [],
37
+ optional: true,
38
+ },
39
+ filenames: {
40
+ type: "string[]",
41
+ label: "File Names",
42
+ description: "An array of filenames for the new files. Please provide a name for each URL and/or Path. Make sure to include the file extensions.",
43
+ },
44
+ autorename: {
45
+ type: "boolean",
46
+ label: "Autorename",
47
+ description: "If there's a conflict, have Dropbox try to autorename the file to avoid the conflict.",
48
+ optional: true,
49
+ },
50
+ mute: {
51
+ type: "boolean",
52
+ label: "Mute",
53
+ description: "Normally, users are made aware of any file modifications in their Dropbox account via notifications in the client software. If `true`, this will not result in a user notification.",
54
+ optional: true,
55
+ },
56
+ strictConflict: {
57
+ type: "boolean",
58
+ label: "Strict Conflict",
59
+ description: "Be more strict about how each WriteMode detects conflict. For example, always return a conflict error when mode = WriteMode.update and the given \"rev\" doesn't match the existing file's \"rev\", even if the existing file has been deleted. This also forces a conflict even when the target path refers to a file with identical contents.",
60
+ optional: true,
61
+ },
62
+ mode: {
63
+ type: "string",
64
+ label: "Mode",
65
+ description: "Selects what to do if the file already exists.",
66
+ options: consts.UPLOAD_FILE_MODE_OPTIONS,
67
+ optional: true,
68
+ },
69
+ },
70
+ async run({ $ }) {
71
+ const {
72
+ dropbox,
73
+ path,
74
+ fileUrls,
75
+ filePaths,
76
+ autorename,
77
+ mute,
78
+ strictConflict,
79
+ mode,
80
+ filenames,
81
+ } = this;
82
+
83
+ if (!fileUrls?.length && !filePaths?.length) {
84
+ throw new ConfigurationError("Must specify either File URLs or File Paths.");
85
+ }
86
+
87
+ const numFiles = fileUrls.length + filePaths.length;
88
+ if (numFiles !== filenames.length) {
89
+ throw new ConfigurationError(`Number of filenames must match number of files. Detected ${numFiles} file(s) and ${filenames.length} filename(s)`);
90
+ }
91
+
92
+ const fileInfo = [];
93
+ const normalizedPath = dropbox.getNormalizedPath(path, true);
94
+ let i = 0;
95
+
96
+ if (fileUrls?.length) {
97
+ for (const url of fileUrls) {
98
+ fileInfo.push({
99
+ contents: await got.stream(url),
100
+ path: `${normalizedPath}${filenames[i]}`,
101
+ });
102
+ i++;
103
+ }
104
+ }
105
+
106
+ if (filePaths?.length) {
107
+ for (const filePath of filePaths) {
108
+ fileInfo.push({
109
+ contents: fs.createReadStream(filePath),
110
+ path: `${normalizedPath}${filenames[i]}`,
111
+ });
112
+ i++;
113
+ }
114
+ }
115
+
116
+ const responses = [];
117
+ for (const file of fileInfo) {
118
+ const { result } = await dropbox.uploadFile({
119
+ contents: file.contents,
120
+ autorename,
121
+ path: file.path,
122
+ mode: mode
123
+ ? {
124
+ ".tag": mode,
125
+ }
126
+ : undefined,
127
+ mute,
128
+ strict_conflict: strictConflict,
129
+ });
130
+ responses.push(result);
131
+ }
132
+ $.export("$summary", "Files successfully uploaded");
133
+ return responses;
134
+ },
135
+ };
@@ -0,0 +1,6 @@
1
+ export const checkTmp = (filename) => {
2
+ if (!filename.startsWith("/tmp")) {
3
+ return `/tmp/${filename}`;
4
+ }
5
+ return filename;
6
+ };
package/dropbox.app.mjs CHANGED
@@ -1,12 +1,10 @@
1
- import dropbox from "dropbox";
1
+ import { Dropbox } from "dropbox";
2
2
  import fetch from "isomorphic-fetch";
3
3
  import get from "lodash/get.js";
4
- import config from "./common/config.mjs";
5
- import isString from "lodash/isString.js";
6
4
  import isEmpty from "lodash/isEmpty.js";
7
5
  import isNil from "lodash/isNil.js";
8
-
9
- const Dropbox = dropbox.Dropbox;
6
+ import isString from "lodash/isString.js";
7
+ import config from "./common/config.mjs";
10
8
 
11
9
  export default {
12
10
  type: "app",
@@ -400,6 +398,14 @@ export default {
400
398
  this.normalizeError(err);
401
399
  }
402
400
  },
401
+ async filesGetTemporaryLink(args) {
402
+ try {
403
+ const dpx = await this.sdk();
404
+ return await dpx.filesGetTemporaryLink(args);
405
+ } catch (err) {
406
+ this.normalizeError(err);
407
+ }
408
+ },
403
409
  async downloadFile(args) {
404
410
  try {
405
411
  const dpx = await this.sdk();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/dropbox",
3
- "version": "0.3.20",
3
+ "version": "0.4.1",
4
4
  "description": "Pipedream Dropbox Components",
5
5
  "main": "dropbox.app.mjs",
6
6
  "keywords": [
@@ -12,10 +12,12 @@
12
12
  "dependencies": {
13
13
  "@types/node-fetch": "^2.5.7",
14
14
  "dropbox": "^10.34.0",
15
- "got": "^14.0.0",
15
+ "got": "^13.0.0",
16
16
  "isomorphic-fetch": "^3.0.0",
17
17
  "lodash": "^4.17.21",
18
- "tmp-promise": "^3.0.3"
18
+ "stream": "^0.0.3",
19
+ "tmp-promise": "^3.0.3",
20
+ "util": "^0.12.5"
19
21
  },
20
22
  "gitHead": "e12480b94cc03bed4808ebc6b13e7fdb3a1ba535",
21
23
  "publishConfig": {
@@ -7,7 +7,7 @@ export default {
7
7
  type: "source",
8
8
  key: "dropbox-all-updates",
9
9
  name: "New or Modified File or Folder",
10
- version: "0.0.17",
10
+ version: "0.0.18",
11
11
  description: "Emit new event when a file or folder is added or modified. Make sure the number of files/folders in the watched folder does not exceed 4000.",
12
12
  props: {
13
13
  ...common.props,
@@ -7,7 +7,7 @@ export default {
7
7
  type: "source",
8
8
  key: "dropbox-new-file",
9
9
  name: "New File",
10
- version: "0.0.18",
10
+ version: "0.0.19",
11
11
  description: "Emit new event when a new file is added to your account or a specific folder. Make sure the number of files/folders in the watched folder does not exceed 4000.",
12
12
  props: {
13
13
  ...common.props,
@@ -7,7 +7,7 @@ export default {
7
7
  type: "source",
8
8
  key: "dropbox-new-folder",
9
9
  name: "New Folder",
10
- version: "0.0.17",
10
+ version: "0.0.18",
11
11
  description: "Emit new event when a new folder is created. Make sure the number of files/folders in the watched folder does not exceed 4000.",
12
12
  hooks: {
13
13
  async activate() {