@divyacon/piece-dropbox 0.0.0-stage → 0.1.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.
Files changed (83) hide show
  1. package/LICENSE.MIT-AP +24 -0
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +65 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/lib/actions/copy-file.d.ts +7 -0
  7. package/dist/lib/actions/copy-file.d.ts.map +1 -0
  8. package/dist/lib/actions/copy-file.js +65 -0
  9. package/dist/lib/actions/copy-file.js.map +1 -0
  10. package/dist/lib/actions/copy-folder.d.ts +7 -0
  11. package/dist/lib/actions/copy-folder.d.ts.map +1 -0
  12. package/dist/lib/actions/copy-folder.js +65 -0
  13. package/dist/lib/actions/copy-folder.js.map +1 -0
  14. package/dist/lib/actions/create-new-folder.d.ts +5 -0
  15. package/dist/lib/actions/create-new-folder.d.ts.map +1 -0
  16. package/dist/lib/actions/create-new-folder.js +54 -0
  17. package/dist/lib/actions/create-new-folder.js.map +1 -0
  18. package/dist/lib/actions/create-new-text-file.d.ts +8 -0
  19. package/dist/lib/actions/create-new-text-file.d.ts.map +1 -0
  20. package/dist/lib/actions/create-new-text-file.js +76 -0
  21. package/dist/lib/actions/create-new-text-file.js.map +1 -0
  22. package/dist/lib/actions/delete-file.d.ts +4 -0
  23. package/dist/lib/actions/delete-file.d.ts.map +1 -0
  24. package/dist/lib/actions/delete-file.js +45 -0
  25. package/dist/lib/actions/delete-file.js.map +1 -0
  26. package/dist/lib/actions/delete-folder.d.ts +4 -0
  27. package/dist/lib/actions/delete-folder.d.ts.map +1 -0
  28. package/dist/lib/actions/delete-folder.js +45 -0
  29. package/dist/lib/actions/delete-folder.js.map +1 -0
  30. package/dist/lib/actions/download-file.d.ts +4 -0
  31. package/dist/lib/actions/download-file.d.ts.map +1 -0
  32. package/dist/lib/actions/download-file.js +53 -0
  33. package/dist/lib/actions/download-file.js.map +1 -0
  34. package/dist/lib/actions/get-file-link.d.ts +4 -0
  35. package/dist/lib/actions/get-file-link.d.ts.map +1 -0
  36. package/dist/lib/actions/get-file-link.js +45 -0
  37. package/dist/lib/actions/get-file-link.js.map +1 -0
  38. package/dist/lib/actions/list-a-folder.d.ts +6 -0
  39. package/dist/lib/actions/list-a-folder.d.ts.map +1 -0
  40. package/dist/lib/actions/list-a-folder.js +58 -0
  41. package/dist/lib/actions/list-a-folder.js.map +1 -0
  42. package/dist/lib/actions/move-file.d.ts +7 -0
  43. package/dist/lib/actions/move-file.d.ts.map +1 -0
  44. package/dist/lib/actions/move-file.js +65 -0
  45. package/dist/lib/actions/move-file.js.map +1 -0
  46. package/dist/lib/actions/move-folder.d.ts +7 -0
  47. package/dist/lib/actions/move-folder.d.ts.map +1 -0
  48. package/dist/lib/actions/move-folder.js +65 -0
  49. package/dist/lib/actions/move-folder.js.map +1 -0
  50. package/dist/lib/actions/search.d.ts +12 -0
  51. package/dist/lib/actions/search.d.ts.map +1 -0
  52. package/dist/lib/actions/search.js +114 -0
  53. package/dist/lib/actions/search.js.map +1 -0
  54. package/dist/lib/actions/upload-file.d.ts +8 -0
  55. package/dist/lib/actions/upload-file.d.ts.map +1 -0
  56. package/dist/lib/actions/upload-file.js +75 -0
  57. package/dist/lib/actions/upload-file.js.map +1 -0
  58. package/dist/lib/auth.d.ts +2 -0
  59. package/dist/lib/auth.d.ts.map +1 -0
  60. package/dist/lib/auth.js +21 -0
  61. package/dist/lib/auth.js.map +1 -0
  62. package/dist/lib/triggers/new-folder.d.ts +15 -0
  63. package/dist/lib/triggers/new-folder.d.ts.map +1 -0
  64. package/dist/lib/triggers/new-folder.js +114 -0
  65. package/dist/lib/triggers/new-folder.js.map +1 -0
  66. package/package.json +43 -3
  67. package/src/index.ts +59 -0
  68. package/src/lib/actions/copy-file.ts +66 -0
  69. package/src/lib/actions/copy-folder.ts +66 -0
  70. package/src/lib/actions/create-new-folder.ts +54 -0
  71. package/src/lib/actions/create-new-text-file.ts +78 -0
  72. package/src/lib/actions/delete-file.ts +44 -0
  73. package/src/lib/actions/delete-folder.ts +43 -0
  74. package/src/lib/actions/download-file.ts +51 -0
  75. package/src/lib/actions/get-file-link.ts +43 -0
  76. package/src/lib/actions/list-a-folder.ts +59 -0
  77. package/src/lib/actions/move-file.ts +65 -0
  78. package/src/lib/actions/move-folder.ts +67 -0
  79. package/src/lib/actions/search.ts +117 -0
  80. package/src/lib/actions/upload-file.ts +79 -0
  81. package/src/lib/auth.ts +16 -0
  82. package/src/lib/triggers/new-folder.ts +167 -0
  83. package/README.md +0 -3
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dropboxNewFolder = void 0;
4
+ const tslib_1 = require("tslib");
5
+ // Vendored from Activepieces packages/pieces/community/dropbox/src/lib/triggers/new-folder.ts (MIT).
6
+ // Generated by packages/scripts/vendor-ap.mjs - do not edit by hand.
7
+ const pieces_framework_1 = require("@agnocon/pieces-framework");
8
+ const pieces_common_1 = require("@agnocon/pieces-common");
9
+ const auth_1 = require("../auth");
10
+ // Returns the latest cursor for a folder without fetching any entries.
11
+ // Designed for apps that only need to know about new changes going forward.
12
+ const getLatestCursor = (accessToken, path, recursive) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
13
+ const res = yield pieces_common_1.httpClient.sendRequest({
14
+ method: pieces_common_1.HttpMethod.POST,
15
+ url: 'https://api.dropboxapi.com/2/files/list_folder/get_latest_cursor',
16
+ headers: { 'Content-Type': 'application/json' },
17
+ body: { path, recursive, include_deleted: false },
18
+ authentication: {
19
+ type: pieces_common_1.AuthenticationType.BEARER_TOKEN,
20
+ token: accessToken,
21
+ },
22
+ });
23
+ return res.body.cursor;
24
+ });
25
+ // Calls list_folder/continue with a stored cursor and returns all new folder entries,
26
+ // plus the updated cursor to store for the next poll.
27
+ const getChangedFolders = (accessToken, cursor) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
28
+ const folders = [];
29
+ let currentCursor = cursor;
30
+ let hasMore = true;
31
+ while (hasMore) {
32
+ const res = yield pieces_common_1.httpClient.sendRequest({
33
+ method: pieces_common_1.HttpMethod.POST,
34
+ url: 'https://api.dropboxapi.com/2/files/list_folder/continue',
35
+ headers: { 'Content-Type': 'application/json' },
36
+ body: { cursor: currentCursor },
37
+ authentication: {
38
+ type: pieces_common_1.AuthenticationType.BEARER_TOKEN,
39
+ token: accessToken,
40
+ },
41
+ });
42
+ const newFolders = res.body.entries.filter((e) => e['.tag'] === 'folder');
43
+ folders.push(...newFolders);
44
+ currentCursor = res.body.cursor;
45
+ hasMore = res.body.has_more;
46
+ }
47
+ return { folders, newCursor: currentCursor };
48
+ });
49
+ // Fetches recent folder entries for test mode — returns up to 5.
50
+ const listRecentFolders = (accessToken, path, recursive) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
51
+ const res = yield pieces_common_1.httpClient.sendRequest({
52
+ method: pieces_common_1.HttpMethod.POST,
53
+ url: 'https://api.dropboxapi.com/2/files/list_folder',
54
+ headers: { 'Content-Type': 'application/json' },
55
+ body: { path, recursive, include_deleted: false, limit: 100 },
56
+ authentication: {
57
+ type: pieces_common_1.AuthenticationType.BEARER_TOKEN,
58
+ token: accessToken,
59
+ },
60
+ });
61
+ return res.body.entries.filter((e) => e['.tag'] === 'folder').slice(0, 5);
62
+ });
63
+ exports.dropboxNewFolder = (0, pieces_framework_1.createTrigger)({
64
+ auth: auth_1.dropboxAuth,
65
+ name: 'new_folder',
66
+ displayName: 'New Folder',
67
+ description: 'Triggers when a new folder is created inside a watched Dropbox folder.',
68
+ aiMetadata: {
69
+ description: 'Fires when a new folder appears inside the watched Dropbox folder path, detected by polling the folder for changes since the last cursor. Each fired event represents one newly created folder; enable recursive watching to also detect folders created within subfolders.',
70
+ },
71
+ type: pieces_framework_1.TriggerStrategy.POLLING,
72
+ props: {
73
+ path: pieces_framework_1.Property.ShortText({
74
+ displayName: 'Watched Folder Path',
75
+ description: 'Folder path to watch. Use empty string "" for root.',
76
+ required: true,
77
+ defaultValue: '',
78
+ }),
79
+ recursive: pieces_framework_1.Property.Checkbox({
80
+ displayName: 'Recursive',
81
+ description: 'Watch subfolders recursively. May return many results.',
82
+ required: false,
83
+ defaultValue: false,
84
+ }),
85
+ },
86
+ sampleData: {
87
+ '.tag': 'folder',
88
+ name: 'Project Docs',
89
+ id: 'id:a4ayc_80_OEAAAAAAAAAXw',
90
+ path_display: '/Work/Project Docs',
91
+ path_lower: '/work/project docs',
92
+ },
93
+ onEnable: (context) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
94
+ var _a;
95
+ const cursor = yield getLatestCursor(context.auth.access_token, context.propsValue.path || '', (_a = context.propsValue.recursive) !== null && _a !== void 0 ? _a : false);
96
+ yield context.store.put('cursor', cursor);
97
+ }),
98
+ onDisable: (context) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
99
+ yield context.store.delete('cursor');
100
+ }),
101
+ run: (context) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
102
+ const cursor = yield context.store.get('cursor');
103
+ if (!cursor)
104
+ return [];
105
+ const { folders, newCursor } = yield getChangedFolders(context.auth.access_token, cursor);
106
+ yield context.store.put('cursor', newCursor);
107
+ return folders;
108
+ }),
109
+ test: (context) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
110
+ var _a;
111
+ return listRecentFolders(context.auth.access_token, context.propsValue.path || '', (_a = context.propsValue.recursive) !== null && _a !== void 0 ? _a : false);
112
+ }),
113
+ });
114
+ //# sourceMappingURL=new-folder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"new-folder.js","sourceRoot":"","sources":["../../../src/lib/triggers/new-folder.ts"],"names":[],"mappings":";;;;AAAA,qGAAqG;AACrG,qEAAqE;AACrE,gEAImC;AAEnC,0DAIgC;AAChC,kCAAsC;AAgBtC,uEAAuE;AACvE,4EAA4E;AAC5E,MAAM,eAAe,GAAG,CACtB,WAAmB,EACnB,IAAY,EACZ,SAAkB,EACD,EA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AO,EAAE,EAAE;;QACtB,OAAO,iBAAiB,CACtB,OAAO,CAAC,IAAI,CAAC,YAAY,EACzB,OAAO,CAAC,UAAU,CAAC,IAAI,IAAI,EAAE,EAC7B,MAAA,OAAO,CAAC,UAAU,CAAC,SAAS,mCAAI,KAAK,CACtC,CAAC;IACJ,CAAC,CAAA;CACF,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
2
  "name": "@divyacon/piece-dropbox",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "DivyaCon dropbox connector",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "require": "./dist/index.js",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "src",
17
+ "LICENSE.MIT-AP"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsc -p tsconfig.json",
21
+ "vendor": "node ../scripts/vendor-ap.mjs piece-dropbox"
22
+ },
23
+ "dependencies": {
24
+ "@agnocon/core-utils": "0.2.0",
25
+ "@agnocon/piece-types": "0.3.1",
26
+ "@agnocon/pieces-common": "0.12.8",
27
+ "@agnocon/pieces-framework": "0.36.0",
28
+ "tslib": "2.6.2"
29
+ },
30
+ "devDependencies": {
31
+ "@types/node": "20.17.6",
32
+ "typescript": "5.5.4"
33
+ },
34
+ "license": "MIT",
35
+ "agnocon": {
36
+ "originVersion": "0.7.5"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public",
40
+ "tag": "latest"
41
+ },
42
+ "keywords": [
43
+ "agnocon",
44
+ "connector"
45
+ ]
6
46
  }
package/src/index.ts ADDED
@@ -0,0 +1,59 @@
1
+ import { createCustomApiCallAction } from '@agnocon/pieces-common';
2
+ import {
3
+ createPiece,
4
+ } from '@agnocon/pieces-framework';
5
+ import { PieceCategory } from '@agnocon/pieces-framework';
6
+ import { dropboxCopyFile } from './lib/actions/copy-file';
7
+ import { dropboxCopyFolder } from './lib/actions/copy-folder';
8
+ import { dropboxCreateNewFolder } from './lib/actions/create-new-folder';
9
+ import { dropboxCreateNewTextFile } from './lib/actions/create-new-text-file';
10
+ import { dropboxDeleteFile } from './lib/actions/delete-file';
11
+ import { dropboxDeleteFolder } from './lib/actions/delete-folder';
12
+ import { dropboxGetFileLink } from './lib/actions/get-file-link';
13
+ import { dropboxListAFolder } from './lib/actions/list-a-folder';
14
+ import { dropboxMoveFile } from './lib/actions/move-file';
15
+ import { dropboxMoveFolder } from './lib/actions/move-folder';
16
+ import { dropboxSearch } from './lib/actions/search';
17
+ import { dropboxUploadFile } from './lib/actions/upload-file';
18
+ import { dropboxDownloadFile } from './lib/actions/download-file';
19
+ import { dropboxAuth } from './lib/auth';
20
+ import { dropboxNewFolder } from './lib/triggers/new-folder';
21
+
22
+ export const dropbox = createPiece({
23
+ minimumSupportedRelease: '0.30.0',
24
+ logoUrl: 'https://cdn.activepieces.com/pieces/dropbox.png',
25
+ actions: [
26
+ dropboxSearch,
27
+ dropboxCreateNewTextFile,
28
+ dropboxUploadFile,
29
+ dropboxDownloadFile,
30
+ dropboxGetFileLink,
31
+ dropboxDeleteFile,
32
+ dropboxMoveFile,
33
+ dropboxCopyFile,
34
+ dropboxCreateNewFolder,
35
+ dropboxDeleteFolder,
36
+ dropboxMoveFolder,
37
+ dropboxCopyFolder,
38
+ dropboxListAFolder,
39
+ createCustomApiCallAction({
40
+ baseUrl: () => 'https://api.dropboxapi.com/2',
41
+ auth: dropboxAuth,
42
+ authMapping: async (auth) => ({
43
+ Authorization: `Bearer ${auth.access_token}`,
44
+ }),
45
+ }),
46
+ ],
47
+ displayName: 'Dropbox',
48
+ description: 'Cloud storage and file synchronization',
49
+ authors: [
50
+ 'BastienMe',
51
+ 'kishanprmr',
52
+ 'MoShizzle',
53
+ 'khaledmashaly',
54
+ 'abuaboud',
55
+ ],
56
+ categories: [PieceCategory.CONTENT_AND_FILES],
57
+ triggers: [dropboxNewFolder],
58
+ auth: dropboxAuth,
59
+ });
@@ -0,0 +1,66 @@
1
+ import { createAction, Property } from '@agnocon/pieces-framework';
2
+ import {
3
+ httpClient,
4
+ HttpMethod,
5
+ AuthenticationType,
6
+ } from '@agnocon/pieces-common';
7
+ import { dropboxAuth } from '../auth';
8
+
9
+ export const dropboxCopyFile = createAction({
10
+ auth: dropboxAuth,
11
+ name: 'copy_dropbox_file',
12
+ description: 'Copy a file',
13
+ audience: 'both',
14
+ aiMetadata: { description: 'Copies the file at the source path to a new destination path within Dropbox, leaving the original in place; optionally autorenames on conflict. Use to duplicate a single file. Not idempotent: each call creates a copy, so repeating it errors on conflict or, with autorename, produces additional duplicates.', idempotent: false },
15
+ displayName: 'Copy file',
16
+ props: {
17
+ from_path: Property.ShortText({
18
+ displayName: 'From Path',
19
+ description: 'The source path of the file (e.g. /folder1/sourcefile.txt)',
20
+ required: true,
21
+ }),
22
+ to_path: Property.ShortText({
23
+ displayName: 'To Path',
24
+ description:
25
+ 'The destination path for the copied (e.g. /folder2/destinationfile.txt)',
26
+ required: true,
27
+ }),
28
+ autorename: Property.Checkbox({
29
+ displayName: 'Auto Rename',
30
+ description:
31
+ "If there's a conflict, have the Dropbox server try to autorename the file to avoid conflict.",
32
+ defaultValue: false,
33
+ required: false,
34
+ }),
35
+ allow_ownership_transfer: Property.Checkbox({
36
+ displayName: 'Allow Ownership Transfer',
37
+ description:
38
+ 'Allows copy by owner even if it would result in an ownership transfer.',
39
+ defaultValue: false,
40
+ required: false,
41
+ }),
42
+ },
43
+ async run(context) {
44
+ const params = {
45
+ from_path: context.propsValue.from_path,
46
+ to_path: context.propsValue.to_path,
47
+ autorename: context.propsValue.autorename,
48
+ allow_ownership_transfer: context.propsValue.allow_ownership_transfer,
49
+ };
50
+
51
+ const result = await httpClient.sendRequest({
52
+ method: HttpMethod.POST,
53
+ url: `https://api.dropboxapi.com/2/files/copy_v2`,
54
+ headers: {
55
+ 'Content-Type': 'application/json',
56
+ },
57
+ body: params,
58
+ authentication: {
59
+ type: AuthenticationType.BEARER_TOKEN,
60
+ token: context.auth.access_token,
61
+ },
62
+ });
63
+
64
+ return result.body;
65
+ },
66
+ });
@@ -0,0 +1,66 @@
1
+ import { createAction, Property } from '@agnocon/pieces-framework';
2
+ import {
3
+ httpClient,
4
+ HttpMethod,
5
+ AuthenticationType,
6
+ } from '@agnocon/pieces-common';
7
+ import { dropboxAuth } from '../auth';
8
+
9
+ export const dropboxCopyFolder = createAction({
10
+ auth: dropboxAuth,
11
+ name: 'copy_dropbox_folder',
12
+ description: 'Copy a folder',
13
+ audience: 'both',
14
+ aiMetadata: { description: 'Copies the folder at the source path, including its contents, to a new destination path within Dropbox, leaving the original in place; optionally autorenames on conflict. Use to duplicate an entire directory. Not idempotent: each call creates a copy, so repeating it errors on conflict or, with autorename, produces additional duplicates.', idempotent: false },
15
+ displayName: 'Copy folder',
16
+ props: {
17
+ from_path: Property.ShortText({
18
+ displayName: 'From Path',
19
+ description: 'The source path of the folder (e.g. /folder1/sourceFolder)',
20
+ required: true,
21
+ }),
22
+ to_path: Property.ShortText({
23
+ displayName: 'To Path',
24
+ description:
25
+ 'The destination path for the copied folder (e.g. /folder2/destinationFolder)',
26
+ required: true,
27
+ }),
28
+ autorename: Property.Checkbox({
29
+ displayName: 'Auto Rename',
30
+ description:
31
+ "If there's a conflict, have the Dropbox server try to autorename the folder to avoid conflict.",
32
+ defaultValue: false,
33
+ required: false,
34
+ }),
35
+ allow_ownership_transfer: Property.Checkbox({
36
+ displayName: 'Allow Ownership Transfer',
37
+ description:
38
+ 'Allows copy by owner even if it would result in an ownership transfer.',
39
+ defaultValue: false,
40
+ required: false,
41
+ }),
42
+ },
43
+ async run(context) {
44
+ const params = {
45
+ from_path: context.propsValue.from_path,
46
+ to_path: context.propsValue.to_path,
47
+ autorename: context.propsValue.autorename,
48
+ allow_ownership_transfer: context.propsValue.allow_ownership_transfer,
49
+ };
50
+
51
+ const result = await httpClient.sendRequest({
52
+ method: HttpMethod.POST,
53
+ url: `https://api.dropboxapi.com/2/files/copy_v2`,
54
+ headers: {
55
+ 'Content-Type': 'application/json',
56
+ },
57
+ body: params,
58
+ authentication: {
59
+ type: AuthenticationType.BEARER_TOKEN,
60
+ token: context.auth.access_token,
61
+ },
62
+ });
63
+
64
+ return result.body;
65
+ },
66
+ });
@@ -0,0 +1,54 @@
1
+ import { createAction, Property } from '@agnocon/pieces-framework';
2
+ import {
3
+ HttpRequest,
4
+ HttpMethod,
5
+ AuthenticationType,
6
+ httpClient,
7
+ } from '@agnocon/pieces-common';
8
+ import { dropboxAuth } from '../auth';
9
+
10
+ export const dropboxCreateNewFolder = createAction({
11
+ auth: dropboxAuth,
12
+ name: 'create_new_dropbox_folder',
13
+ description: 'Create a new empty folder',
14
+ audience: 'both',
15
+ aiMetadata: { description: 'Creates a new empty folder at the given Dropbox path; optionally autorenames on conflict. Use to set up a destination directory before placing files. Not idempotent: a repeat call for an existing path errors (or, with autorename, creates a differently named folder).', idempotent: false },
16
+ displayName: 'Create New Folder',
17
+ props: {
18
+ path: Property.ShortText({
19
+ displayName: 'Path',
20
+ description: 'The path of the new folder e.g. /Homework/math',
21
+ required: true,
22
+ }),
23
+ autorename: Property.Checkbox({
24
+ displayName: 'Auto Rename',
25
+ description:
26
+ "If there's a conflict, have the Dropbox server try to autorename the folder to avoid the conflict. The default for this field is False.",
27
+ required: false,
28
+ }),
29
+ },
30
+ async run(context) {
31
+ const body = {
32
+ autorename: context.propsValue.autorename ? true : false,
33
+ path: context.propsValue.path,
34
+ };
35
+
36
+ const request: HttpRequest = {
37
+ method: HttpMethod.POST,
38
+ url: `https://api.dropboxapi.com/2/files/create_folder_v2`,
39
+ body,
40
+ authentication: {
41
+ type: AuthenticationType.BEARER_TOKEN,
42
+ token: context.auth.access_token,
43
+ },
44
+ };
45
+
46
+ const result = await httpClient.sendRequest(request);
47
+
48
+ if (result.status == 200) {
49
+ return result.body;
50
+ } else {
51
+ return result;
52
+ }
53
+ },
54
+ });
@@ -0,0 +1,78 @@
1
+ import { createAction, Property } from '@agnocon/pieces-framework';
2
+ import {
3
+ HttpRequest,
4
+ HttpMethod,
5
+ AuthenticationType,
6
+ httpClient,
7
+ } from '@agnocon/pieces-common';
8
+ import { dropboxAuth } from '../auth';
9
+
10
+ export const dropboxCreateNewTextFile = createAction({
11
+ auth: dropboxAuth,
12
+ name: 'create_new_dropbox_text_file',
13
+ description: 'Create a new text file from text input',
14
+ audience: 'both',
15
+ aiMetadata: { description: 'Writes the provided text content to a new file at the given Dropbox path (upload in add mode). Use when an agent needs to persist generated or supplied text directly as a file without first producing a file object. Not idempotent: each call uploads, so repeating it can create autorenamed duplicates rather than overwriting.', idempotent: false },
16
+ displayName: 'Create New Text File',
17
+ props: {
18
+ path: Property.ShortText({
19
+ displayName: 'Path',
20
+ description: 'The path of the new folder e.g. /Homework/math',
21
+ required: true,
22
+ }),
23
+ text: Property.LongText({
24
+ displayName: 'Text',
25
+ description: 'The text to write into the file.',
26
+ required: true,
27
+ }),
28
+ autorename: Property.Checkbox({
29
+ displayName: 'Autorename',
30
+ description:
31
+ "If there's a conflict, have the Dropbox server try to autorename the folder to avoid the conflict. The default for this field is False.",
32
+ required: false,
33
+ }),
34
+ mute: Property.Checkbox({
35
+ displayName: 'Mute',
36
+ description:
37
+ "Normally, users are made aware of any file modifications in their Dropbox account via notifications in the client software. If true, this tells the clients that this modification shouldn't result in a user notification.",
38
+ required: false,
39
+ }),
40
+ strict_conflict: Property.Checkbox({
41
+ displayName: 'Strict conflict',
42
+ description:
43
+ '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.',
44
+ required: false,
45
+ }),
46
+ },
47
+ async run(context) {
48
+ const params = {
49
+ autorename: context.propsValue.autorename,
50
+ path: context.propsValue.path,
51
+ mode: 'add',
52
+ mute: context.propsValue.mute,
53
+ strict_conflict: context.propsValue.strict_conflict,
54
+ };
55
+
56
+ const request: HttpRequest = {
57
+ method: HttpMethod.POST,
58
+ url: `https://content.dropboxapi.com/2/files/upload`,
59
+ body: Buffer.from(context.propsValue.text, 'utf-8'),
60
+ authentication: {
61
+ type: AuthenticationType.BEARER_TOKEN,
62
+ token: context.auth.access_token,
63
+ },
64
+ headers: {
65
+ 'Dropbox-API-Arg': JSON.stringify(params),
66
+ 'Content-Type': 'application/octet-stream',
67
+ },
68
+ };
69
+
70
+ const result = await httpClient.sendRequest(request);
71
+
72
+ if (result.status == 200) {
73
+ return result.body;
74
+ } else {
75
+ return result;
76
+ }
77
+ },
78
+ });
@@ -0,0 +1,44 @@
1
+ import { createAction, Property } from '@agnocon/pieces-framework';
2
+ import {
3
+ httpClient,
4
+ HttpMethod,
5
+ AuthenticationType,
6
+ } from '@agnocon/pieces-common';
7
+ import { dropboxAuth } from '../auth';
8
+
9
+ export const dropboxDeleteFile = createAction({
10
+ auth: dropboxAuth,
11
+ name: 'delete_dropbox_file',
12
+ description: 'Delete a file',
13
+ audience: 'both',
14
+ aiMetadata: { description: 'Permanently deletes the file at the given Dropbox path. Use to remove a specific file an agent has resolved the path for. Effectively idempotent on the end state once the path is gone, but a repeat call fails because the path no longer exists; treat as a destructive, non-recoverable mutation.', idempotent: false },
15
+ displayName: 'Delete file',
16
+ props: {
17
+ path: Property.ShortText({
18
+ displayName: 'Path',
19
+ description:
20
+ 'The path of the file to be deleted (e.g. /folder1/file.txt)',
21
+ required: true,
22
+ }),
23
+ },
24
+ async run(context) {
25
+ const params = {
26
+ path: context.propsValue.path,
27
+ };
28
+
29
+ const result = await httpClient.sendRequest({
30
+ method: HttpMethod.POST,
31
+ url: `https://api.dropboxapi.com/2/files/delete_v2`,
32
+ headers: {
33
+ 'Content-Type': 'application/json',
34
+ },
35
+ body: { path: context.propsValue.path },
36
+ authentication: {
37
+ type: AuthenticationType.BEARER_TOKEN,
38
+ token: context.auth.access_token,
39
+ },
40
+ });
41
+
42
+ return result.body;
43
+ },
44
+ });
@@ -0,0 +1,43 @@
1
+ import { createAction, Property } from '@agnocon/pieces-framework';
2
+ import {
3
+ httpClient,
4
+ HttpMethod,
5
+ AuthenticationType,
6
+ } from '@agnocon/pieces-common';
7
+ import { dropboxAuth } from '../auth';
8
+
9
+ export const dropboxDeleteFolder = createAction({
10
+ auth: dropboxAuth,
11
+ name: 'delete_dropbox_folder',
12
+ description: 'Delete a folder',
13
+ audience: 'both',
14
+ aiMetadata: { description: 'Permanently deletes the folder at the given Dropbox path along with all of its contents. Use to remove an entire directory. Effectively idempotent on the end state once the path is gone, but a repeat call fails because the path no longer exists; treat as a destructive, non-recoverable mutation.', idempotent: false },
15
+ displayName: 'Delete folder',
16
+ props: {
17
+ path: Property.ShortText({
18
+ displayName: 'Path',
19
+ description: 'The path of the folder to be deleted (e.g. /folder1)',
20
+ required: true,
21
+ }),
22
+ },
23
+ async run(context) {
24
+ const params = {
25
+ path: context.propsValue.path,
26
+ };
27
+
28
+ const result = await httpClient.sendRequest({
29
+ method: HttpMethod.POST,
30
+ url: `https://api.dropboxapi.com/2/files/delete_v2`,
31
+ headers: {
32
+ 'Content-Type': 'application/json',
33
+ },
34
+ body: params,
35
+ authentication: {
36
+ type: AuthenticationType.BEARER_TOKEN,
37
+ token: context.auth.access_token,
38
+ },
39
+ });
40
+
41
+ return result.body;
42
+ },
43
+ });
@@ -0,0 +1,51 @@
1
+ import { createAction, Property } from '@agnocon/pieces-framework';
2
+ import {
3
+ httpClient,
4
+ HttpMethod,
5
+ AuthenticationType,
6
+ } from '@agnocon/pieces-common';
7
+ import { dropboxAuth } from '../auth';
8
+
9
+ export const dropboxDownloadFile = createAction({
10
+ auth: dropboxAuth,
11
+ name: 'downloadFile',
12
+ displayName: 'Download File',
13
+ description: 'Download a File from Dropbox',
14
+ audience: 'both',
15
+ aiMetadata: { description: 'Downloads the file at the given Dropbox path and returns it as a file object for use by later steps. Use to retrieve file contents into a flow. Read-only on Dropbox; repeating the call with the same path is safe and yields the same file.', idempotent: true },
16
+ props: {
17
+ path: Property.ShortText({
18
+ displayName: "Path",
19
+ description: "The path of the file (e.g. /folder1/file.txt)",
20
+ required: true
21
+ })
22
+ },
23
+ async run(context) {
24
+ // Capture file name, if unsuccesfull default to output.pdf
25
+ const fileName = (context.propsValue.path.match(/[^/]+$/) ?? ['output.pdf'])[0]
26
+
27
+ // For information about Dropbox JSON encoding, see https://www.dropbox.com/developers/reference/json-encoding
28
+ const dropboxApiArg = JSON.stringify({path:context.propsValue.path}).replace(/[\u007f-\uffff]/g, (c) => '\\u'+('000'+c.charCodeAt(0).toString(16)).slice(-4));
29
+
30
+ const result = await httpClient.sendRequest({
31
+ method: HttpMethod.POST,
32
+ url: `https://content.dropboxapi.com/2/files/download`,
33
+ headers: {
34
+ 'Content-Type': 'application/octet-stream',
35
+ 'Dropbox-API-Arg': dropboxApiArg
36
+ },
37
+ authentication: {
38
+ type: AuthenticationType.BEARER_TOKEN,
39
+ token: context.auth.access_token,
40
+ },
41
+ responseType:'arraybuffer'
42
+ });
43
+
44
+ return {
45
+ file: await context.files.write({
46
+ fileName: fileName,
47
+ data: Buffer.from(result.body)
48
+ })
49
+ }
50
+ },
51
+ });