js-webflow-api
js-webflow-api copied to clipboard
`webflow.updateItem(...)` method inconsistent with other methods
Hi!
The webflow.updateItem(...)
method introduced a spread operation in the arguments that makes it behavior differently (and unnecessary) from other methods on the object.
The documentation (READme.md) specifies that both the updateItem
and createItem
methods can be used like so:
// Create a new item
await webflow.createItem({
collectionId,
fields,
});
// Update an item
await webflow.updateItem({
collectionId,
itemId,
fields,
});
However, the updateItem
function doesn't work like this, as the method uses a spread operator and thus expects all fields to be at the top level of the passed object:
async updateItem({ collectionId, itemId, ...fields }: { itemId: string; collectionId: string }) {
const _params = { collectionId, itemId, fields };
const res = await Item.update(_params, this.client);
return new Item(this.client, res);
}
This means that in order to use the method, you must use the following patter:
// Update an item
await webflow.updateItem({
collectionId,
itemId,
...fields,
});
This is a little awkward...and could be improved in the future by making a breaking change in the next major version bump.
In the meantime, updating the docs should help 👍
This also caused me issues