Skip to content

Commit c2e688a

Browse files
committed
Collection item sources
1 parent 37a7a4e commit c2e688a

File tree

3 files changed

+14
-45
lines changed

3 files changed

+14
-45
lines changed

components/webflow_v2/sources/changed-collection-item/changed-collection-item.mjs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import common from "../common/collection-common.mjs";
33
export default {
44
type: "source",
55
key: "webflow_v2-changed-collection-item",
6-
name: "New Changed Collection Item",
6+
name: "Collection Item Updated",
77
description: "Emit new event when a collection item is changed. [See the docs here](https://developers.webflow.com/#model16)",
88
version: "0.0.{{ts}}",
99
...common,
@@ -13,11 +13,12 @@ export default {
1313
return "collection_item_changed";
1414
},
1515
generateMeta(data) {
16-
const ts = Date.parse(data["updated-on"]);
16+
const { id, fieldData, lastUpdated } = data;
17+
const ts = Date.parse(lastUpdated);
1718

1819
return {
19-
id: `${data._id}-${ts}`,
20-
summary: `Collection ${data.slug} item changed`,
20+
id: `${id}-${ts}`,
21+
summary: `Item updated: ${fieldData?.slug ?? fieldData?.name ?? id}`,
2122
ts,
2223
};
2324
},

components/webflow_v2/sources/new-collection-item/new-collection-item.mjs

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,23 @@
1-
import constants from "../../common/constants.mjs";
21
import common from "../common/common.mjs";
32

43
export default {
54
type: "source",
65
key: "webflow_v2-new-collection-item",
7-
name: "New Collection Item",
6+
name: "New Collection Item Created",
87
description: "Emit new event when a collection item is created. [See the docs here](https://developers.webflow.com/#item-model)",
98
version: "0.0.{{ts}}",
109
...common,
11-
hooks: {
12-
...common.hooks,
13-
async deploy() {
14-
if (this.collectionIds?.length !== 1) {
15-
console.log("Skipping retrieval of historical events for multiple or no Collection ID");
16-
return;
17-
}
18-
19-
const path = `/collections/${this.collectionIds[0]}/items`;
20-
console.log("Retrieving historical events...");
21-
22-
let {
23-
total,
24-
items: events,
25-
} = await this._makeRequest(path);
26-
27-
if (total > constants.LIMIT) {
28-
const offset = Math.floor(total / constants.LIMIT);
29-
30-
events = (await this._makeRequest(path, {
31-
offset,
32-
})).items.reverse();
33-
34-
events.push(...(await this._makeRequest(path, {
35-
offset: offset - 1,
36-
})).items.reverse());
37-
} else {
38-
events.reverse();
39-
}
40-
41-
this.emitHistoricalEvents(events);
42-
},
43-
},
4410
methods: {
4511
...common.methods,
4612
getWebhookTriggerType() {
4713
return "collection_item_created";
4814
},
4915
generateMeta(data) {
16+
const { id, fieldData } = data;
5017
return {
51-
id: data._id,
52-
summary: `New collection item ${data.slug} created`,
53-
ts: Date.parse(data["created-on"]),
18+
id,
19+
summary: `New item: ${fieldData?.slug ?? fieldData?.name ?? id}`,
20+
ts: Date.parse(data["createdOn"]),
5421
};
5522
},
5623
},

components/webflow_v2/sources/new-deleted-collection-item/new-deleted-collection-item.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ export default {
1313
return "collection_item_deleted";
1414
},
1515
generateMeta(data) {
16+
const { id } = data;
1617
return {
17-
id: data.itemId,
18-
summary: `Item ${data.itemId} deleted`,
19-
ts: Date.parse(data["created-on"]),
18+
id,
19+
summary: `Item deleted: ${id}`,
20+
ts: Date.now(),
2021
};
2122
},
2223
},

0 commit comments

Comments
 (0)