Socket
Socket
Sign inDemoInstall

@sanity/preview-url-secret

Package Overview
Dependencies
Maintainers
44
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sanity/preview-url-secret - npm Package Compare versions

Comparing version 1.6.3 to 1.6.4

dist/_chunks/constants.cjs

7

CHANGELOG.md

@@ -9,2 +9,9 @@ <!-- markdownlint-disable --><!-- textlint-disable -->

## [1.6.4](https://github.com/sanity-io/visual-editing/compare/preview-url-secret-v1.6.3...preview-url-secret-v1.6.4) (2024-02-26)
### Bug Fixes
* **deps:** update dependency @sanity/client to v6.14.4 ([#1002](https://github.com/sanity-io/visual-editing/issues/1002)) ([1239cb2](https://github.com/sanity-io/visual-editing/commit/1239cb24da0f9132f6093f8ae9eccd275565fc7d))
## [1.6.3](https://github.com/sanity-io/visual-editing/compare/preview-url-secret-v1.6.2...preview-url-secret-v1.6.3) (2024-02-16)

@@ -11,0 +18,0 @@

2

dist/create-secret.js

@@ -1,1 +0,1 @@

import{uuid as t}from"@sanity/uuid";import{a as e,S as a,s as r,c as n,t as o,d as c}from"./_chunks/constants-DEcpk6S1.js";async function s(s,i,p,u,l=t()){const d=s.withConfig({apiVersion:e});try{const t=new Date(Date.now()+1e3*a),e="".concat(r,".").concat(l),c=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)}(),s=d.patch(e).set({secret:c,source:i,studioUrl:p,userId:u});return await d.transaction().createOrReplace({_id:e,_type:n}).patch(s).commit({tag:o}),{secret:c,expiresAt:t}}finally{await d.delete({query:c})}}export{s as createPreviewSecret};//# sourceMappingURL=create-secret.js.map
import{uuid as t}from"@sanity/uuid";import{a as e,S as a,s as r,c as n,t as o,d as s}from"./_chunks/constants.js";async function c(c,i,p,u,l=t()){const y=c.withConfig({apiVersion:e});try{const t=new Date(Date.now()+1e3*a),e=`${r}.${l}`,s=function(){if(typeof crypto<"u"){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)}(),c=y.patch(e).set({secret:s,source:i,studioUrl:p,userId:u});return await y.transaction().createOrReplace({_id:e,_type:n}).patch(c).commit({tag:o}),{secret:s,expiresAt:t}}finally{await y.delete({query:s})}}export{c as createPreviewSecret};//# sourceMappingURL=create-secret.js.map

@@ -1,1 +0,1 @@

import{u as e,b as n}from"./_chunks/constants-DEcpk6S1.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
import{u as e,b as t}from"./_chunks/constants.js";function r(r){const{draftMode:n,previewMode:a,origin:o=(typeof location>"u"?"https://localhost":location.origin)}=r,i=(null==a?void 0:a.enable)||(null==n?void 0:n.enable);let{preview:s="/"}=r;const c=new URL(s,o),h=i?new URL(i,o):void 0;return async n=>{try{if(n.previewSearchParam){const e=new URL(n.previewSearchParam,c);e.origin===c.origin&&(s=`${e.pathname}${e.search}`)}else if(n.referrer){const e=new URL(n.referrer);e.origin===c.origin&&(s=`${e.pathname}${e.search}`)}}catch{}typeof location<"u"&&location.origin===c.origin&&n.studioBasePath&&(s.startsWith(`${n.studioBasePath}/`)||s===n.studioBasePath)&&(s=r.preview||"/");const a=new URL(s,c);if(h){const r=new URL(h),{searchParams:o}=r;return o.set(e,n.previewUrlSecret),a.pathname!==r.pathname&&o.set(t,`${a.pathname}${a.search}`),r.toString()}return a.toString()}}export{r as definePreviewUrl};//# sourceMappingURL=define-preview-url.js.map

@@ -1,1 +0,1 @@

import{b as r}from"./_chunks/constants-DEcpk6S1.js";function s(s){return s.searchParams.has(r)?new URL(s.searchParams.get(r),s.origin):s}export{s as getRedirectTo};//# sourceMappingURL=get-redirect-to.js.map
import{b as r}from"./_chunks/constants.js";function s(s){return s.searchParams.has(r)?new URL(s.searchParams.get(r),s.origin):s}export{s as getRedirectTo};//# sourceMappingURL=get-redirect-to.js.map

@@ -1,1 +0,1 @@

import{a as e,u as t,b as r,f as i,t as o,i as s}from"./_chunks/constants-DEcpk6S1.js";async function n(n,a,c="Cloudflare-Workers"===(e=>null==(e=globalThis.navigator)?void 0:e.userAgent)()){const l=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:!1})}(n);let u;try{u=function(e){const i=new URL(e,"http://localhost"),o=i.searchParams.get(t);if(!o)throw new Error("Missing secret");let s;const n=i.searchParams.get(r);if(n){const{pathname:e,search:t}=new URL(n,"http://localhost");s="".concat(e).concat(t)}return{secret:o,redirectTo:s}}(a)}catch(e){return s&&console.error("Failed to parse preview URL",e,{previewUrl:a,client:l}),{isValid:!1}}const{isValid:d,studioUrl:h}=await async function(e,t,r){if("undefined"!=typeof EdgeRuntime&&await new Promise((e=>setTimeout(e,300))),!t||!t.trim())return{isValid:!1,studioUrl:null};const s=await e.fetch(i,{secret:t},{tag:o,...r?void 0:{cache:"no-store"}});return(null==s?void 0:s._id)&&(null==s?void 0:s._updatedAt)&&(null==s?void 0:s.secret)?{isValid:t===s.secret,studioUrl:s.studioUrl}:{isValid:!1,studioUrl:null}}(l,u.secret,c),p=d?u.redirectTo:void 0;let f;if(d)try{f=new URL(h).origin}catch(e){s&&console.error("Failed to parse studioUrl",e,{previewUrl:a,studioUrl:h})}return{isValid:d,redirectTo:p,studioOrigin:f}}export{r as urlSearchParamPreviewPathname,t as urlSearchParamPreviewSecret,n as validatePreviewUrl};//# sourceMappingURL=index.js.map
import{a as e,u as t,b as r,f as i,t as s,i as o}from"./_chunks/constants.js";async function n(n,a,l="Cloudflare-Workers"===(e=>null==(e=globalThis.navigator)?void 0:e.userAgent)()){const c=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:!1})}(n);let u;try{u=function(e){const i=new URL(e,"http://localhost"),s=i.searchParams.get(t);if(!s)throw new Error("Missing secret");let o;const n=i.searchParams.get(r);if(n){const{pathname:e,search:t}=new URL(n,"http://localhost");o=`${e}${t}`}return{secret:s,redirectTo:o}}(a)}catch(e){return o&&console.error("Failed to parse preview URL",e,{previewUrl:a,client:c}),{isValid:!1}}const{isValid:d,studioUrl:h}=await async function(e,t,r){if(typeof EdgeRuntime<"u"&&await new Promise((e=>setTimeout(e,300))),!t||!t.trim())return{isValid:!1,studioUrl:null};const o=await e.fetch(i,{secret:t},{tag:s,...r?void 0:{cache:"no-store"}});return null!=o&&o._id&&null!=o&&o._updatedAt&&null!=o&&o.secret?{isValid:t===o.secret,studioUrl:o.studioUrl}:{isValid:!1,studioUrl:null}}(c,u.secret,l),p=d?u.redirectTo:void 0;let f;if(d)try{f=new URL(h).origin}catch(e){o&&console.error("Failed to parse studioUrl",e,{previewUrl:a,studioUrl:h})}return{isValid:d,redirectTo:p,studioOrigin:f}}export{r as urlSearchParamPreviewPathname,t as urlSearchParamPreviewSecret,n as validatePreviewUrl};//# sourceMappingURL=index.js.map

@@ -1,1 +0,1 @@

import{defineType as e,definePlugin as t}from"sanity";import{c as i,S as n}from"./_chunks/constants-DEcpk6S1.js";import{LockIcon as s,CloseCircleIcon as o,CheckmarkCircleIcon as r}from"@sanity/icons";const a=e({type:"document",icon:s,name:i,title:"@sanity/preview-url-secret",readOnly:!0,fields:[{type:"string",name:"secret",title:"Secret"},{type:"string",name:"source",title:"Source Tool"},{type:"string",name:"studioUrl",title:"Studio URL"},{type:"string",name:"userId",title:"Sanity User ID"}],preview:{select:{source:"source",studioUrl:"studioUrl",updatedAt:"_updatedAt"},prepare(e){const t=e.studioUrl?new URL(e.studioUrl,location.origin):void 0,i=new Date(e.updatedAt).getTime(),s=new Date(i+1e3*n),a=s<new Date,c=a?o:r;return{title:t?"".concat(t.host).concat(t.pathname):e.source,subtitle:a?"Expired":"Expires in ".concat(Math.round((s.getTime()-Date.now())/6e4)," minutes"),media:c}}}}),c=t((()=>({name:"sanity-plugin-debug-secrets",schema:{types:[a]},document:{actions:(e,t)=>t.schemaType!==i?e:e.filter((({action:e})=>"delete"===e)),inspectors:(e,t)=>t.documentType!==i?e:[],unstable_fieldActions:(e,t)=>t.schemaType.name!==i?e:[]}})));export{c as debugSecrets};//# sourceMappingURL=sanity-plugin-debug-secrets.js.map
import{defineType as e,definePlugin as t}from"sanity";import{c as i,S as s}from"./_chunks/constants.js";import{LockIcon as n,CloseCircleIcon as r,CheckmarkCircleIcon as o}from"@sanity/icons";const a=e({type:"document",icon:n,name:i,title:"@sanity/preview-url-secret",readOnly:!0,fields:[{type:"string",name:"secret",title:"Secret"},{type:"string",name:"source",title:"Source Tool"},{type:"string",name:"studioUrl",title:"Studio URL"},{type:"string",name:"userId",title:"Sanity User ID"}],preview:{select:{source:"source",studioUrl:"studioUrl",updatedAt:"_updatedAt"},prepare(e){const t=e.studioUrl?new URL(e.studioUrl,location.origin):void 0,i=new Date(e.updatedAt).getTime(),n=new Date(i+1e3*s),a=n<new Date,c=a?r:o;return{title:t?`${t.host}${t.pathname}`:e.source,subtitle:a?"Expired":`Expires in ${Math.round((n.getTime()-Date.now())/6e4)} minutes`,media:c}}}}),c=t((()=>({name:"sanity-plugin-debug-secrets",schema:{types:[a]},document:{actions:(e,t)=>t.schemaType!==i?e:e.filter((({action:e})=>"delete"===e)),inspectors:(e,t)=>t.documentType!==i?e:[],unstable_fieldActions:(e,t)=>t.schemaType.name!==i?e:[]}})));export{c as debugSecrets};//# sourceMappingURL=sanity-plugin-debug-secrets.js.map

@@ -1,1 +0,1 @@

import{b as s,u as a}from"./_chunks/constants-DEcpk6S1.js";function e(e){const r=new URL(e);return r.searchParams.delete(s),r.searchParams.delete(a),r}function r(s){return s.searchParams.has(a)}function n(e,r,n){const t=new URL(e);return t.searchParams.set(a,r),t.searchParams.set(s,n),t}export{r as hasSecretSearchParams,n as setSecretSearchParams,e as withoutSecretSearchParams};//# sourceMappingURL=without-secret-search-params.js.map
import{b as s,u as a}from"./_chunks/constants.js";function e(e){const r=new URL(e);return r.searchParams.delete(s),r.searchParams.delete(a),r}function r(s){return s.searchParams.has(a)}function n(e,r,n){const t=new URL(e);return t.searchParams.set(a,r),t.searchParams.set(s,n),t}export{r as hasSecretSearchParams,n as setSecretSearchParams,e as withoutSecretSearchParams};//# sourceMappingURL=without-secret-search-params.js.map
{
"name": "@sanity/preview-url-secret",
"version": "1.6.3",
"version": "1.6.4",
"homepage": "https://github.com/sanity-io/visual-editing/tree/main/packages/preview-url-secret#readme",

@@ -170,17 +170,17 @@ "bugs": {

"@sanity/channels": "0.4.0",
"@sanity/client": "^6.13.3",
"@sanity/icons": "^2.10.2",
"@sanity/pkg-utils": "^4.2.2",
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.0.1",
"eslint": "^8.56.0",
"@sanity/client": "^6.14.4",
"@sanity/icons": "^2.10.3",
"@sanity/pkg-utils": "^4.3.0",
"@typescript-eslint/eslint-plugin": "^7.0.2",
"@typescript-eslint/parser": "^7.0.2",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-simple-import-sort": "^12.0.0",
"sanity": "^3.29.1",
"sanity": "^3.30.0",
"typescript": "^5.3.3",
"vitest": "^1.2.2"
"vitest": "^1.3.1"
},
"peerDependencies": {
"@sanity/client": "^6.13.3"
"@sanity/client": "^6.14.4"
},

@@ -187,0 +187,0 @@ "engines": {

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc