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

feat: pass arbitrary options to fetch() with the fetchOptions parameter #9

Merged
merged 2 commits into from
Dec 5, 2023

Conversation

angeloashmore
Copy link
Member

@angeloashmore angeloashmore commented Dec 2, 2023

Types of changes

  • Chore (a non-breaking change which is related to package maintenance)
  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

This PR adds a fetchOptions parameter to all methods that use fetch() (getAllCustomTypes(), updateCustomType(), etc.).

The option allows developers to add arbitrary options to fetch() requests, such as cache and headers.

fetchOptions can be provided to createClient(), which will set fetch() options for all network requests.

const client = createClient({
  repositoryName: "example-prismic-repo",
  token: "token",
  fetchOptions: {
    cache: "force-cache",
  },
});

Alternatively, fetchOptions can be passed to any method that uses fetch() in its implementation. Options passed to methods will be merged with and override ones passed to createClient().

const client = createClient({
  repositoryName: "example-prismic-repo",
  token: "token",
});

const customTypes = await client.getAllCustomTypes({
  fetchOptions: {
    cache: "force-cache",
  },
});

The feature works identically to @prismicio/client's fetchOptions parameter.

See prismicio/prismic-client#291 for more details on the @prismcio/client implementation.

This PR supersedes #8.

Checklist:

  • My change requires an update to the official documentation.
  • All TSDoc comments are up-to-date and new ones have been added where necessary.
  • All new and existing tests are passing.

🪿

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (a3594f6) 100.00% compared to head (7dada7a) 100.00%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff            @@
##              main        #9   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines          611       641   +30     
  Branches        34        37    +3     
=========================================
+ Hits           611       641   +30     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Dec 2, 2023

size-limit report 📦

Path Size
dist/index.js 1.17 KB (+8.06% 🔺)
dist/index.cjs 1.44 KB (+6.41% 🔺)

Copy link
Collaborator

@xrutayisire xrutayisire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super cool! I had again forgotten about this work!
LGTM, did you testing yet with Slice Machine? Do you want to create an alpha to test or directly a release? Anyway, if you can update our version in SM to use this one it would be the prefect end to the topic 🙂

@angeloashmore
Copy link
Member Author

angeloashmore commented Dec 5, 2023

@xrutayisire: Super cool! I had again forgotten about this work! LGTM, did you testing yet with Slice Machine? Do you want to create an alpha to test or directly a release? Anyway, if you can update our version in SM to use this one it would be the prefect end to the topic 🙂

Let's go for a direct release on this package since it is tested.

I confirmed it works with Slice Machine and added/updated tests to ensure we're continuing to send the User-Agent header. I'll update Slice Machine once this update is published. 👍

@angeloashmore angeloashmore merged commit ae76fe8 into main Dec 5, 2023
1 check passed
@angeloashmore angeloashmore deleted the aa/fetch-options branch December 5, 2023 04:27
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

Successfully merging this pull request may close these issues.

None yet

3 participants