1+ import { axios } from "@pipedream/platform" ;
2+
13export default {
24 type : "app" ,
35 app : "agrello" ,
4- propDefinitions : { } ,
6+ propDefinitions : {
7+ folderId : {
8+ type : "string" ,
9+ label : "Folder ID" ,
10+ description : "The ID of the folder" ,
11+ async options ( { page } ) {
12+ return await this . listFolders ( {
13+ params : {
14+ page,
15+ } ,
16+ } ) ;
17+ } ,
18+ } ,
19+ documentId : {
20+ type : "string" ,
21+ label : "Document ID" ,
22+ description : "The ID of the document" ,
23+ async options ( {
24+ folderId, page,
25+ } ) {
26+ const { content } = await this . listDocuments ( {
27+ folderId,
28+ params : {
29+ page,
30+ } ,
31+ } ) ;
32+ return content . map ( ( {
33+ id : value , name : label ,
34+ } ) => ( {
35+ label,
36+ value,
37+ } ) ) ;
38+ } ,
39+ } ,
40+ } ,
541 methods : {
6- // this.$auth contains connected account data
7- authKeys ( ) {
8- console . log ( Object . keys ( this . $auth ) ) ;
42+ _baseUrl ( ) {
43+ return "https://api.agrello.io/public/v3" ;
44+ } ,
45+ _headers ( headers = { } ) {
46+ return {
47+ ...headers ,
48+ Authorization : `Bearer ${ this . $auth . oauth_access_token } ` ,
49+ } ;
50+ } ,
51+ _makeRequest ( {
52+ $ = this , path, headers, ...opts
53+ } ) {
54+ return axios ( $ , {
55+ url : this . _baseUrl ( ) + path ,
56+ headers : this . _headers ( headers ) ,
57+ ...opts ,
58+ } ) ;
59+ } ,
60+ async listFolders ( ) {
61+ const { content } = await this . _makeRequest ( {
62+ path : "/folders" ,
63+ } ) ;
64+
65+ const folders = [ ] ;
66+ for ( const parent of content ) {
67+ folders . push ( {
68+ label : `${ parent . name } ` ,
69+ value : parent . id ,
70+ } ) ;
71+ folders . push ( ...await this . getSubFolders ( parent . name , parent . id ) ) ;
72+ }
73+
74+ return folders ;
75+
76+ } ,
77+ async getSubFolders ( parentName , parentId ) {
78+ const folders = [ ] ;
79+ const { subspaces } = await this . _makeRequest ( {
80+ path : `/folders/${ parentId } /folders` ,
81+ } ) ;
82+ for ( const folder of subspaces ) {
83+ const label = `${ parentName } - ${ folder . name } ` ;
84+ folders . push ( {
85+ label,
86+ value : folder . id ,
87+ } ) ;
88+ folders . push ( ...await this . getSubFolders ( label , folder . id ) ) ;
89+ }
90+ return folders ;
91+ } ,
92+ listDocuments ( {
93+ folderId, ...opts
94+ } ) {
95+ return this . _makeRequest ( {
96+ path : `/folders/${ folderId } /containers` ,
97+ ...opts ,
98+ } ) ;
99+ } ,
100+ getDocument ( { documentId } ) {
101+ return this . _makeRequest ( {
102+ path : `/containers/${ documentId } ` ,
103+ } ) ;
104+ } ,
105+ createWebhook ( opts = { } ) {
106+ return this . _makeRequest ( {
107+ method : "POST" ,
108+ path : "/webhooks" ,
109+ ...opts ,
110+ } ) ;
111+ } ,
112+ deleteWebhook ( hookId ) {
113+ return this . _makeRequest ( {
114+ method : "DELETE" ,
115+ path : `/webhooks/${ hookId } ` ,
116+ } ) ;
117+ } ,
118+ async * paginate ( {
119+ fn, params = { } , maxResults = null , ...opts
120+ } ) {
121+ let hasMore = false ;
122+ let count = 0 ;
123+ let page = 0 ;
124+
125+ do {
126+ params . page = page ++ ;
127+ const { content } = await fn ( {
128+ params,
129+ ...opts ,
130+ } ) ;
131+ for ( const d of content ) {
132+ yield d ;
133+
134+ if ( maxResults && ++ count === maxResults ) {
135+ return count ;
136+ }
137+ }
138+
139+ hasMore = content . length ;
140+
141+ } while ( hasMore ) ;
9142 } ,
10143 } ,
11- } ;
144+ } ;
0 commit comments