@sanity/preview-url-secret
Advanced tools
Comparing version 1.6.22-canary.9 to 1.6.22-canary.10
@@ -19,3 +19,3 @@ import type {SanityClient} from '@sanity/client' | ||
* as well as those that use `import type { SanityClient } from '@sanity/client'` | ||
* @internal | ||
* @public | ||
*/ | ||
@@ -22,0 +22,0 @@ export declare type SanityClientLike = { |
@@ -20,3 +20,3 @@ /** | ||
* as well as those that use `import type { SanityClient } from '@sanity/client'` | ||
* @internal | ||
* @public | ||
*/ | ||
@@ -23,0 +23,0 @@ export declare type SanityClientLike = { |
@@ -1,2 +0,3 @@ | ||
import { apiVersion, urlSearchParamPreviewSecret, urlSearchParamPreviewPathname, fetchSecretQuery, tag, isDev } from './constants.js'; | ||
import { apiVersion, urlSearchParamPreviewSecret, urlSearchParamPreviewPathname, isDev } from './constants.js'; | ||
import { validateSecret } from './validate-secret.js'; | ||
@@ -39,24 +40,2 @@ function createClientWithConfig(client) { | ||
async function validateSecret(client, secret, disableCacheNoStore) { | ||
if (typeof EdgeRuntime !== "undefined") { | ||
await new Promise((resolve) => setTimeout(resolve, 300)); | ||
} | ||
if (!secret || !secret.trim()) { | ||
return { isValid: false, studioUrl: null }; | ||
} | ||
const result = await client.fetch( | ||
fetchSecretQuery, | ||
{ secret }, | ||
{ | ||
tag, | ||
// In CloudFlare Workers we can't pass the cache header | ||
...!disableCacheNoStore ? { cache: "no-store" } : void 0 | ||
} | ||
); | ||
if (!result?._id || !result?._updatedAt || !result?.secret) { | ||
return { isValid: false, studioUrl: null }; | ||
} | ||
return { isValid: secret === result.secret, studioUrl: result.studioUrl }; | ||
} | ||
async function validatePreviewUrl(_client, previewUrl, disableCacheNoStore = globalThis.navigator?.userAgent === "Cloudflare-Workers") { | ||
@@ -63,0 +42,0 @@ const client = createClientWithConfig(_client); |
{ | ||
"name": "@sanity/preview-url-secret", | ||
"version": "1.6.22-canary.9", | ||
"version": "1.6.22-canary.10", | ||
"homepage": "https://github.com/sanity-io/visual-editing/tree/main/packages/preview-url-secret#readme", | ||
@@ -54,2 +54,8 @@ "bugs": { | ||
}, | ||
"./validate-secret": { | ||
"source": "./src/_exports/validate-secret.ts", | ||
"import": "./dist/validate-secret.js", | ||
"require": "./dist/validate-secret.cjs", | ||
"default": "./dist/validate-secret.js" | ||
}, | ||
"./without-secret-search-params": { | ||
@@ -83,2 +89,5 @@ "source": "./src/_exports/without-secret-search-params.ts", | ||
], | ||
"validate-secret": [ | ||
"./dist/validate-secret.d.ts" | ||
], | ||
"without-secret-search-params": [ | ||
@@ -115,6 +124,6 @@ "./dist/without-secret-search-params.d.ts" | ||
"vitest": "^2.1.1", | ||
"@repo/channels": "0.4.0", | ||
"@repo/package.config": "0.0.0", | ||
"@repo/eslint-config": "0.0.0", | ||
"@repo/package.config": "0.0.0", | ||
"@repo/prettier-config": "0.0.0" | ||
"@repo/prettier-config": "0.0.0", | ||
"@repo/channels": "0.4.0" | ||
}, | ||
@@ -121,0 +130,0 @@ "peerDependencies": { |
@@ -18,3 +18,3 @@ /** @internal */ | ||
* as well as those that use `import type { SanityClient } from '@sanity/client'` | ||
* @internal | ||
* @public | ||
*/ | ||
@@ -21,0 +21,0 @@ export type SanityClientLike = { |
import {fetchSecretQuery, tag} from './constants' | ||
import type {FetchSecretQueryParams, FetchSecretQueryResponse, SanityClientLike} from './types' | ||
/** @internal */ | ||
export type {SanityClientLike} | ||
/** @public */ | ||
export async function validateSecret( | ||
@@ -6,0 +8,0 @@ client: SanityClientLike, |
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
144983
73
1509