1+ import { WebflowClient } from "webflow-api" ;
2+ import constants from "./common/constants.mjs" ;
3+
14export default {
25 type : "app" ,
36 app : "webflow_v2" ,
4- propDefinitions : { } ,
7+ propDefinitions : {
8+ domains : {
9+ label : "Domain" ,
10+ description : "The list of domains." ,
11+ type : "string[]" ,
12+ async options ( { siteId } ) {
13+ const domains = await this . getDomains ( siteId ) ;
14+
15+ return domains . map ( ( domain ) => domain . name ) ;
16+ } ,
17+ } ,
18+ sites : {
19+ label : "Site" ,
20+ description : "The list of sites" ,
21+ type : "string" ,
22+ async options ( ) {
23+ const sites = await this . getSites ( ) ;
24+
25+ return sites . map ( ( site ) => ( {
26+ label : site . name ,
27+ value : site . _id ,
28+ } ) ) ;
29+ } ,
30+ } ,
31+ collections : {
32+ label : "Collection" ,
33+ description : "The list of collection of a site" ,
34+ type : "string" ,
35+ async options ( { siteId } ) {
36+ const collections = await this . getCollections ( siteId ) ;
37+
38+ return collections . map ( ( collection ) => ( {
39+ label : collection . name ,
40+ value : collection . _id ,
41+ } ) ) ;
42+ } ,
43+ } ,
44+ items : {
45+ label : "Item" ,
46+ description : "The list of items of a collection" ,
47+ type : "string" ,
48+ async options ( {
49+ collectionId, page,
50+ } ) {
51+ const items = await this . getItems ( page , collectionId ) ;
52+
53+ return items . map ( ( item ) => ( {
54+ label : item . name ,
55+ value : item . _id ,
56+ } ) ) ;
57+ } ,
58+ } ,
59+ orders : {
60+ label : "Order" ,
61+ description : "The list of orders of a site" ,
62+ type : "string" ,
63+ async options ( {
64+ siteId, page,
65+ } ) {
66+ const items = await this . getOrders ( {
67+ page,
68+ siteId,
69+ } ) ;
70+
71+ return items . map ( ( item ) => item . orderId ) ;
72+ } ,
73+ } ,
74+ } ,
575 methods : {
6- // this.$auth contains connected account data
7- authKeys ( ) {
8- console . log ( Object . keys ( this . $auth ) ) ;
76+ /**
77+ * Get the auth access token;
78+ *
79+ * @returns {string } The base auth access token.
80+ */
81+ _authToken ( ) {
82+ return this . $auth . oauth_access_token ;
83+ } ,
84+ _createApiClient ( ) {
85+ return new WebflowClient ( {
86+ accessToken : this . _authToken ( ) ,
87+ } ) ;
88+ } ,
89+ /**
90+ * Create a Webflow webhook;
91+ *
92+ * @param {siteId } ID of the site to be monitored.
93+ * @param {url } URL to webhook return.
94+ * @param {triggerType } Type of event that will be triggered.
95+ * @param {filter } Filters to be applied in webhook.
96+ *
97+ * @returns {params } The Webflow webhook.
98+ */
99+ async createWebhook ( siteId , url , triggerType , filter = { } ) {
100+ const apiClient = this . _createApiClient ( ) ;
101+
102+ return apiClient . createWebhook ( {
103+ siteId,
104+ triggerType,
105+ url,
106+ filter,
107+ } ) ;
108+ } ,
109+ /**
110+ * Remove a Webflow webhook;
111+ *
112+ * @param {siteId } ID of the site.
113+ * @param {webhookId } ID of the webhook.
114+ */
115+ async removeWebhook ( siteId , webhookId ) {
116+ const apiClient = this . _createApiClient ( ) ;
117+ return apiClient . removeWebhook ( {
118+ siteId,
119+ webhookId,
120+ } ) ;
121+ } ,
122+ /**
123+ * Get an order;
124+ *
125+ * @param {options } Options to filter the order.
126+ *
127+ * @returns {params } An order.
128+ */
129+ async getOrder ( {
130+ siteId, orderId,
131+ } ) {
132+ const apiClient = this . _createApiClient ( ) ;
133+
134+ return apiClient . get ( `/sites/${ siteId } /order/${ orderId } ` ) ;
135+ } ,
136+ /**
137+ * Get a list of orders;
138+ *
139+ * @param {options } Options to filter the orders.
140+ *
141+ * @returns {params } A list of orders.
142+ */
143+ async getOrders ( {
144+ page, siteId, status,
145+ } ) {
146+ const apiClient = this . _createApiClient ( ) ;
147+
148+ return apiClient . get ( `/sites/${ siteId } /orders` , {
149+ status : status ,
150+ offset : page ?? 0 ,
151+ limit : constants . LIMIT ,
152+ } ) ;
153+ } ,
154+ /**
155+ * Get a list of domains;
156+ *
157+ * @param {options } Options to filter the domains.
158+ *
159+ * @returns {params } A list of domains.
160+ */
161+ async getDomains ( siteId ) {
162+ const webflow = this . _createApiClient ( ) ;
163+
164+ return await webflow . domains ( {
165+ siteId,
166+ } ) ;
167+ } ,
168+ /**
169+ * Get a site;
170+ *
171+ * @param {options } Options to filter the site.
172+ *
173+ * @returns {params } A site.
174+ */
175+ async getSite ( siteId ) {
176+ const webflow = this . _createApiClient ( ) ;
177+
178+ return await webflow . site ( {
179+ siteId,
180+ } ) ;
181+ } ,
182+ /**
183+ * Get a list of sites;
184+ *
185+ * @param {options } Options to filter the sites.
186+ *
187+ * @returns {params } A list of sites.
188+ */
189+ async getSites ( ) {
190+ const webflow = this . _createApiClient ( ) ;
191+
192+ return await webflow . sites . list ( ) ;
193+ } ,
194+ /**
195+ * Get a collection;
196+ *
197+ * @param {options } Options to filter the collection.
198+ *
199+ * @returns {params } A collection.
200+ */
201+ async getCollection ( collectionId ) {
202+ const webflow = this . _createApiClient ( ) ;
203+
204+ return await webflow . collection ( {
205+ collectionId,
206+ } ) ;
207+ } ,
208+ /**
209+ * Get a list of collections;
210+ *
211+ * @param {options } Options to filter the collections.
212+ *
213+ * @returns {params } A list of collections.
214+ */
215+ async getCollections ( siteId ) {
216+ const webflow = this . _createApiClient ( ) ;
217+
218+ if ( ! siteId ) return [ ] ;
219+
220+ return await webflow . collections . list ( {
221+ siteId : siteId ,
222+ } ) ;
223+ } ,
224+ /**
225+ * Get a list of items;
226+ *
227+ * @param {options } Options to filter the items.
228+ *
229+ * @returns {params } A list of items.
230+ */
231+ async getItems ( page = 0 , collectionId ) {
232+ const webflow = this . _createApiClient ( ) ;
233+
234+ if ( ! collectionId ) return [ ] ;
235+
236+ const response = await webflow . items ( {
237+ collectionId,
238+ } , {
239+ limit : constants . LIMIT ,
240+ offset : page ,
241+ } ) ;
242+
243+ return response ;
9244 } ,
10245 } ,
11- } ;
246+ } ;
0 commit comments