@pipedream/dropbox 0.3.1 → 0.3.4

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.
@@ -0,0 +1,21 @@
1
+ import isEmpty from "lodash/isEmpty.js";
2
+ import isNil from "lodash/isNil.js";
3
+
4
+ export default {
5
+ methods: {
6
+ getNormalizedPath: (path, appendFinalBar) => {
7
+ let normalizedPath = path?.value || path;
8
+
9
+ // Check for empties path
10
+ if (isNil(normalizedPath) || isEmpty(normalizedPath)) {
11
+ normalizedPath = "/";
12
+ }
13
+
14
+ if (appendFinalBar && normalizedPath[normalizedPath.length - 1] !== "/") {
15
+ normalizedPath += "/";
16
+ }
17
+
18
+ return normalizedPath;
19
+ },
20
+ },
21
+ };
@@ -0,0 +1,47 @@
1
+ import dropbox from "../../dropbox.app.mjs";
2
+ import common from "../common.mjs";
3
+
4
+ export default {
5
+ ...common,
6
+ name: "Create a Text File",
7
+ description: "Creates a brand new text file from plain text content you specify. [See docs here](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesUpload__anchor)",
8
+ key: "dropbox-create-a-text-file",
9
+ version: "0.0.2",
10
+ type: "action",
11
+ props: {
12
+ dropbox,
13
+ name: {
14
+ type: "string",
15
+ label: "File name",
16
+ description: "Your new file name.",
17
+ },
18
+ path: {
19
+ propDefinition: [
20
+ dropbox,
21
+ "pathFolder",
22
+ ],
23
+ description: "The file path in the user's Dropbox to create the file. If not filled, it will be created in the root folder.",
24
+ },
25
+ content: {
26
+ type: "string",
27
+ label: "Content",
28
+ description: "The content of your new file",
29
+ },
30
+ },
31
+ async run({ $ }) {
32
+ const {
33
+ name,
34
+ content,
35
+ path,
36
+ } = this;
37
+
38
+ const res = await this.dropbox.uploadFile({
39
+ contents: Buffer.from(content),
40
+ path: this.getNormalizedPath(path, true) + name,
41
+ autorename: true,
42
+ });
43
+
44
+ $.export("$summary", `${name} successfully created in the folder ${path?.label || path}`);
45
+ return res;
46
+ },
47
+ };
@@ -0,0 +1,47 @@
1
+ import dropbox from "../../dropbox.app.mjs";
2
+ import common from "../common.mjs";
3
+
4
+ export default {
5
+ ...common,
6
+ name: "Create folder",
7
+ description: "Create a folder. [See docs here](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesCreateFolderV2__anchor)",
8
+ key: "dropbox-create-folder",
9
+ version: "0.0.2",
10
+ type: "action",
11
+ props: {
12
+ dropbox,
13
+ name: {
14
+ type: "string",
15
+ label: "Folder name",
16
+ description: "Your new folder name.",
17
+ },
18
+ path: {
19
+ propDefinition: [
20
+ dropbox,
21
+ "pathFolder",
22
+ ],
23
+ optional: true,
24
+ description: "The file path in the user's Dropbox to create the folder. If not filled, it will be created in the root folder.",
25
+ },
26
+ autorename: {
27
+ type: "boolean",
28
+ label: "Autorename",
29
+ description: "If there's a conflict, have Dropbox try to autorename the folder to avoid the conflict.",
30
+ default: true,
31
+ },
32
+ },
33
+ async run({ $ }) {
34
+ const {
35
+ autorename,
36
+ name,
37
+ path,
38
+ } = this;
39
+
40
+ const res = await this.dropbox.createFolder({
41
+ autorename,
42
+ path: this.getNormalizedPath(path, true) + name,
43
+ });
44
+ $.export("$summary", `Folder successfully created: \`${res.result.metadata.name}\``);
45
+ return res;
46
+ },
47
+ };
@@ -0,0 +1,87 @@
1
+ import dropbox from "../../dropbox.app.mjs";
2
+ import common from "../common.mjs";
3
+
4
+ export default {
5
+ name: "Create or Append to a Text File",
6
+ description: "Adds a new line to an existing text file, or creates a file if it doesn't exist. [See docs here](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesUpload__anchor)",
7
+ key: "dropbox-create-or-append-to-a-text-file",
8
+ version: "0.0.2",
9
+ type: "action",
10
+ props: {
11
+ dropbox,
12
+ name: {
13
+ type: "string",
14
+ label: "File name",
15
+ description: "Your new file name",
16
+ },
17
+ path: {
18
+ propDefinition: [
19
+ dropbox,
20
+ "pathFolder",
21
+ ],
22
+ optional: true,
23
+ description: "The file path in the user's Dropbox to create the file. If not filled, it will be created in the root folder.",
24
+ },
25
+ content: {
26
+ type: "string",
27
+ label: "Content",
28
+ description: "The content to be written",
29
+ },
30
+ },
31
+ methods: {
32
+ ...common.methods,
33
+ async getFileInfo(path, content) {
34
+ let file;
35
+ try {
36
+ file = await this.dropbox.downloadFile({
37
+ path,
38
+ });
39
+ } catch {
40
+ file = null;
41
+ }
42
+
43
+ return {
44
+ fileExists: !!(file?.result?.fileBinary),
45
+ content: file?.result?.fileBinary
46
+ ? `${file.result.fileBinary.toString()}\n${content}`
47
+ : content,
48
+ };
49
+ },
50
+ getArgs(fileExists, content, normalizedPath) {
51
+ return {
52
+ contents: Buffer.from(content),
53
+ path: normalizedPath,
54
+ autorename: !fileExists,
55
+ mode: fileExists
56
+ ? {
57
+ ".tag": "overwrite",
58
+ }
59
+ : undefined,
60
+ };
61
+ },
62
+ },
63
+ async run({ $ }) {
64
+ const {
65
+ name,
66
+ content,
67
+ path,
68
+ } = this;
69
+
70
+ const normalizedPath = this.getNormalizedPath(path, true) + name;
71
+ const {
72
+ fileExists,
73
+ content: normalizedContent,
74
+ } = await this.getFileInfo(normalizedPath, content);
75
+
76
+ const res = await this.dropbox.uploadFile(this.getArgs(
77
+ fileExists,
78
+ normalizedContent,
79
+ normalizedPath,
80
+ ));
81
+
82
+ $.export("$summary", fileExists
83
+ ? `Text successfully appended to the file "${name}"`
84
+ : `Text file successfully created in the path "${path?.label || path}"`);
85
+ return res;
86
+ },
87
+ };
@@ -0,0 +1,91 @@
1
+ import dropbox from "../../dropbox.app.mjs";
2
+ import consts from "../../consts.mjs";
3
+
4
+ export default {
5
+ name: "Create/Update a Share Link",
6
+ description: "Creates or updates a public share link to the file or folder (It allows to share the file or folder with anyone). [See docs here](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#sharingCreateSharedLinkWithSettings__anchor)",
7
+ key: "dropbox-create-update-update-a-share-link",
8
+ version: "0.0.2",
9
+ type: "action",
10
+ props: {
11
+ dropbox,
12
+ path: {
13
+ propDefinition: [
14
+ dropbox,
15
+ "pathFileFolder",
16
+ ],
17
+ description: "The path to be shared by the shared link.",
18
+ },
19
+ requirePassword: {
20
+ type: "boolean",
21
+ label: "Require password",
22
+ description: "Boolean flag to enable or disable password protection.",
23
+ default: false,
24
+ },
25
+ linkPassword: {
26
+ type: "string",
27
+ label: "Link password",
28
+ description: "If `require_password` is `true`, this is needed to specify the password to access the link.",
29
+ optional: true,
30
+ },
31
+ expires: {
32
+ type: "string",
33
+ label: "Expires",
34
+ description: "Expiration time of the shared link. By default the link never expires. Make sure to use a valid [timestamp](https://dropbox.github.io/dropbox-sdk-js/global.html#Timestamp) value.",
35
+ optional: true,
36
+ },
37
+ audience: {
38
+ type: "string",
39
+ label: "Audience",
40
+ description: "The new audience who can benefit from the access level specified by the link's access level specified in the `link_access_level` field of `LinkPermissions`. This is used in conjunction with team policies and shared folder policies to determine the final effective audience type in the `effective_audience` field of `LinkPermissions.",
41
+ optional: true,
42
+ options: consts.CREATE_SHARED_LINK_AUDIENCE_OPTIONS,
43
+ },
44
+ access: {
45
+ type: "string",
46
+ label: "Access",
47
+ description: "Requested access level you want the audience to gain from this link. Note, modifying access level for an existing link is not supported.",
48
+ optional: true,
49
+ options: consts.CREATE_SHARED_LINK_ACCESS_OPTIONS,
50
+ },
51
+ allowDownload: {
52
+ type: "boolean",
53
+ label: "Allow downloads",
54
+ description: "Boolean flag to allow or not allow capabilities for shared links.",
55
+ optional: true,
56
+ },
57
+ },
58
+ async run({ $ }) {
59
+ const {
60
+ path,
61
+ requirePassword,
62
+ linkPassword,
63
+ expires,
64
+ audience,
65
+ access,
66
+ requestedVisibility,
67
+ allowDownload,
68
+ removeExpiration,
69
+ } = this;
70
+
71
+ if (requirePassword && !linkPassword) {
72
+ throw new Error("Since the password is required, please add a linkPassword");
73
+ }
74
+
75
+ const res = await this.dropbox.createSharedLink({
76
+ path: path?.value || path,
77
+ settings: {
78
+ require_password: requirePassword,
79
+ link_password: linkPassword,
80
+ expires,
81
+ audience,
82
+ access,
83
+ requested_visibility: requestedVisibility,
84
+ allow_download: allowDownload,
85
+ },
86
+ remove_expiration: removeExpiration,
87
+ });
88
+ $.export("$summary", `Shared link for "${path?.label || path}" successfully created`);
89
+ return res;
90
+ },
91
+ };
@@ -0,0 +1,27 @@
1
+ import dropbox from "../../dropbox.app.mjs";
2
+
3
+ export default {
4
+ name: "Delete a File/Folder",
5
+ description: "Permanently removes a file/folder from the server. [See docs here](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesDeleteV2__anchor)",
6
+ key: "dropbox-delete-a-file-folder",
7
+ version: "0.0.2",
8
+ type: "action",
9
+ props: {
10
+ dropbox,
11
+ path: {
12
+ propDefinition: [
13
+ dropbox,
14
+ "pathFileFolder",
15
+ ],
16
+ description: "Path in the user's Dropbox to delete.",
17
+ },
18
+ },
19
+ async run({ $ }) {
20
+ const { path } = this;
21
+ const res = await this.dropbox.deleteFileFolder({
22
+ path: path?.value || path,
23
+ });
24
+ $.export("$summary", `"${path?.label || path}" successfully deleted`);
25
+ return res;
26
+ },
27
+ };
@@ -0,0 +1,76 @@
1
+ import dropbox from "../../dropbox.app.mjs";
2
+
3
+ export default {
4
+ name: "List All Files/Subfolders in a Folder",
5
+ description: "Retrieves a list of files or subfolders in a specified folder [See the docs here](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesListFolder__anchor)",
6
+ key: "dropbox-list-file-folders-in-a-folder",
7
+ version: "0.0.2",
8
+ type: "action",
9
+ props: {
10
+ dropbox,
11
+ path: {
12
+ propDefinition: [
13
+ dropbox,
14
+ "pathFolder",
15
+ ],
16
+ description: "Scopes the search to a path in the user's Dropbox.",
17
+ },
18
+ recursive: {
19
+ type: "boolean",
20
+ label: "Recursive",
21
+ description: "If `true`, the list folder operation will be applied recursively to all subfolders and the response will contain contents of all subfolders.",
22
+ default: true,
23
+ },
24
+ includeDeleted: {
25
+ type: "boolean",
26
+ label: "Include deleted",
27
+ description: "If `true`, the results will include files and folders that used to exist but were deleted.",
28
+ default: false,
29
+ },
30
+ includeHasExplicitSharedMembers: {
31
+ type: "boolean",
32
+ label: "Include has explicit shared members",
33
+ description: "If `true`, the results will include a flag for each file indicating whether or not that file has any explicit members.",
34
+ default: false,
35
+ },
36
+ includeMountedFolders: {
37
+ type: "boolean",
38
+ label: "Include mounted folders",
39
+ description: "If `true`, the results will include entries under mounted folders which includes app folder, shared folder and team folder.",
40
+ default: false,
41
+ },
42
+ includeNonDownloadableFiles: {
43
+ type: "boolean",
44
+ label: "Include non downloadable files",
45
+ description: "If `true`, include files that are not downloadable, i.e. Google Docs.",
46
+ default: true,
47
+ },
48
+ limit: {
49
+ propDefinition: [
50
+ dropbox,
51
+ "limit",
52
+ ],
53
+ },
54
+ },
55
+ async run({ $ }) {
56
+ const {
57
+ limit,
58
+ path,
59
+ recursive,
60
+ includeDeleted,
61
+ includeHasExplicitSharedMembers,
62
+ includeMountedFolders,
63
+ includeNonDownloadableFiles,
64
+ } = this;
65
+ const res = await this.dropbox.listFilesFolders({
66
+ path: path?.value || path,
67
+ recursive,
68
+ include_deleted: includeDeleted,
69
+ include_has_explicit_shared_members: includeHasExplicitSharedMembers,
70
+ include_mounted_folders: includeMountedFolders,
71
+ include_non_downloadable_files: includeNonDownloadableFiles,
72
+ }, limit);
73
+ $.export("$summary", `Files and folders in the path ${path?.label || path} successfully fetched`);
74
+ return res;
75
+ },
76
+ };
@@ -0,0 +1,53 @@
1
+ import consts from "../../consts.mjs";
2
+ import dropbox from "../../dropbox.app.mjs";
3
+
4
+ export default {
5
+ name: "List File Revisions",
6
+ description: "Retrieves a list of file revisions needed to recover previous content. [See docs here](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesListRevisions__anchor)",
7
+ key: "dropbox-list-file-revisions",
8
+ version: "0.0.2",
9
+ type: "action",
10
+ props: {
11
+ dropbox,
12
+ path: {
13
+ propDefinition: [
14
+ dropbox,
15
+ "pathFile",
16
+ ],
17
+ description: "The file path for the file whose revisions you'd like to list.",
18
+ },
19
+ mode: {
20
+ type: "string",
21
+ label: "Mode",
22
+ description: "Determines the behavior of the API in listing the revisions for a given file path or id.",
23
+ optional: true,
24
+ options: consts.LIST_FILE_REVISIONS_OPTIONS,
25
+ },
26
+ limit: {
27
+ propDefinition: [
28
+ dropbox,
29
+ "limit",
30
+ ],
31
+ description: "The maximum number of revision entries returned.",
32
+ optional: true,
33
+ },
34
+ },
35
+ async run({ $ }) {
36
+ const {
37
+ path,
38
+ mode,
39
+ limit,
40
+ } = this;
41
+ const res = await this.dropbox.listFileRevisions({
42
+ path: path?.value || path,
43
+ mode: mode
44
+ ? {
45
+ ".tag": mode,
46
+ }
47
+ : undefined,
48
+ limit,
49
+ });
50
+ $.export("$summary", `File revisions for file "${path?.label || path}" successfully fetched`);
51
+ return res;
52
+ },
53
+ };
@@ -0,0 +1,67 @@
1
+ import dropbox from "../../dropbox.app.mjs";
2
+
3
+ export default {
4
+ name: "Move a File/Folder",
5
+ description: "Moves a file or folder to a different location in the user's Dropbox [See the docs here](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesMoveV2__anchor)",
6
+ key: "dropbox-move-file-folder",
7
+ version: "0.0.2",
8
+ type: "action",
9
+ props: {
10
+ dropbox,
11
+ pathFrom: {
12
+ propDefinition: [
13
+ dropbox,
14
+ "pathFileFolder",
15
+ ],
16
+ label: "Path from",
17
+ description: "The file/folder that you want to move.",
18
+ },
19
+ pathTo: {
20
+ propDefinition: [
21
+ dropbox,
22
+ "pathFolder",
23
+ ],
24
+ label: "Path to",
25
+ description: "The new path of your file/folder",
26
+ },
27
+ autorename: {
28
+ type: "boolean",
29
+ label: "Autorename",
30
+ description: "If there's a conflict, have Dropbox try to autorename the folder to avoid the conflict.",
31
+ optional: true,
32
+ },
33
+ allowOwnershipTransfer: {
34
+ type: "boolean",
35
+ label: "Allow ownership transfer",
36
+ description: "Allow moves by owner even if it would result in an ownership transfer for the content being moved. This does not apply to copies.",
37
+ optional: true,
38
+ },
39
+ },
40
+ async run({ $ }) {
41
+ const {
42
+ pathFrom,
43
+ autorename,
44
+ allowOwnershipTransfer,
45
+ pathTo,
46
+ } = this;
47
+
48
+ let normalizedPathTo = pathTo?.value || pathTo;
49
+ const normalizedPathFrom = pathFrom?.value || pathFrom;
50
+
51
+ // If path is a file, we need to move it as a file
52
+ if (pathFrom?.type == "file" && pathFrom.value) {
53
+ const splited = normalizedPathFrom.split("/");
54
+ const fileName = splited[splited.length - 1];
55
+ normalizedPathTo = `${pathTo?.value || pathTo}/${fileName}`;
56
+ }
57
+
58
+ const res = await this.dropbox.filesMove({
59
+ from_path: pathFrom.value,
60
+ to_path: normalizedPathTo,
61
+ autorename,
62
+ allow_ownership_transfer: allowOwnershipTransfer,
63
+ });
64
+ $.export("$summary", `"${normalizedPathFrom}" successfully moved to "${normalizedPathTo}"`);
65
+ return res;
66
+ },
67
+ };
@@ -0,0 +1,57 @@
1
+ import dropbox from "../../dropbox.app.mjs";
2
+
3
+ export default {
4
+ name: "Rename a File/Folder",
5
+ description: "Renames a file or folder in the user's Dropbox [See the docs here](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesMoveV2__anchor)",
6
+ key: "dropbox-rename-file-folder",
7
+ version: "0.0.2",
8
+ type: "action",
9
+ props: {
10
+ dropbox,
11
+ pathFrom: {
12
+ propDefinition: [
13
+ dropbox,
14
+ "pathFileFolder",
15
+ ],
16
+ label: "Path From",
17
+ description: "The file that you want to rename.",
18
+ },
19
+ newName: {
20
+ type: "string",
21
+ label: "New Name",
22
+ description: "The file's new name (make sure to include the file extension).",
23
+ },
24
+ autorename: {
25
+ type: "boolean",
26
+ label: "Autorename",
27
+ description: "If there's a conflict, have Dropbox try to autorename the folder to avoid the conflict.",
28
+ optional: true,
29
+ },
30
+ allowOwnershipTransfer: {
31
+ type: "boolean",
32
+ label: "Allow ownership transfer",
33
+ description: "Allow moves by owner even if it would result in an ownership transfer for the content being moved. This does not apply to copies.",
34
+ optional: true,
35
+ },
36
+ },
37
+ async run({ $ }) {
38
+ const {
39
+ pathFrom,
40
+ newName,
41
+ autorename,
42
+ allowOwnershipTransfer,
43
+ } = this;
44
+
45
+ const normalizedPathFrom = pathFrom?.value || pathFrom;
46
+ const splitedPath = normalizedPathFrom.split("/");
47
+ splitedPath[splitedPath.length - 1] = newName;
48
+ const res = await this.dropbox.filesMove({
49
+ from_path: normalizedPathFrom,
50
+ to_path: splitedPath.join("/"),
51
+ autorename,
52
+ allow_ownership_transfer: allowOwnershipTransfer,
53
+ });
54
+ $.export("$summary", `"${normalizedPathFrom}" successfully renamed to "${newName}"`);
55
+ return res;
56
+ },
57
+ };
@@ -0,0 +1,42 @@
1
+ import dropbox from "../../dropbox.app.mjs";
2
+
3
+ export default {
4
+ name: "Restore a File",
5
+ description: "Restores a previous file version. [See docs here](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesRestore__anchor)",
6
+ key: "dropbox-restore-a-file",
7
+ version: "0.0.2",
8
+ type: "action",
9
+ props: {
10
+ dropbox,
11
+ path: {
12
+ propDefinition: [
13
+ dropbox,
14
+ "pathFile",
15
+ ],
16
+ description: "The path to save the restored file.",
17
+ },
18
+ rev: {
19
+ propDefinition: [
20
+ dropbox,
21
+ "fileRevision",
22
+ ({ path }) => ({
23
+ path,
24
+ }),
25
+ ],
26
+ description: "The revision to restore.",
27
+ },
28
+ },
29
+ async run({ $ }) {
30
+ const {
31
+ path,
32
+ rev,
33
+ } = this;
34
+
35
+ const res = await this.dropbox.restoreFile({
36
+ path: path?.value || path,
37
+ rev: rev?.value || rev,
38
+ });
39
+ $.export("$summary", `"${path?.label || path}" successfully restored to "${rev?.label || rev}" revision`);
40
+ return res;
41
+ },
42
+ };