@sanity/preview-url-secret
Advanced tools
Comparing version 0.3.0-pink-lizard to 0.3.1-pink-lizard
# Changelog | ||
## [0.3.1-pink-lizard](https://github.com/sanity-io/visual-editing/compare/preview-url-secret-v0.3.0-pink-lizard...preview-url-secret-v0.3.1-pink-lizard) (2023-11-11) | ||
### Bug Fixes | ||
* garbage collect expired secrets ([817582b](https://github.com/sanity-io/visual-editing/commit/817582b509d7614162485f71ba38f84e98653157)) | ||
## [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) | ||
@@ -4,0 +11,0 @@ |
@@ -8,2 +8,3 @@ import type { SanityClient } from '@sanity/client' | ||
studioUrl: string, | ||
userId?: string, | ||
id?: string, | ||
@@ -10,0 +11,0 @@ ): Promise<string> |
@@ -1,1 +0,1 @@ | ||
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 | ||
import{uuid as t}from"@sanity/uuid";import{a as e,s as a,t as r,c as n,d as o}from"./_chunks/constants-OvbOEjOh.js";async function s(s,c,i,p,u=t()){const l=s.withConfig({apiVersion:e});try{const t=`${a}.${u}`,e=function(){if("undefined"!=typeof crypto){const t=new Uint8Array(16);crypto.getRandomValues(t);let e="";for(let a=0;a<t.length;a++)e+=t[a].toString(16).padStart(2,"0");return e=btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/[=]+$/,""),e}return Math.random().toString(36).slice(2)}(),o=l.patch(t).set({secret:e,source:c,studioUrl:i,userId:p});return await l.transaction().createOrReplace({_id:t,_type:n}).patch(o).commit({tag:r}),e}finally{await l.delete({query:o})}}export{s as createPreviewSecret};//# sourceMappingURL=create-secret.js.map |
@@ -1,1 +0,1 @@ | ||
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 | ||
import{u as e,b as n}from"./_chunks/constants-OvbOEjOh.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 |
@@ -1,1 +0,1 @@ | ||
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 | ||
import{a as e,u as t,b as r,f as s,t as i,i as n}from"./_chunks/constants-OvbOEjOh.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 |
@@ -1,1 +0,1 @@ | ||
import{b as e,u as s}from"./_chunks/constants-M5g_6bzK.js";function a(a){const r=new URL(a);return r.searchParams.delete(e),r.searchParams.delete(s),r}export{a as withoutSecretSearchParams};//# sourceMappingURL=without-secret-search-params.js.map | ||
import{b as e,u as s}from"./_chunks/constants-OvbOEjOh.js";function a(a){const r=new URL(a);return r.searchParams.delete(e),r.searchParams.delete(s),r}export{a as withoutSecretSearchParams};//# sourceMappingURL=without-secret-search-params.js.map |
{ | ||
"name": "@sanity/preview-url-secret", | ||
"version": "0.3.0-pink-lizard", | ||
"version": "0.3.1-pink-lizard", | ||
"homepage": "https://github.com/sanity-io/visual-editing/tree/main/packages/preview-url-secret#readme", | ||
@@ -139,2 +139,5 @@ "bugs": { | ||
}, | ||
"dependencies": { | ||
"@sanity/uuid": "3.0.2" | ||
}, | ||
"devDependencies": { | ||
@@ -163,5 +166,2 @@ "@edge-runtime/types": "^2.2.7", | ||
}, | ||
"dependencies": { | ||
"@sanity/uuid": "3.0.2" | ||
}, | ||
"scripts": { | ||
@@ -168,0 +168,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
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
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
49156
184