Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

butter.page.retrieve and butter.page.list have incorrect return type #89

Closed
AlyonaSidarenka opened this issue Jul 17, 2024 · 3 comments
Closed

Comments

@AlyonaSidarenka
Copy link

When making request for page:
const response = await butter.page.retrieve<ButterPageFieldstype, "page_type_value">( PAGE_TYPE, slug, params, );

ACTUAL result:
According to typescript files return type is:
Promise<Response<PageRetrieveResponse<PageModel, PageType, PageSlug>>>
following this, page should be available this way:
const page = response.data.data;

but in reality page is accessible like that:
const page = response.data;

EXPECTED type is
const response: Promise<PageRetrieveResponse<ButterPageFieldstype, "page_type_value">>

Note: same for await butter.page.list
ACTUAL return type: Promise<Response<PageListResponse<PageModel, PageType>>>;;
EXPECTED: Promise<PageListResponse<PageModel, PageType>>;;

might be related to the fact that you guys switched from axios to fetch and axios wraps response with data object

@abeciana1
Copy link

abeciana1 commented Jul 22, 2024

Hi @AlyonaSidarenka I'm sorry you're going through this! I'm tagging @courcelan from our team to help with this issue.

@courcelan
Copy link
Contributor

Hi @AlyonaSidarenka,

You are corrected that the response was updated when we switched to fetch; we no longer have data double wrapped.

Is your main concern here about the TS definition on the return type or that its no longer response.data.data?

We are working on updating the definition files to reflect the changes as you described.

Thanks!

courcelan added a commit that referenced this issue Jul 26, 2024
This updates the response structure to echo schema expected from TypeScript definitions and the same data schema/structure as return in buttercms-js version 1.

The response no longer returns the `xsrfCookieName`, `xsrfHeaderName`, and `maxContentLength` in `response.config` as they are not in use by native fetch. Additionally, `response.config` returns  only the fully formed `url` (`response.config.url`) rather than breaking it down in discrete parts. If needed, please use the native `URL` API in your code to get similar datapoints.

This PR fixes the issues raised in #89.

bump package version to 2.1.0
courcelan added a commit that referenced this issue Jul 26, 2024
…and v1

This updates the response structure to echo schema expected from TypeScript definitions and the same data schema/structure as return in buttercms-js version 1.

The response no longer returns the `xsrfCookieName`, `xsrfHeaderName`, and `maxContentLength` in `response.config` as they are not in use by native fetch. Additionally, `response.config` returns  only the fully formed `url` (`response.config.url`) rather than breaking it down in discrete parts. If needed, please use the native `URL` API in your code to get similar datapoints.

This PR fixes the issues raised in #89.

bump package version to 2.1.0
@AlyonaSidarenka
Copy link
Author

@courcelan thanks, confirm that using v2.1.0 fixes the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants