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: accept Web API Request object in enableAutoPreviewsFromReq() #240

Merged
merged 8 commits into from
May 26, 2022

Conversation

angeloashmore
Copy link
Member

@angeloashmore angeloashmore commented May 19, 2022

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 support for Web API Request objects containing a Web API Headers instance. Frameworks like SvelteKit use this API rather than an Express-style request object which, unlike the Web API counterpart, contains plain-object-based data.

import * as prismic from "@prismicio/client";

const headers = new Headers();
headers.set("cookie", `io.prismic.preview=abc123`);

const request = {
  headers,
  url: 'https://example.com/preview?documentId=abc123&token=abc123'
};

const client = prismic.createClient("qwerty");
client.enableAutoPreviewsFromReq(request);

// The client will automatically read the `io.prismic.preview` cookie
// and URL parameters to enable preview sessions.

For more details, see #239.

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-commenter commented May 19, 2022

Codecov Report

Merging #240 (6a0fa54) into master (f93af08) will decrease coverage by 0.26%.
The diff coverage is 95.65%.

@@             Coverage Diff             @@
##            master     #240      +/-   ##
===========================================
- Coverage   100.00%   99.73%   -0.27%     
===========================================
  Files           23       23              
  Lines          363      372       +9     
  Branches        67       74       +7     
===========================================
+ Hits           363      371       +8     
- Partials         0        1       +1     
Impacted Files Coverage Δ
src/client.ts 99.54% <95.45%> (-0.46%) ⬇️
src/lib/getCookie.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f93af08...6a0fa54. Read the comment docs.

@github-actions
Copy link

github-actions bot commented May 19, 2022

size-limit report 📦

Path Size
dist/index.js 4.06 KB (+1.12% 🔺)
dist/index.cjs 6.93 KB (+0.63% 🔺)

@angeloashmore angeloashmore changed the title feat: accept Request object containing a Headers object when using enableAutoPreviewsFromReq() feat: accept Web API Request object in enableAutoPreviewsFromReq() May 19, 2022
@angeloashmore angeloashmore requested a review from lihbr May 19, 2022 03:58
Copy link
Member

@lihbr lihbr left a comment

Choose a reason for hiding this comment

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

LGTM, just a small one to make it stronger ☺️

src/client.ts Outdated Show resolved Hide resolved
@lihbr lihbr added the enhancement New feature or request label May 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants