webflow / js-webflow-api

Node.js SDK for the Webflow Data API
https://www.npmjs.com/package/webflow-api
296 stars 95 forks source link

`webflow.updateItem(...)` method inconsistent with other methods #95

Open sebscholl opened 1 year ago

sebscholl commented 1 year ago

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 👍

andrewmclagan commented 1 year ago

This also caused me issues