@sanity/preview-url-secret
Advanced tools
Comparing version 1.6.0 to 1.6.1
@@ -1,15 +0,16 @@ | ||
# Changelog | ||
<!-- markdownlint-disable --><!-- textlint-disable --> | ||
### Dependencies | ||
# 📓 Changelog | ||
* The following workspace dependencies were updated | ||
* devDependencies | ||
* @sanity/channels bumped to 0.1.0 | ||
All notable changes to this project will be documented in this file. See | ||
[Conventional Commits](https://conventionalcommits.org) for commit guidelines. | ||
### Dependencies | ||
* The following workspace dependencies were updated | ||
* devDependencies | ||
* @sanity/channels bumped from 0.2.0 to 0.3.0 | ||
## [1.6.1](https://github.com/sanity-io/visual-editing/compare/preview-url-secret-v1.6.0...preview-url-secret-v1.6.1) (2024-02-05) | ||
### Bug Fixes | ||
* add previewMode, deprecate draftMode ([#833](https://github.com/sanity-io/visual-editing/issues/833)) ([92cf3dc](https://github.com/sanity-io/visual-editing/commit/92cf3dc7e2236a98f8cc10faa3b73d1deb5a4dc2)) | ||
## [1.6.0](https://github.com/sanity-io/visual-editing/compare/preview-url-secret-v1.5.5...preview-url-secret-v1.6.0) (2024-02-02) | ||
@@ -16,0 +17,0 @@ |
@@ -53,14 +53,30 @@ /** | ||
/** | ||
* The API route that securely puts the app in a "Draft Mode" | ||
* Next.js docs: https://nextjs.org/docs/app/building-your-application/configuring/draft-mode | ||
* @deprecated - use `previewMode` instead | ||
*/ | ||
draftMode: { | ||
draftMode?: { | ||
/** | ||
* The route that enables Draft Mode | ||
* @example '/api/draft' | ||
* @deprecated - use `previewMode.enable` instead | ||
*/ | ||
enable: string | ||
/** | ||
* A route that reports of Draft Mode is enabled or not, useful for debugging | ||
* @example '/api/check-draft' | ||
* @deprecated - use `previewMode.check` instead | ||
*/ | ||
check?: string | ||
/** | ||
* @deprecated - use `previewMode.disable` instead | ||
*/ | ||
disable?: string | ||
} | ||
/** | ||
* The API routes for setting the application's "Preview Mode" | ||
*/ | ||
previewMode?: { | ||
/** | ||
* The route that enables Preview Mode | ||
* @example '/api/preview' | ||
*/ | ||
enable: string | ||
/** | ||
* The route that reports if Preview Mode is enabled or not, useful for debugging | ||
* @example '/api/check-preview' | ||
* @deprecated - this API is not yet implemented | ||
@@ -70,4 +86,4 @@ */ | ||
/** | ||
* The route that disables Draft Mode, useful for debugging | ||
* @example '/api/disable-draft' | ||
* The route that disables Preview Mode, useful for debugging | ||
* @example '/api/disable-preview' | ||
* @deprecated - this API is not yet implemented | ||
@@ -74,0 +90,0 @@ */ |
@@ -1,1 +0,1 @@ | ||
import{u as e,b as t}from"./_chunks/constants-mg9CwKOs.js";function n(n){const{draftMode:a,origin:r=("undefined"==typeof location?"https://localhost":location.origin)}=n;let{preview:o="/"}=n;const i=new URL(o,r),c=a.enable?new URL(a.enable,r):void 0;return async a=>{try{if(a.previewSearchParam){const e=new URL(a.previewSearchParam,i);e.origin===i.origin&&(o="".concat(e.pathname).concat(e.search))}else if(a.referrer){const e=new URL(a.referrer);e.origin===i.origin&&(o="".concat(e.pathname).concat(e.search))}}catch{}"undefined"!=typeof location&&location.origin===i.origin&&a.studioBasePath&&(o.startsWith("".concat(a.studioBasePath,"/"))||o===a.studioBasePath)&&(o=n.preview||"/");const r=new URL(o,i);if(c){const n=new URL(c),{searchParams:o}=n;return o.set(e,a.previewUrlSecret),r.pathname!==n.pathname&&o.set(t,"".concat(r.pathname).concat(r.search)),n.toString()}return r.toString()}}export{n as definePreviewUrl};//# sourceMappingURL=define-preview-url.js.map | ||
import{u as e,b as n}from"./_chunks/constants-mg9CwKOs.js";function t(t){const{draftMode:a,previewMode:o,origin:r=("undefined"==typeof location?"https://localhost":location.origin)}=t,i=(null==o?void 0:o.enable)||(null==a?void 0:a.enable);let{preview:c="/"}=t;const s=new URL(c,r),h=i?new URL(i,r):void 0;return async a=>{try{if(a.previewSearchParam){const e=new URL(a.previewSearchParam,s);e.origin===s.origin&&(c="".concat(e.pathname).concat(e.search))}else if(a.referrer){const e=new URL(a.referrer);e.origin===s.origin&&(c="".concat(e.pathname).concat(e.search))}}catch{}"undefined"!=typeof location&&location.origin===s.origin&&a.studioBasePath&&(c.startsWith("".concat(a.studioBasePath,"/"))||c===a.studioBasePath)&&(c=t.preview||"/");const o=new URL(c,s);if(h){const t=new URL(h),{searchParams:r}=t;return r.set(e,a.previewUrlSecret),o.pathname!==t.pathname&&r.set(n,"".concat(o.pathname).concat(o.search)),t.toString()}return o.toString()}}export{t as definePreviewUrl};//# sourceMappingURL=define-preview-url.js.map |
{ | ||
"name": "@sanity/preview-url-secret", | ||
"version": "1.6.0", | ||
"version": "1.6.1", | ||
"homepage": "https://github.com/sanity-io/visual-editing/tree/main/packages/preview-url-secret#readme", | ||
@@ -171,3 +171,3 @@ "bugs": { | ||
"@sanity/client": "^6.12.3", | ||
"@sanity/icons": "^2.10.0", | ||
"@sanity/icons": "^2.10.1", | ||
"@sanity/pkg-utils": "^4.1.2", | ||
@@ -174,0 +174,0 @@ "@typescript-eslint/eslint-plugin": "^6.20.0", |
@@ -27,3 +27,3 @@ # @sanity/preview-url-secret | ||
origin: 'http://localhost:3000', | ||
draftMode: { | ||
previewMode: { | ||
enable: '/api/draft', | ||
@@ -30,0 +30,0 @@ }, |
@@ -19,2 +19,3 @@ import { | ||
draftMode, | ||
previewMode, | ||
origin = typeof location === 'undefined' | ||
@@ -24,6 +25,7 @@ ? 'https://localhost' | ||
} = options | ||
const enableUrl = previewMode?.enable || draftMode?.enable | ||
let { preview = '/' } = options | ||
const productionUrl = new URL(preview, origin) | ||
const enableDraftModeUrl = draftMode.enable | ||
? new URL(draftMode.enable, origin) | ||
const enablePreviewModeUrl = enableUrl | ||
? new URL(enableUrl, origin) | ||
: undefined | ||
@@ -58,7 +60,7 @@ | ||
const previewUrl = new URL(preview, productionUrl) | ||
if (enableDraftModeUrl) { | ||
const enableDraftModeRequestUrl = new URL(enableDraftModeUrl) | ||
const { searchParams } = enableDraftModeRequestUrl | ||
if (enablePreviewModeUrl) { | ||
const enablePreviewModeRequestUrl = new URL(enablePreviewModeUrl) | ||
const { searchParams } = enablePreviewModeRequestUrl | ||
searchParams.set(urlSearchParamPreviewSecret, context.previewUrlSecret) | ||
if (previewUrl.pathname !== enableDraftModeRequestUrl.pathname) { | ||
if (previewUrl.pathname !== enablePreviewModeRequestUrl.pathname) { | ||
searchParams.set( | ||
@@ -70,3 +72,3 @@ urlSearchParamPreviewPathname, | ||
return enableDraftModeRequestUrl.toString() | ||
return enablePreviewModeRequestUrl.toString() | ||
} | ||
@@ -73,0 +75,0 @@ return previewUrl.toString() |
@@ -81,14 +81,30 @@ /** @internal */ | ||
/** | ||
* The API route that securely puts the app in a "Draft Mode" | ||
* Next.js docs: https://nextjs.org/docs/app/building-your-application/configuring/draft-mode | ||
* @deprecated - use `previewMode` instead | ||
*/ | ||
draftMode: { | ||
draftMode?: { | ||
/** | ||
* The route that enables Draft Mode | ||
* @example '/api/draft' | ||
* @deprecated - use `previewMode.enable` instead | ||
*/ | ||
enable: string | ||
/** | ||
* A route that reports of Draft Mode is enabled or not, useful for debugging | ||
* @example '/api/check-draft' | ||
* @deprecated - use `previewMode.check` instead | ||
*/ | ||
check?: string | ||
/** | ||
* @deprecated - use `previewMode.disable` instead | ||
*/ | ||
disable?: string | ||
} | ||
/** | ||
* The API routes for setting the application's "Preview Mode" | ||
*/ | ||
previewMode?: { | ||
/** | ||
* The route that enables Preview Mode | ||
* @example '/api/preview' | ||
*/ | ||
enable: string | ||
/** | ||
* The route that reports if Preview Mode is enabled or not, useful for debugging | ||
* @example '/api/check-preview' | ||
* @deprecated - this API is not yet implemented | ||
@@ -98,4 +114,4 @@ */ | ||
/** | ||
* The route that disables Draft Mode, useful for debugging | ||
* @example '/api/disable-draft' | ||
* The route that disables Preview Mode, useful for debugging | ||
* @example '/api/disable-preview' | ||
* @deprecated - this API is not yet implemented | ||
@@ -102,0 +118,0 @@ */ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
109043
887