@sanity/preview-url-secret
Advanced tools
Comparing version 0.2.1-pink-lizard to 0.3.0-pink-lizard
# Changelog | ||
## [0.3.0-pink-lizard](https://github.com/sanity-io/visual-editing/compare/preview-url-secret-v0.2.1-pink-lizard...preview-url-secret-v0.3.0-pink-lizard) (2023-11-10) | ||
### Features | ||
* generate secrets on demand ([9b47760](https://github.com/sanity-io/visual-editing/commit/9b477607edc2f3b89e03e0c64c9f7a92687f7c25)) | ||
### Bug Fixes | ||
* don't show secret url search params in navbar ([4c684f1](https://github.com/sanity-io/visual-editing/commit/4c684f11c981bd0788cc2a8b5f9fcc4c7e9e9693)) | ||
* implement url validation on the api handler side ([ca0c856](https://github.com/sanity-io/visual-editing/commit/ca0c856637e5c00200e02c708e02814319a9e55f)) | ||
* keep preview url in sync (figure out cleaning hidden search params later) ([38912e1](https://github.com/sanity-io/visual-editing/commit/38912e17a86f17e0886aac9ae43dc3aa3299a574)) | ||
* mark API that's not yet implemented ([53c0a33](https://github.com/sanity-io/visual-editing/commit/53c0a339b02ab6f5e7925740eb7ef888c227e2b6)) | ||
* quote query string ([90006be](https://github.com/sanity-io/visual-editing/commit/90006be863b388c688f659eb37dba8bb759a2ee2)) | ||
## [0.2.1-pink-lizard](https://github.com/sanity-io/visual-editing/compare/preview-url-secret-v0.2.0-pink-lizard...preview-url-secret-v0.2.1-pink-lizard) (2023-11-10) | ||
@@ -4,0 +20,0 @@ |
@@ -0,4 +1,41 @@ | ||
import type { SanityClient } from '@sanity/client' | ||
/** @internal */ | ||
export declare function createPreviewSecret(): Promise<string> | ||
export declare function createPreviewSecret( | ||
_client: SanityClient, | ||
source: string, | ||
studioUrl: string, | ||
id?: string, | ||
): Promise<string> | ||
/** | ||
* A subset type that's compatible with most SanityClient typings, | ||
* this makes it easier to use this package in libraries that may use `import type { SanityClient } from 'sanity'` | ||
* as well as those that use `import type { SanityClient } from '@sanity/client'` | ||
* @internal | ||
*/ | ||
export declare type SanityClientLike = { | ||
config(): { | ||
token?: string | ||
} | ||
withConfig(config: { | ||
apiVersion?: string | ||
useCdn?: boolean | ||
perspective?: 'published' | ||
resultSourceMap?: boolean | ||
}): SanityClientLike | ||
fetch< | ||
R, | ||
Q = { | ||
[key: string]: any | ||
}, | ||
>( | ||
query: string, | ||
params: Q, | ||
options: { | ||
tag?: string | ||
}, | ||
): Promise<R> | ||
} | ||
export {} |
@@ -1,1 +0,1 @@ | ||
async function n(){return"TODO"}export{n as createPreviewSecret};//# sourceMappingURL=create-secret.js.map | ||
import{uuid as t}from"@sanity/uuid";import{a as e,s as r,t as a,c as n}from"./_chunks/constants-M5g_6bzK.js";async function o(o,c,i,s=t()){const p=o.withConfig({apiVersion:e}),u=`${n}.${s}`,l=function(){if("undefined"!=typeof crypto){const t=new Uint8Array(16);crypto.getRandomValues(t);let e="";for(let r=0;r<t.length;r++)e+=t[r].toString(16).padStart(2,"0");return e=btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/[=]+$/,""),e}return Math.random().toString(36).slice(2)}(),f=p.patch(u).set({secret:l,source:c,studioUrl:i});return await p.transaction().createOrReplace({_id:u,_type:r}).patch(f).commit({tag:a}),l}export{o as createPreviewSecret};//# sourceMappingURL=create-secret.js.map |
@@ -44,2 +44,3 @@ /** | ||
* @example '/api/check-draft' | ||
* @deprecated - this API is not yet implemented | ||
*/ | ||
@@ -50,2 +51,3 @@ check?: string | ||
* @example '/api/disable-draft' | ||
* @deprecated - this API is not yet implemented | ||
*/ | ||
@@ -52,0 +54,0 @@ disable?: string |
@@ -1,1 +0,1 @@ | ||
import{a as e,u as t}from"./_chunks/constants-YdXKqiF_.js";function n(n){const{draftMode:a,origin:r,preview:s="/"}=n,i=new URL(s,r),o=a.enable?new URL(a.enable,r):void 0;return async n=>{const a=new URL(n.previewSearchParam||s,i);if(o){const r=new URL(o),{searchParams:s}=r;return s.set(e,n.previewUrlSecret),a.pathname.startsWith("/api")||a.pathname===r.pathname||s.set(t,a.pathname),r.toString()}return a.toString()}}export{n as definePreviewUrl};//# sourceMappingURL=define-preview-url.js.map | ||
import{u as e,b as n}from"./_chunks/constants-M5g_6bzK.js";function r(r){const{draftMode:t,origin:a,preview:s="/"}=r,o=new URL(s,a),i=t.enable?new URL(t.enable,a):void 0;return async r=>{const t=new URL(r.previewSearchParam||s,o);if(i){const a=new URL(i),{searchParams:s}=a;return s.set(e,r.previewUrlSecret),t.pathname!==a.pathname&&s.set(n,t.pathname),a.toString()}return t.toString()}}export{r as definePreviewUrl};//# sourceMappingURL=define-preview-url.js.map |
@@ -5,3 +5,3 @@ import cjs from './index.cjs'; | ||
export const urlSearchParamPreviewSecret = cjs.urlSearchParamPreviewSecret; | ||
export const validateUrlSecret = cjs.validateUrlSecret; | ||
export const validatePreviewUrl = cjs.validatePreviewUrl; | ||
@@ -0,1 +1,42 @@ | ||
/** | ||
* @alpha | ||
*/ | ||
export declare interface PreviewUrlValidateUrlResult { | ||
isValid: boolean | ||
/** | ||
* If the URL is valid, and there's a parameter for what preview path to redirect to, it will be here | ||
*/ | ||
redirectTo?: string | ||
} | ||
/** | ||
* A subset type that's compatible with most SanityClient typings, | ||
* this makes it easier to use this package in libraries that may use `import type { SanityClient } from 'sanity'` | ||
* as well as those that use `import type { SanityClient } from '@sanity/client'` | ||
* @internal | ||
*/ | ||
export declare type SanityClientLike = { | ||
config(): { | ||
token?: string | ||
} | ||
withConfig(config: { | ||
apiVersion?: string | ||
useCdn?: boolean | ||
perspective?: 'published' | ||
resultSourceMap?: boolean | ||
}): SanityClientLike | ||
fetch< | ||
R, | ||
Q = { | ||
[key: string]: any | ||
}, | ||
>( | ||
query: string, | ||
params: Q, | ||
options: { | ||
tag?: string | ||
}, | ||
): Promise<R> | ||
} | ||
/** @internal */ | ||
@@ -7,8 +48,10 @@ export declare const urlSearchParamPreviewPathname = 'sanity-preview-pathname' | ||
/** @internal */ | ||
export declare function validateUrlSecret<SanityClientType>( | ||
client: SanityClientType, | ||
secret: string | null | undefined, | ||
): Promise<boolean> | ||
/** | ||
* @alpha | ||
*/ | ||
export declare function validatePreviewUrl( | ||
_client: SanityClientLike, | ||
previewUrl: string, | ||
): Promise<PreviewUrlValidateUrlResult> | ||
export {} |
@@ -1,1 +0,1 @@ | ||
export{u as urlSearchParamPreviewPathname,a as urlSearchParamPreviewSecret}from"./_chunks/constants-YdXKqiF_.js";async function e(e,r){return console.log("validateUrlSecret",{client:e,secret:r}),!0}export{e as validateUrlSecret};//# sourceMappingURL=index.js.map | ||
import{a as e,u as t,b as r,f as s,t as i,i as n}from"./_chunks/constants-M5g_6bzK.js";async function o(o,c){const a=function(t){if(!t)throw new TypeError("`client` is required");if(!t.config().token)throw new TypeError("`client` must have a `token` specified");return t.withConfig({apiVersion:e,useCdn:!1,perspective:"published",resultSourceMap:!1,stega:void 0})}(o);let u;try{u=function(e){const s=new URL(e,"http://localhost"),i=s.searchParams.get(t);if(!i)throw new Error("Missing secret");let n;const o=s.searchParams.get(r);if(o){const{pathname:e,search:t}=new URL(o,"http://localhost");n=`${e}${t}`}return{secret:i,redirectTo:n}}(c)}catch(e){return n&&console.error("Failed to parse preview URL",e,{previewUrl:c,client:a}),{isValid:!1}}const d=await async function(e,t){if("undefined"!=typeof EdgeRuntime&&await new Promise((e=>setTimeout(e,300))),!t||!t.trim())return!1;const r=await e.fetch(s,{secret:t},{tag:i,cache:"no-store"});return!!(r?._id&&r?._updatedAt&&r?.secret)&&t===r.secret}(a,u.secret);return{isValid:d,redirectTo:d?u.redirectTo:void 0}}export{r as urlSearchParamPreviewPathname,t as urlSearchParamPreviewSecret,o as validatePreviewUrl};//# sourceMappingURL=index.js.map |
{ | ||
"name": "@sanity/preview-url-secret", | ||
"version": "0.2.1-pink-lizard", | ||
"version": "0.3.0-pink-lizard", | ||
"homepage": "https://github.com/sanity-io/visual-editing/tree/main/packages/preview-url-secret#readme", | ||
@@ -51,2 +51,13 @@ "bugs": { | ||
}, | ||
"./without-secret-search-params": { | ||
"types": "./dist/without-secret-search-params.d.ts", | ||
"source": "./src/_exports/without-secret-search-params.ts", | ||
"require": "./dist/without-secret-search-params.cjs", | ||
"node": { | ||
"module": "./dist/without-secret-search-params.js", | ||
"import": "./dist/without-secret-search-params.cjs.js" | ||
}, | ||
"import": "./dist/without-secret-search-params.js", | ||
"default": "./dist/without-secret-search-params.js" | ||
}, | ||
"./package.json": "./package.json" | ||
@@ -65,2 +76,5 @@ }, | ||
"./dist/define-preview-url.d.ts" | ||
], | ||
"without-secret-search-params": [ | ||
"./dist/without-secret-search-params.d.ts" | ||
] | ||
@@ -128,2 +142,3 @@ } | ||
"devDependencies": { | ||
"@edge-runtime/types": "^2.2.7", | ||
"@sanity/client": "^6.8.0", | ||
@@ -150,2 +165,5 @@ "@sanity/pkg-utils": "^3.2.3", | ||
}, | ||
"dependencies": { | ||
"@sanity/uuid": "3.0.2" | ||
}, | ||
"scripts": { | ||
@@ -152,0 +170,0 @@ "prebuild": "rimraf dist", |
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
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
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 2 instances 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
47616
32
181
2
11
5
+ Added@sanity/uuid@3.0.2
+ Added@sanity/uuid@3.0.2(transitive)
+ Added@types/uuid@8.3.4(transitive)
+ Addeduuid@8.3.2(transitive)