Skip to content

Commit fb6999d

Browse files
committed
Initial migration - 'list sites' action
1 parent 5f75543 commit fb6999d

File tree

4 files changed

+255
-12
lines changed

4 files changed

+255
-12
lines changed

components/webflow/actions/list-sites/list-sites.mjs renamed to components/webflow_v2/actions/list-sites/list-sites.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import webflow from "../../webflow.app.mjs";
1+
import app from "../../webflow_v2.app.mjs";
22

33
export default {
4-
key: "webflow-list-sites",
4+
key: "webflow_v2-list-sites",
55
name: "List Sites",
66
description: "List sites. [See the docs here](https://developers.webflow.com/#list-sites)",
7-
version: "0.0.4",
7+
version: "0.1.{{ts}}",
88
type: "action",
99
props: {
10-
webflow,
10+
app,
1111
},
1212
async run({ $ }) {
13-
const response = await this.webflow.getSites();
13+
const response = await this.app.getSites();
1414

1515
$.export("$summary", "Successfully retrieved sites");
1616

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default {
2+
LIMIT: 100,
3+
DEPLOY_OFFSET: 25,
4+
};

components/webflow_v2/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/webflow_v2",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Webflow (v2) Components",
55
"main": "webflow_v2.app.mjs",
66
"keywords": [
@@ -9,7 +9,11 @@
99
],
1010
"homepage": "https://pipedream.com/apps/webflow_v2",
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
12+
"dependencies": {
13+
"@pipedream/platform": "^3.0.3",
14+
"webflow-api": "2.4.2"
15+
},
1216
"publishConfig": {
1317
"access": "public"
1418
}
15-
}
19+
}
Lines changed: 240 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,246 @@
1+
import { WebflowClient } from "webflow-api";
2+
import constants from "./common/constants.mjs";
3+
14
export 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

Comments
 (0)